Java Code Examples for org.assertj.core.api.SoftAssertions#assertAll()

The following examples show how to use org.assertj.core.api.SoftAssertions#assertAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JvmOptionConverterTest.java    From quickperf with Apache License 2.0 7 votes vote down vote up
@Test public void
should_return_jvm_option_objects_from_jvm_options_as_a_string() {

    // GIVEN
    JvmOptions jvmOptionsAsAnnotation = mock(JvmOptions.class);
    when(jvmOptionsAsAnnotation.value()).thenReturn(" -XX:+UseCompressedOops   -XX:+UseCompressedClassPointers  ");

    // WHEN
    List<JvmOption> jvmOptions = jvmOptionConverter.jvmOptionFrom(jvmOptionsAsAnnotation);

    // THEN
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(jvmOptions).hasSize(2);

    JvmOption firstJvmOption = jvmOptions.get(0);
    softAssertions.assertThat(firstJvmOption.asString())
                  .isEqualTo("-XX:+UseCompressedOops");

    JvmOption secondJvmOption = jvmOptions.get(1);
    softAssertions.assertThat(secondJvmOption.asString())
                  .isEqualTo("-XX:+UseCompressedClassPointers");

    softAssertions.assertAll();

}
 
Example 2
Source File: LappsGridRecommenderConformityTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
@Parameters(method = "getNerServices")
public void testNerConformity(LappsGridService aService) throws Exception
{
    CAS cas = loadData();
    
    predict(aService.getUrl(), cas);

    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(JCasUtil.select(cas.getJCas(), Token.class))
            .as("Prediction should contain Tokens")
            .isNotEmpty();
    softly.assertThat(JCasUtil.select(cas.getJCas(), NamedEntity.class))
            .as("Prediction should contain NER")
            .isNotEmpty();

    softly.assertAll();
}
 
Example 3
Source File: QueryTasksAccTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@WithAccessId(user = "admin")
@Test
void testQueryTaskValuesForEveryColumn() {
  SoftAssertions softly = new SoftAssertions();
  Arrays.stream(TaskQueryColumnName.values())
      .forEach(
          columnName ->
              softly
                  .assertThatCode(
                      () -> taskService.createTaskQuery().listValues(columnName, ASCENDING))
                  .describedAs("Column is not working " + columnName)
                  .doesNotThrowAnyException());
  softly.assertAll();
}
 
Example 4
Source File: LogTypeTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private LogTypeAssert supportsCategory(final LogCategory category, final LogCategory... otherCategories) {
    isNotNull();
    final SoftAssertions softAssertions = new SoftAssertions();

    final List<LogCategory> shouldNotContain = new ArrayList<>(Arrays.asList(LogCategory.values()));
    shouldNotContain.remove(category);
    shouldNotContain.removeAll(Arrays.asList(otherCategories));

    final List<LogCategory> shouldContain = new ArrayList<>(Arrays.asList(otherCategories));
    shouldContain.add(category);

    final String shouldContainMessage =
            MessageFormat.format("Expected log type <{0}> to support category <{1}>, but it didn't.", actual,
                    category);
    shouldContain.forEach(c -> {
        softAssertions.assertThat(actual.supportsCategory(c))
                .overridingErrorMessage(shouldContainMessage)
                .isTrue();
    });

    final String shouldNotContainMessage =
            MessageFormat.format("Expected log type <{0}> to not support category <{1}>, but it did.", actual,
                    category);
    shouldNotContain.forEach(c -> {
        softAssertions.assertThat(actual.supportsCategory(c))
                .overridingErrorMessage(shouldContainMessage)
                .isFalse();
    });

    softAssertions.assertAll();
    return myself;
}
 
