Search in sources :

Example 11 with EvaluationResult

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

the class MembersShouldTest method complex_members_syntax.

@Test
public void complex_members_syntax() {
    EvaluationResult result = members().that(areNoFieldsWithType(List.class)).and().haveNameMatching(".*field.*").should().beAnnotatedWith(B.class).andShould().notBePublic().orShould().bePrivate().evaluate(importClasses(ClassWithVariousMembers.class));
    assertViolation(result);
    String failure = getOnlyElement(result.getFailureReport().getDetails());
    assertThat(failure).matches(String.format(".*Field .*%s.* does not have modifier PRIVATE.*", FIELD_D)).contains("and Field").matches(String.format(".*Field .*%s.* is not annotated with @B.*", FIELD_D));
}
Also used : B(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.B) FIELD_B(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.FIELD_B) METHOD_B(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.METHOD_B) ClassWithVariousMembers(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.ClassWithVariousMembers) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test)

Example 12 with EvaluationResult

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

the class MembersShouldTest method property_predicates.

@Test
@UseDataProvider("restricted_property_rule_ends")
public void property_predicates(MembersShouldConjunction<?> conjunction, Set<String> expectedMembers) {
    EvaluationResult result = conjunction.evaluate(importClasses(ClassWithVariousMembers.class, A.class, B.class, C.class, MetaAnnotation.class));
    Set<String> actualMembers = parseMembers(result.getFailureReport().getDetails());
    assertThat(actualMembers).containsOnlyElementsOf(expectedMembers);
}
Also used : A(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.A) CONSTRUCTOR_ANNOTATED_WITH_A(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.CONSTRUCTOR_ANNOTATED_WITH_A) FIELD_A(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.FIELD_A) METHOD_ANNOTATED_WITH_A(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.METHOD_ANNOTATED_WITH_A) FIELD_ANNOTATED_WITH_A(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.FIELD_ANNOTATED_WITH_A) METHOD_A(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.METHOD_A) B(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.B) FIELD_B(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.FIELD_B) METHOD_B(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.METHOD_B) FIELD_PUBLIC(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.FIELD_PUBLIC) C(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.C) FIELD_C(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.FIELD_C) METHOD_C(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.METHOD_C) METHOD_PUBLIC(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.METHOD_PUBLIC) CONSTRUCTOR_PUBLIC(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.CONSTRUCTOR_PUBLIC) MetaAnnotation(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.MetaAnnotation) ClassWithVariousMembers(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest.ClassWithVariousMembers) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 13 with EvaluationResult

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

the class MembersShouldTest method haveNameNotStartingWith.

@Test
@UseDataProvider("haveNameNotStartingWith_rules")
public void haveNameNotStartingWith(ArchRule rule, String prefix) {
    EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));
    assertThat(singleLineFailureReportOf(result)).containsPattern(String.format(".*%s.* name starts with '%s' in %s", quote(prefix), quote(prefix), locationPattern(SimpleFieldAndMethod.class)));
}
Also used : SimpleFieldAndMethod(com.tngtech.archunit.lang.syntax.elements.testclasses.SimpleFieldAndMethod) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 14 with EvaluationResult

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

the class MembersShouldTest method haveNameEndingWith.

@Test
@UseDataProvider("haveNameEndingWith_rules")
public void haveNameEndingWith(ArchRule rule, String suffix, String violatingMember) {
    EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));
    assertThat(singleLineFailureReportOf(result)).containsPattern(String.format(".*%s.* name does not end with '%s' in %s", quote(violatingMember), quote(suffix), locationPattern(SimpleFieldAndMethod.class)));
}
Also used : SimpleFieldAndMethod(com.tngtech.archunit.lang.syntax.elements.testclasses.SimpleFieldAndMethod) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with EvaluationResult

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

the class ArchitecturesTest method layered_architecture_allows_individual_empty_optionalLayer.

@Test
public void layered_architecture_allows_individual_empty_optionalLayer() {
    LayeredArchitecture architecture = layeredArchitecture().optionalLayer("can be absent").definedBy(absolute("should.not.be.found.."));
    JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
    EvaluationResult result = architecture.evaluate(classes);
    assertThat(result.hasViolation()).as("result of evaluating empty optionalLayer has violation").isFalse();
    assertThat(result.getFailureReport().isEmpty()).as("failure report").isTrue();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

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