Search in sources :

Example 6 with EvaluationResult

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

the class GivenMembersTest method declaration_predicates.

@Test
@UseDataProvider("restricted_declaration_rule_starts")
public void declaration_predicates(DescribedRuleStart conjunction, Set<String> expectedMessages) {
    EvaluationResult result = conjunction.should(everythingViolationPrintMemberName()).evaluate(importClasses(ClassWithVariousMembers.class, OtherClassWithMembers.class));
    assertThat(result.getFailureReport().getDetails()).containsOnlyElementsOf(expectedMessages);
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 7 with EvaluationResult

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

the class GivenMembersTest method complex_members_syntax.

@Test
public void complex_members_syntax() {
    EvaluationResult result = members().that().haveName(FIELD_A).or().arePublic().and(areNoFieldsWithType(List.class)).should(beAnnotatedWith(B.class)).evaluate(importClasses(ClassWithVariousMembers.class));
    assertViolation(result);
    assertThat(result.getFailureReport().getDetails()).containsOnly(String.format("Member '%s' is not annotated with @B", FIELD_A), String.format("Member '%s' is not annotated with @B", CONSTRUCTOR_THREE_ARGS), String.format("Member '%s' is not annotated with @B", METHOD_C));
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test)

Example 8 with EvaluationResult

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

the class GivenMethodsTest method property_predicates.

@Test
@UseDataProvider("restricted_property_rule_starts")
public void property_predicates(DescribedRuleStart ruleStart, Collection<String> expectedMembers) {
    EvaluationResult result = ruleStart.should(everythingViolationPrintMemberName()).evaluate(importClasses(ClassWithVariousMembers.class));
    assertThat(result.getFailureReport().getDetails()).containsOnlyElementsOf(expectedMembers);
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) GivenMembersTest(com.tngtech.archunit.lang.syntax.elements.GivenMembersTest) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 9 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult 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 10 with EvaluationResult

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

the class MembersShouldTest method haveNameNotContaining.

@Test
@UseDataProvider("haveNameNotContaining_rules")
public void haveNameNotContaining(ArchRule rule, String infix) {
    EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));
    assertThat(singleLineFailureReportOf(result)).containsPattern(String.format(".*%s.* name contains '%s' in %s", quote(infix), quote(infix), 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)

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