Example 5
Source File: WitServiceIT.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
@Test
public void testRenameMethodComment2() throws Exception {
	// arrange + act
	BotIssue issue = createBotIssueForCommentBody("Could you rename this to \"doSomething\" @Bot?");

	// assert
	assertNotNull(issue);
	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(issue.getRefactoringOperation()).isEqualTo(RefactoringOperations.RENAME_METHOD);
	softAssertions.assertThat(issue.getRefactorString()).isEqualTo("doSomething");
	softAssertions.assertAll();
}
 
Example 6
Source File: PermissionCheckTest.java    From jump-the-queue with Apache License 2.0 5 votes vote down vote up
/**
 * Check if all relevant methods in use case implementations have permission checks i.e. {@link RolesAllowed},
 * {@link DenyAll} or {@link PermitAll} annotation is applied. This is only checked for methods that are declared in
 * the corresponding interface and thus have the {@link Override} annotations applied.
 */
@Test
@Ignore // Currently Access control has not been implemented in jumpthequeue so the test is ignored
public void permissionCheckAnnotationPresent() {

  String packageName = "com.devonfw.application.jtqj";
  Filter<String> filter = new Filter<String>() {

    @Override
    public boolean accept(String value) {

      return value.contains(".logic.impl.usecase.Uc") && value.endsWith("Impl");
    }

  };
  ReflectionUtil ru = ReflectionUtilImpl.getInstance();
  Set<String> classNames = ru.findClassNames(packageName, true, filter);
  Set<Class<?>> classes = ru.loadClasses(classNames);
  SoftAssertions assertions = new SoftAssertions();
  for (Class<?> clazz : classes) {
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
      Method parentMethod = ru.getParentMethod(method);
      if (parentMethod != null) {
        Class<?> declaringClass = parentMethod.getDeclaringClass();
        if (declaringClass.isInterface() && declaringClass.getSimpleName().startsWith("Uc")) {
          boolean hasAnnotation = false;
          if (method.getAnnotation(RolesAllowed.class) != null || method.getAnnotation(DenyAll.class) != null
              || method.getAnnotation(PermitAll.class) != null) {
            hasAnnotation = true;
          }
          assertions.assertThat(hasAnnotation)
              .as("Method " + method.getName() + " in Class " + clazz.getSimpleName() + " is missing access control")
              .isTrue();
        }
      }
    }
  }
  assertions.assertAll();
}
 
Example 7
Source File: RemoveMethodParameterTest.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * Test whether the refactoring was performed correctly in a different class
 * which contains a method calling the refactored target method
 * 
 * @throws Exception
 */
@Test
public void testCallerClassRefactored() throws Exception {
	// arrange
	List<File> filesToConsider = new ArrayList<File>();
	filesToConsider.add(fileOfTestClass);
	filesToConsider.add(fileWithCallerMethod);
	int lineNumberOfMethodWithParameterToBeRemoved = removeParameterTestClass.getLineOfMethodWithUnusedParameter(0,
			0, 0);
	String parameterName = "b";

	CompilationUnit cuOriginalFileOfTestClass = StaticJavaParser.parse(fileOfTestClass);
	CompilationUnit cuOriginalFileWithCallerMethod = StaticJavaParser.parse(fileWithCallerMethod);
	MethodDeclaration originalMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			lineNumberOfMethodWithParameterToBeRemoved, cuOriginalFileOfTestClass);
	MethodDeclaration originalCallerMethodInDifferentFile = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterCallerTestClass.getLineOfCallerMethodInDifferentFile(), cuOriginalFileWithCallerMethod);

	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(originalMethod).isNotNull();
	softAssertions.assertThat(originalCallerMethodInDifferentFile).isNotNull();
	softAssertions.assertAll();

	// act
	performRemoveParameter(filesToConsider, fileOfTestClass, lineNumberOfMethodWithParameterToBeRemoved,
			parameterName);

	// assert
	CompilationUnit cuRefactoredFileOfTestClass = StaticJavaParser.parse(fileOfTestClass);
	CompilationUnit cuRefactoredFileWithCallerMethod = StaticJavaParser.parse(fileWithCallerMethod);
	MethodDeclaration refactoredMethod = getMethodByName(TARGET_CLASS_NAME, originalMethod.getNameAsString(),
			cuRefactoredFileOfTestClass);

	// assert that caller method in different file has been refactored
	MethodDeclaration methodInDifferentFileWithTargetMethodCalls = getMethodByName(CALL_OF_TARGET_METHOD_CLASS_NAME,
			originalCallerMethodInDifferentFile.getNameAsString(), cuRefactoredFileWithCallerMethod);
	assertThat(methodInDifferentFileWithTargetMethodCalls).isNotNull();
	assertAllMethodCallsArgumentSizeEqualToRefactoredMethodParameterCount(
			methodInDifferentFileWithTargetMethodCalls, refactoredMethod);
}
 
