Search in sources :

Example 1 with FailureReport

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));
}
Also used : FailureReport(com.tngtech.archunit.lang.FailureReport) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with FailureReport

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);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArchConfigurationRule(com.tngtech.archunit.testutil.ArchConfigurationRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MAX_NUMBER_OF_CYCLES_TO_DETECT_PROPERTY_NAME(com.tngtech.archunit.library.dependencies.CycleConfiguration.MAX_NUMBER_OF_CYCLES_TO_DETECT_PROPERTY_NAME) ArchConfiguration(com.tngtech.archunit.ArchConfiguration) SliceRuleTest.getNumberOfCyclesInCompleteGraph(com.tngtech.archunit.library.dependencies.SliceRuleTest.getNumberOfCyclesInCompleteGraph) SlicesRuleDefinition.slices(com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Slow(com.tngtech.archunit.Slow) Rule(org.junit.Rule) CompleteNineNodesGraphRoot(com.tngtech.archunit.library.dependencies.testexamples.completedependencygraph.ninenodes.CompleteNineNodesGraphRoot) FailureReport(com.tngtech.archunit.lang.FailureReport) FailureReport(com.tngtech.archunit.lang.FailureReport) Test(org.junit.Test)

Example 3 with FailureReport

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)));
}
Also used : FailureReport(com.tngtech.archunit.lang.FailureReport) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with FailureReport

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));
}
Also used : FailureReport(com.tngtech.archunit.lang.FailureReport) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with FailureReport

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());
}
Also used : FailureReport(com.tngtech.archunit.lang.FailureReport) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

FailureReport (com.tngtech.archunit.lang.FailureReport)7 Test (org.junit.Test)7 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 ArchConfiguration (com.tngtech.archunit.ArchConfiguration)1 Slow (com.tngtech.archunit.Slow)1 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)1 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)1 MAX_NUMBER_OF_CYCLES_TO_DETECT_PROPERTY_NAME (com.tngtech.archunit.library.dependencies.CycleConfiguration.MAX_NUMBER_OF_CYCLES_TO_DETECT_PROPERTY_NAME)1 SliceRuleTest.getNumberOfCyclesInCompleteGraph (com.tngtech.archunit.library.dependencies.SliceRuleTest.getNumberOfCyclesInCompleteGraph)1 SlicesRuleDefinition.slices (com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices)1 CompleteNineNodesGraphRoot (com.tngtech.archunit.library.dependencies.testexamples.completedependencygraph.ninenodes.CompleteNineNodesGraphRoot)1 ArchConfigurationRule (com.tngtech.archunit.testutil.ArchConfigurationRule)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Rule (org.junit.Rule)1 Category (org.junit.experimental.categories.Category)1