use of com.tngtech.archunit.lang.FailureReport in project ArchUnit by TNG.
the class MembersShouldConjunctionTest method andShould_ANDs_conditions.
@Test
@UseDataProvider("ANDed_conditions")
public void andShould_ANDs_conditions(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(RightOne.class, RightTwo.class, WrongOne.class, WrongTwo.class));
FailureReport report = result.getFailureReport();
assertThat(report.toString()).contains(String.format("members should not be declared in %s and should not be declared in %s", WrongOne.class.getName(), WrongTwo.class.getName()));
assertThat(report.getDetails()).containsOnly(isDeclaredInMessage(WrongOne.class, CONSTRUCTOR_NAME, 111), isDeclaredInMessage(WrongOne.class, "wrongMethod1", 113), isDeclaredInMessage(WrongTwo.class, CONSTRUCTOR_NAME, 117), isDeclaredInMessage(WrongTwo.class, "wrongMethod2", 119));
}
use of com.tngtech.archunit.lang.FailureReport in project ArchUnit by TNG.
the class SliceRulePerformanceTest method searching_for_cycles_should_terminate_reasonably_fast_for_complete_graph.
/**
* This test would not terminate within a reasonable time with the old BFS cycle detection
*/
@Test
public void searching_for_cycles_should_terminate_reasonably_fast_for_complete_graph() {
SliceRule cycleFree = slices().matching(completeGraphPackageRoot + ".(*)").should().beFreeOfCycles();
int expectedNumberOfCycles = getNumberOfCyclesInCompleteGraph(numberOfClassesFormingCompleteGraph);
ArchConfiguration.get().setProperty(MAX_NUMBER_OF_CYCLES_TO_DETECT_PROPERTY_NAME, String.valueOf(2 * expectedNumberOfCycles));
FailureReport failureReport = cycleFree.evaluate(classesFormingCompleteDependencyGraph).getFailureReport();
long numberOfDetectedCycles = failureReport.getDetails().stream().filter(input -> input.contains("Cycle detected: ")).count();
assertThat(numberOfDetectedCycles).as("number of cycles detected").isEqualTo(expectedNumberOfCycles);
}
use of com.tngtech.archunit.lang.FailureReport in project ArchUnit by TNG.
the class MembersShouldConjunctionTest method orShould_ORs_conditions.
@Test
@UseDataProvider("ORed_conditions")
public void orShould_ORs_conditions(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(RightOne.class, RightTwo.class, WrongOne.class));
FailureReport report = result.getFailureReport();
assertThat(report.toString()).contains(String.format("members should be declared in %s or should be declared in %s", RightOne.class.getName(), RightTwo.class.getName()));
assertThat(report.getDetails()).containsOnly(String.format("%s and %s", isNotDeclaredInMessage(WrongOne.class, CONSTRUCTOR_NAME, RightOne.class, 111), isNotDeclaredInMessage(WrongOne.class, CONSTRUCTOR_NAME, RightTwo.class, 111)), String.format("%s and %s", isNotDeclaredInMessage(WrongOne.class, "wrongMethod1", RightOne.class, 113), isNotDeclaredInMessage(WrongOne.class, "wrongMethod1", RightTwo.class, 113)));
}
use of com.tngtech.archunit.lang.FailureReport in project ArchUnit by TNG.
the class ClassesShouldConjunctionTest method andShould_ANDs_conditions.
@Test
@UseDataProvider("ANDed_conditions")
public void andShould_ANDs_conditions(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(RightOne.class, RightTwo.class, Wrong.class));
FailureReport report = result.getFailureReport();
assertThat(report.toString()).contains(String.format("classes should have fully qualified name '%s' and should have fully qualified name '%s'", RightOne.class.getName(), RightTwo.class.getName()));
assertThat(report.getDetails()).containsOnly(doesntHaveFqnMessage(RightTwo.class, RightOne.class), doesntHaveFqnMessage(RightOne.class, RightTwo.class), doesntHaveFqnMessage(Wrong.class, RightOne.class), doesntHaveFqnMessage(Wrong.class, RightTwo.class));
}
use of com.tngtech.archunit.lang.FailureReport in project ArchUnit by TNG.
the class ClassesShouldConjunctionTest method andShould_ANDs_conditions_that.
@Test
@UseDataProvider("ANDed_conditions_that")
public void andShould_ANDs_conditions_that(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(RightOne.class, RightTwo.class, Wrong.class, OtherWrong.class));
FailureReport report = result.getFailureReport();
assertThat(report.toString()).contains(String.format("no classes should access classes that have fully qualified name '%s' and should have fully qualified name '%s'", Wrong.class.getName(), OtherWrong.class.getName()));
assertThat(report.getDetails()).usingElementComparator(matchesRegex()).containsOnly(classHasFullNameRegex(OtherWrong.class) + " and " + otherWrongCallsWrongRegex());
}
Aggregations