Example 8
Source File: WitServiceIT.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
@Test
public void testRenameMethodComment() throws Exception {
	// arrange + act
	BotIssue issue = createBotIssueForCommentBody("@Bot Please rename this method to getABC");

	// assert
	assertNotNull(issue);
	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(issue.getRefactoringOperation()).isEqualTo(RefactoringOperations.RENAME_METHOD);
	softAssertions.assertThat(issue.getRefactorString()).isEqualTo("getABC");
	softAssertions.assertAll();
}
 
Example 9
Source File: IntegrationTestForKotlinDSL.java    From jig with Apache License 2.0 5 votes vote down vote up
@Test
void スタブプロジェクトへの適用でパッケージ図と機能一覧が出力されること() throws IOException, URISyntaxException {
    BuildResult result = runner.executeGradleTasks(GradleVersions.CURRENT, "clean", "compileJava", "jigReports", "--stacktrace");

    System.out.println(result.getOutput());
    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(result.getOutput()).contains("BUILD SUCCESSFUL");
    softly.assertThat(outputDir.resolve("package-relation-depth4.svg")).exists();
    softly.assertAll();
}
 
Example 10
Source File: FindPageObjectTest.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Test
public void shoudFindListOfPageObjectsInPageObject() {
  SoftAssertions softly = new SoftAssertions();
  softly.assertThat(masterPage.getDrinks().getLiPageObjectList().size()).isEqualTo(3);
  softly.assertThat(masterPage.getDrinks().getLiPageObjectList().get(0).getText())
      .isEqualTo(COFFEE_TEXT);
  softly.assertThat(masterPage.getDrinks().getLiPageObjectList().get(1).getText())
      .isEqualTo(TEA_TEXT);
  softly.assertThat(masterPage.getDrinks().getLiPageObjectList().get(2).getText())
      .isEqualTo(MILK_TEXT);
  softly.assertAll();
}
 
Example 11
Source File: DataAnonymizerServiceTest.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
@Test
public void testUserComment() {
	String anonymizedComment = anonymizer.anonymizeComment(userComment);
	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(anonymizedComment).isEqualTo("@USER could you remove the parameter c from this method?");
	softAssertions.assertAll();
}
 
Example 12
Source File: GrammarServiceTest.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
@Test
public void testCommentToIssueMappingReorderModifiers() throws Exception {
	// arrange + act
	BotIssue botIssue = getIssueAfterMapping(VALID_COMMENT_REORDER_MODIFIER);

	// assert
	String refactoringOperationKey = "Reorder Modifier";

	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(ruleToClassMapping).containsKey(refactoringOperationKey);
	softAssertions.assertThat(botIssue.getRefactoringOperation()).isEqualTo(refactoringOperationKey);
	softAssertions.assertAll();
}
 
