Search in sources :

Example 1 with EvaluationResult

use of com.tngtech.archunit.lang.EvaluationResult in project jmolecules-integrations by xmolecules.

the class JMoleculesOnionSimpleArchitectureRulesTest method ensureOnionSimple.

@ArchTest
void ensureOnionSimple(JavaClasses types) {
    EvaluationResult result = JMoleculesArchitectureRules.ensureOnionSimple().evaluate(types);
    // 
    assertThat(result.getFailureReport().getDetails()).satisfiesExactlyInAnyOrder(// 
    violation(AppType.class, InfraType.class), // 
    violation(AppType.class, InfraByAnnotation.class), // 
    violation(DomainType.class, AppType.class), // 
    violation(DomainType.class, AppByAnnotation.class), // 
    violation(DomainType.class, InfraType.class), // 
    violation(DomainType.class, InfraByAnnotation.class));
}
Also used : AppByAnnotation(org.jmolecules.archunit.onion.simple.AppByAnnotation) DomainType(org.jmolecules.archunit.onion.simple.domain.DomainType) InfraByAnnotation(org.jmolecules.archunit.onion.simple.InfraByAnnotation) AppType(org.jmolecules.archunit.onion.simple.app.AppType) InfraType(org.jmolecules.archunit.onion.simple.infra.InfraType) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ArchTest(com.tngtech.archunit.junit.ArchTest)

Example 2 with EvaluationResult

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

the class GivenCodeUnitsTest method types_match_for_constructors.

@Test
public void types_match_for_constructors() {
    EvaluationResult result = constructors().that(new DescribedPredicate<JavaMember>("are there") {

        @Override
        public boolean test(JavaMember input) {
            return true;
        }
    }).and(new DescribedPredicate<JavaConstructor>("are there") {

        @Override
        public boolean test(JavaConstructor input) {
            return true;
        }
    }).should(new ArchCondition<JavaConstructor>("not exist") {

        @Override
        public void check(JavaConstructor constructor, ConditionEvents events) {
            events.add(SimpleConditionEvent.violated(constructor, "expected violation"));
        }
    }).evaluate(importClasses(ClassWithVariousMembers.class));
    assertThat(Joiner.on(" ").join(result.getFailureReport().getDetails())).contains("expected violation");
}
Also used : DescribedPredicate(com.tngtech.archunit.base.DescribedPredicate) ArchCondition(com.tngtech.archunit.lang.ArchCondition) JavaMember(com.tngtech.archunit.core.domain.JavaMember) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) JavaConstructor(com.tngtech.archunit.core.domain.JavaConstructor) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Test(org.junit.Test)

Example 3 with EvaluationResult

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

the class GivenCodeUnitsTest method parameter_types_predicates.

@Test
@UseDataProvider("restricted_parameter_types_rule_starts")
public void parameter_types_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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with EvaluationResult

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

the class GivenCodeUnitsTest method complex_code_unit_syntax.

@Test
public void complex_code_unit_syntax() {
    EvaluationResult result = codeUnits().that().areNotPackagePrivate().and().haveRawParameterTypes(lessThanTwo()).or(have(modifier(PUBLIC))).should(beAnnotatedWith(A.class)).evaluate(importClasses(ClassWithVariousMembers.class));
    assertViolation(result);
    assertThat(result.getFailureReport().getDetails()).containsOnly(String.format("Member '%s' is not annotated with @A", METHOD_ONE_ARG), String.format("Member '%s' is not annotated with @A", METHOD_THREE_ARGS), String.format("Member '%s' is not annotated with @A", CONSTRUCTOR_ONE_ARG), String.format("Member '%s' is not annotated with @A", CONSTRUCTOR_THREE_ARGS));
}
Also used : EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test)

Example 5 with EvaluationResult

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

the class GivenFieldsTest 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) 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