Search in sources :

Example 21 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class GivenSlicesTest method restricting_slices_that_should_not_depend_on_each_other.

@Test
public void restricting_slices_that_should_not_depend_on_each_other() {
    archConfigurationRule.setFailOnEmptyShould(false);
    GivenSlices givenSlices = slices().matching("..testclasses.(*)..");
    JavaClasses classes = new ClassFileImporter().importPackages("com.tngtech.archunit.library.testclasses");
    EvaluationResult result = givenSlices.that(DescribedPredicate.<Slice>alwaysFalse()).and(DescribedPredicate.<Slice>alwaysTrue()).should().notDependOnEachOther().evaluate(classes);
    assertThat(result.hasViolation()).as("Result has violation").isFalse();
    result = givenSlices.that(DescribedPredicate.<Slice>alwaysTrue()).or(DescribedPredicate.<Slice>alwaysFalse()).should().notDependOnEachOther().evaluate(classes);
    assertThat(result.hasViolation()).as("Result has violation").isTrue();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) GivenSlices(com.tngtech.archunit.library.dependencies.syntax.GivenSlices) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArchitecturesTest(com.tngtech.archunit.library.ArchitecturesTest) Test(org.junit.Test)

Example 22 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class PlantUmlArchConditionTest method can_handle_all_possible_user_inputs_without_violations.

@Test
@UseDataProvider("possibleInputTypes")
public void can_handle_all_possible_user_inputs_without_violations(PlantUmlCreationTestCase testCase) {
    File file = TestDiagram.in(temporaryFolder).component("SomeOrigin").withStereoTypes("..origin").component("SomeTarget").withStereoTypes("..target").dependencyFrom("[SomeOrigin]").to("[SomeTarget]").write();
    PlantUmlArchCondition condition = testCase.createConditionFrom(file);
    EvaluationResult result = createEvaluationResult(condition, "simpledependency");
    assertNoViolation(result);
}
Also used : File(java.io.File) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 23 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class PlantUmlArchConditionTest method assertConditionHasNumberOfFailures.

private void assertConditionHasNumberOfFailures(JavaClasses classes, PlantUmlArchCondition condition, int expectedNumberOfFailures) {
    EvaluationResult result = classes().should(condition).evaluate(classes);
    assertThat(result.getFailureReport().getDetails()).as("number of failures").hasSize(expectedNumberOfFailures);
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult)

Example 24 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class MethodsShouldTest method property_predicates.

@Test
@UseDataProvider("restricted_property_rule_ends")
public void property_predicates(ArchRule ruleStart, Collection<String> expectedMembers) {
    EvaluationResult result = ruleStart.evaluate(importClasses(ClassWithVariousMembers.class));
    Set<String> actualMethods = parseMembers(ClassWithVariousMembers.class, result.getFailureReport().getDetails());
    assertThat(actualMethods).containsOnlyElementsOf(expectedMembers);
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 25 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.

the class ClassesShouldTest method haveSimpleNameEndingWith.

@Test
@UseDataProvider("haveSimpleNameEndingWith_rules")
public void haveSimpleNameEndingWith(ArchRule rule, String suffix) {
    EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name ending with '%s'", suffix)).containsPattern(String.format("simple name of %s does not end with '%s' in %s", quote(WrongNamedClass.class.getName()), quote(suffix), locationPattern(WrongNamedClass.class))).doesNotContain(SomeClass.class.getName());
}
Also used : SomeClass(com.tngtech.archunit.lang.syntax.elements.testclasses.SomeClass) WrongNamedClass(com.tngtech.archunit.lang.syntax.elements.testclasses.WrongNamedClass) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)140 Test (org.junit.Test)132 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)107 CanBeAnnotatedTest (com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest)63 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)13 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)13 SomeClass (com.tngtech.archunit.lang.syntax.elements.testclasses.SomeClass)12 WrongNamedClass (com.tngtech.archunit.lang.syntax.elements.testclasses.WrongNamedClass)12 ArchCondition (com.tngtech.archunit.lang.ArchCondition)7 ArchRule (com.tngtech.archunit.lang.ArchRule)6 FailureReport (com.tngtech.archunit.lang.FailureReport)6 ClassWithVariousMembers (com.tngtech.archunit.lang.syntax.elements.GivenCodeUnitsTest.ClassWithVariousMembers)6 SimpleFieldAndMethod (com.tngtech.archunit.lang.syntax.elements.testclasses.SimpleFieldAndMethod)6 ArchTest (com.tngtech.archunit.junit.ArchTest)5 OnionArchitecture (com.tngtech.archunit.library.Architectures.OnionArchitecture)5 ArchConfiguration (com.tngtech.archunit.ArchConfiguration)4 JavaMember (com.tngtech.archunit.core.domain.JavaMember)4 ConditionEvents (com.tngtech.archunit.lang.ConditionEvents)4 ClassWithVariousMembers (com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.ClassWithVariousMembers)3 Date (java.util.Date)3