Example 13
Source File: SampleModelSerializationTest.java    From doov with Apache License 2.0 5 votes vote down vote up
@Test
void should_write_fields_to_csv_and_parse_back() {
    ByteArrayOutputStream csvResult = new ByteArrayOutputStream();
    Writer outputWriter = new OutputStreamWriter(csvResult);
    CsvWriter csvWriter = new CsvWriter(outputWriter, new CsvWriterSettings());
    wrapper.getFieldInfos().stream()
                    .filter(f -> !f.isTransient())
                    .forEach(f -> {
                        FieldId fieldId = f.id();
                        csvWriter.writeRow(fieldId.code(), wrapper.getAsString(fieldId));
                    });
    csvWriter.close();
    System.out.println(csvResult.toString());

    SampleModelWrapper copy = new SampleModelWrapper();

    ByteArrayInputStream csvInput = new ByteArrayInputStream(csvResult.toByteArray());
    CsvParser csvParser = new CsvParser(new CsvParserSettings());
    csvParser.parseAll(csvInput).forEach(record -> {
        FieldInfo fieldInfo = fieldInfoByName(record[0], wrapper);
        copy.setAsString(fieldInfo, record[1]);
    });

    SoftAssertions softly = new SoftAssertions();
    wrapper.getFieldInfos().stream()
                    .filter(f -> !f.isTransient())
                    .forEach(f -> {
                        Object value = copy.get(f.id());
                        softly.assertThat(value).isEqualTo(wrapper.get(f.id()));
                    });
    softly.assertAll();
}
 
Example 14
Source File: SampleFieldIdInfoTest.java    From doov with Apache License 2.0 5 votes vote down vote up
@Test
public void should_have_field_info() {
    SoftAssertions softAssertions = new SoftAssertions();

    Arrays.stream(SampleFieldId.values()).forEach(id -> {
        softAssertions.assertThat(fieldInfo(id)).isPresent();
        softAssertions.assertThat(fieldInfo(id))
                .isNotEmpty()
                .hasValueSatisfying(info -> assertThat(info.type()).isNotNull());
    });

    softAssertions.assertAll();
}
 
Example 15
Source File: SampleModelCollectorTest.java    From doov with Apache License 2.0 5 votes vote down vote up
private static void should_collect_all_values_when_collect(FieldModel target, FieldModel source) {
    SoftAssertions softly = new SoftAssertions();
    SampleFieldInfo.stream().forEach(info -> {
        Object after = target.get(info.id());
        Object before = source.get(info.id());
        softly.assertThat(after).describedAs(info.id().code()).isEqualTo(before);
    });
    softly.assertAll();
}
 
Example 16
Source File: ApplicationHeaderBlockTest.java    From banking-swift-messages-java with MIT License 5 votes vote down vote up
@Test
public void of_WHEN_valid_output_block_is_passed_RETURN_new_block() throws Exception {

    // Given
    GeneralBlock generalBlock = new GeneralBlock(ApplicationHeaderBlock.BLOCK_ID_2, "O9401506110804LRLRXXXX4A1100009040831108041707N");

    // When
    ApplicationHeaderBlock block = ApplicationHeaderBlock.of(generalBlock);

    // Then
    assertThat(block).isNotNull();
    assertThat(block.getOutput()).isPresent();
    if (block.getOutput().isPresent()) {
        SoftAssertions softly = new SoftAssertions();
        ApplicationHeaderOutputBlock outputBlock = block.getOutput().get();
        softly.assertThat(outputBlock.getMessageType()).isEqualTo("940");
        softly.assertThat(outputBlock.getInputDateTime()).isEqualTo(LocalDateTime.of(2011, 8, 4, 15, 6));
        softly.assertThat(outputBlock.getInputReference()).isEqualTo("LRLRXXXX4A11");
        softly.assertThat(outputBlock.getSessionNumber()).isEqualTo("0000");
        softly.assertThat(outputBlock.getSequenceNumber()).isEqualTo("904083");
        softly.assertThat(outputBlock.getOutputDateTime()).isEqualTo(LocalDateTime.of(2011, 8, 4, 17, 7));
        softly.assertThat(outputBlock.getMessagePriority()).isEqualTo(MessagePriority.NORMAL);
        softly.assertAll();
    }

    assertThat(block.getInput()).isNotPresent();
}
 
Example 17
Source File: FindPageObjectTest.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindWebElementListInPageObject() {
  SoftAssertions softly = new SoftAssertions();
  softly.assertThat(masterPage.getDrinks().getLiWebElementList().size()).isEqualTo(3);
  softly.assertThat(masterPage.getDrinks().getLiWebElementList().get(2).getText())
      .isEqualTo(MILK_TEXT);
  softly.assertAll();
}
 
Example 18
Source File: RemoveMethodParameterTest.java    From Refactoring-Bot with MIT License 4 votes vote down vote up
/**
 * Test whether the refactoring was performed correctly in the target class
 * 
 * @throws Exception
 */
@Test
public void testTargetClassRefactored() throws Exception {
	// arrange
	List<File> filesToConsider = new ArrayList<File>();
	filesToConsider.add(fileOfTestClass);
	int lineNumberOfMethodWithParameterToBeRemoved = removeParameterTestClass.getLineOfMethodWithUnusedParameter(0,
			0, 0);
	String parameterName = "b";

	CompilationUnit cuOriginalFileOfTestClass = StaticJavaParser.parse(fileOfTestClass);
	MethodDeclaration originalMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			lineNumberOfMethodWithParameterToBeRemoved, cuOriginalFileOfTestClass);
	MethodDeclaration originalDummyMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterTestClass.getLineNumberOfDummyMethod(0, 0, 0), cuOriginalFileOfTestClass);
	MethodDeclaration originalCallerMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterTestClass.getLineNumberOfCaller(), cuOriginalFileOfTestClass);
	MethodDeclaration originalCallerMethodInnerClass = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterInnerTestClass.getLineNumberOfCallerInInnerClass(), cuOriginalFileOfTestClass);
	MethodDeclaration originalMethodWithTargetMethodSignatureInInnerClass = RefactoringHelper
			.getMethodDeclarationByLineNumber(
					removeParameterInnerTestClass.getLineOfMethodWithUnusedParameter(0, 0, 0),
					cuOriginalFileOfTestClass);

	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(originalMethod).isNotNull();
	softAssertions.assertThat(originalDummyMethod).isNotNull();
	softAssertions.assertThat(originalCallerMethod).isNotNull();
	softAssertions.assertThat(originalCallerMethodInnerClass).isNotNull();
	softAssertions.assertThat(originalMethodWithTargetMethodSignatureInInnerClass).isNotNull();
	softAssertions.assertAll();

	// act
	performRemoveParameter(filesToConsider, fileOfTestClass, lineNumberOfMethodWithParameterToBeRemoved,
			parameterName);

	// assert
	CompilationUnit cuRefactoredFileOfTestClass = StaticJavaParser.parse(fileOfTestClass);
	MethodDeclaration refactoredMethod = getMethodByName(TARGET_CLASS_NAME, originalMethod.getNameAsString(),
			cuRefactoredFileOfTestClass);

	// assert that parameter has been removed from the target method
	assertThat(refactoredMethod).isNotNull();
	assertThat(refactoredMethod.getParameterByName(parameterName).isPresent()).isFalse();

	// assert that parameter has been removed from the Javadoc
	assertParameterNotPresentInJavadoc(refactoredMethod, parameterName);

	// assert that dummy method is unchanged
	MethodDeclaration dummyMethod = getMethodByName(TARGET_CLASS_NAME, originalDummyMethod.getNameAsString(),
			cuRefactoredFileOfTestClass);
	assertThat(dummyMethod).isNotNull();
	assertThat(dummyMethod.getParameterByName(parameterName)).isPresent();

	// assert that inner class method with same name as target method is unchanged
	MethodDeclaration methodWithTargetMethodSignatureInInnerClass = getMethodByName(TARGET_INNER_CLASS_NAME,
			originalMethodWithTargetMethodSignatureInInnerClass.getNameAsString(), cuRefactoredFileOfTestClass);
	assertThat(methodWithTargetMethodSignatureInInnerClass).isNotNull();
	assertThat(methodWithTargetMethodSignatureInInnerClass.getParameterByName(parameterName)).isPresent();

	// assert that caller method in same file has been refactored
	MethodDeclaration methodWithTargetMethodCalls = getMethodByName(TARGET_CLASS_NAME,
			originalCallerMethod.getNameAsString(), cuRefactoredFileOfTestClass);
	assertThat(methodWithTargetMethodCalls).isNotNull();
	assertAllMethodCallsArgumentSizeEqualToRefactoredMethodParameterCount(methodWithTargetMethodCalls,
			refactoredMethod);

	// assert that caller method in same file in inner class has been refactored
	MethodDeclaration methodWithTargetMethodCallInInnerClass = getMethodByName(TARGET_INNER_CLASS_NAME,
			originalCallerMethodInnerClass.getNameAsString(), cuRefactoredFileOfTestClass);
	assertThat(methodWithTargetMethodCallInInnerClass).isNotNull();
	assertAllMethodCallsArgumentSizeEqualToRefactoredMethodParameterCount(methodWithTargetMethodCallInInnerClass,
			refactoredMethod);
}
 
Example 19
Source File: RemoveMethodParameterTest.java    From Refactoring-Bot with MIT License 4 votes vote down vote up
/**
 * Test whether the refactoring was performed correctly in the sibling class of
 * the target class
 * 
 * @throws Exception
 */
@Test
public void testSiblingClassRefactored() throws Exception {
	// arrange
	List<File> filesToConsider = new ArrayList<File>();
	filesToConsider.add(fileOfTestClass);
	filesToConsider.add(fileOfSiblingClass);
	int lineNumberOfMethodWithParameterToBeRemoved = removeParameterTestClass.getLineOfMethodWithUnusedParameter(0,
			0, 0);
	String parameterName = "b";

	CompilationUnit cuOriginalFileOfSiblingClass = StaticJavaParser.parse(fileOfSiblingClass);
	CompilationUnit cuOriginalFileOfTestClass = StaticJavaParser.parse(fileOfTestClass);
	MethodDeclaration originalMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			lineNumberOfMethodWithParameterToBeRemoved, cuOriginalFileOfTestClass);
	MethodDeclaration originalMethodInSiblingClass = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterSiblingClass.getLineOfMethodWithUnusedParameter(0, 0, 0), cuOriginalFileOfSiblingClass);
	MethodDeclaration originalCallerMethodInSiblingClass = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterSiblingClass.getLineNumberOfCaller(), cuOriginalFileOfSiblingClass);

	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(originalMethod).isNotNull();
	softAssertions.assertThat(originalMethodInSiblingClass).isNotNull();
	softAssertions.assertThat(originalCallerMethodInSiblingClass).isNotNull();
	softAssertions.assertAll();

	// act
	performRemoveParameter(filesToConsider, fileOfTestClass, lineNumberOfMethodWithParameterToBeRemoved,
			parameterName);

	// assert
	CompilationUnit cuRefactoredFileOfSiblingClass = StaticJavaParser.parse(fileOfSiblingClass);
	CompilationUnit cuRefactoredFileOfTestClass = StaticJavaParser.parse(fileOfTestClass);
	MethodDeclaration refactoredMethod = getMethodByName(TARGET_CLASS_NAME, originalMethod.getNameAsString(),
			cuRefactoredFileOfTestClass);

	// assert that target's sibling has been refactored
	String methodInSiblingClassName = originalMethodInSiblingClass.getNameAsString();
	MethodDeclaration methodInSiblingClass = getMethodByName(SIBLING_CLASS_NAME, methodInSiblingClassName,
			cuRefactoredFileOfSiblingClass);
	assertThat(methodInSiblingClass).isNotNull();
	assertThat(methodInSiblingClass.getParameterByName(parameterName).isPresent()).isFalse();

	// assert that caller method in target's sibling class has been refactored
	String callerMethodInSiblingClassName = originalCallerMethodInSiblingClass.getNameAsString();
	MethodDeclaration methodInSiblingClassWithSiblingMethodCall = getMethodByName(SIBLING_CLASS_NAME,
			callerMethodInSiblingClassName, cuRefactoredFileOfSiblingClass);
	assertThat(methodInSiblingClassWithSiblingMethodCall).isNotNull();
	assertAllMethodCallsArgumentSizeEqualToRefactoredMethodParameterCount(methodInSiblingClassWithSiblingMethodCall,
			refactoredMethod);
}
 
Example 20
Source File: RemoveMethodParameterTest.java    From Refactoring-Bot with MIT License 4 votes vote down vote up
/**
 * Two classes sharing the same interface should only lead to a refactoring in
 * both classes, if the common interface declares the target method signature.
 * This is not given in this test case
 * 
 * @throws Exception
 */
@Test
public void testTwoClassesWithSameMethodSigAndEmptyInterface() throws Exception {
	// arrange
	List<File> filesToConsider = new ArrayList<File>();
	filesToConsider.add(fileOfTestClassImplementingEmptyInterface);
	filesToConsider.add(fileOfEmptyInterface);
	int lineNumberOfMethodWithParameterToBeRemoved = removeParameterTestClassWithEmptyInterfaceImpl
			.getLineOfMethodWithUnusedParameter(0, 0, 0);
	String parameterName = "b";

	CompilationUnit cuOriginalFileOfTestClassImplementingEmptyInterface = StaticJavaParser
			.parse(fileOfTestClassImplementingEmptyInterface);
	MethodDeclaration originalInnerClassMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterInnerTestClassWithEmptyInterfaceImpl.getLineOfMethodWithUnusedParameter(0, 0, 0),
			cuOriginalFileOfTestClassImplementingEmptyInterface);
	MethodDeclaration originalOuterClassMethod = RefactoringHelper.getMethodDeclarationByLineNumber(
			removeParameterTestClassWithEmptyInterfaceImpl.getLineOfMethodWithUnusedParameter(0, 0, 0),
			cuOriginalFileOfTestClassImplementingEmptyInterface);

	SoftAssertions softAssertions = new SoftAssertions();
	softAssertions.assertThat(originalInnerClassMethod).isNotNull();
	softAssertions.assertThat(originalOuterClassMethod).isNotNull();
	softAssertions.assertAll();

	// act
	performRemoveParameter(filesToConsider, fileOfTestClassImplementingEmptyInterface,
			lineNumberOfMethodWithParameterToBeRemoved, parameterName);

	// assert
	CompilationUnit cuRefactoredFileOfTestClassImplementingEmptyInterface = StaticJavaParser
			.parse(fileOfTestClassImplementingEmptyInterface);

	// assert that method in outer class has been refactored
	MethodDeclaration refactoredOuterClassMethod = getMethodByName(CLASS_IMPLEMENTING_EMPTY_INTERFACE,
			originalOuterClassMethod.getNameAsString(), cuRefactoredFileOfTestClassImplementingEmptyInterface);
	assertThat(refactoredOuterClassMethod).isNotNull();
	assertThat(refactoredOuterClassMethod.getParameterByName(parameterName).isPresent()).isFalse();

	// assert that inner class method remained unchanged
	MethodDeclaration refactoredInnerClassMethod = getMethodByName(INNER_CLASS_IMPLEMENTING_EMPTY_INTERFACE,
			originalInnerClassMethod.getNameAsString(), cuRefactoredFileOfTestClassImplementingEmptyInterface);
	assertThat(refactoredInnerClassMethod).isNotNull();
	assertThat(refactoredInnerClassMethod.getParameterByName(parameterName).isPresent()).isTrue();
}