Search in sources :

Example 6 with JavaMember

use of com.tngtech.archunit.core.domain.JavaMember in project ArchUnit by TNG.

the class CodeUnitsShouldTest method types_match_for_constructors.

@Test
public void types_match_for_constructors() {
    EvaluationResult result = constructors().that().arePrivate().should(new ArchCondition<JavaMember>("exist") {

        @Override
        public void check(JavaMember item, ConditionEvents events) {
        }
    }).andShould(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 : ArchCondition(com.tngtech.archunit.lang.ArchCondition) JavaMember(com.tngtech.archunit.core.domain.JavaMember) ClassWithVariousMembers(com.tngtech.archunit.lang.syntax.elements.GivenCodeUnitsTest.ClassWithVariousMembers) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) JavaConstructor(com.tngtech.archunit.core.domain.JavaConstructor) Test(org.junit.Test)

Example 7 with JavaMember

use of com.tngtech.archunit.core.domain.JavaMember in project ArchUnit by TNG.

the class GivenCodeUnitsTest method types_match_for_methods.

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

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

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

        @Override
        public void check(JavaMethod method, ConditionEvents events) {
            events.add(SimpleConditionEvent.violated(method, "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) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) JavaMember(com.tngtech.archunit.core.domain.JavaMember) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Test(org.junit.Test)

Aggregations

JavaMember (com.tngtech.archunit.core.domain.JavaMember)7 ArchCondition (com.tngtech.archunit.lang.ArchCondition)7 ConditionEvents (com.tngtech.archunit.lang.ConditionEvents)7 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)4 Test (org.junit.Test)4 SimpleConditionEvent (com.tngtech.archunit.lang.SimpleConditionEvent)3 DescribedPredicate (com.tngtech.archunit.base.DescribedPredicate)2 JavaConstructor (com.tngtech.archunit.core.domain.JavaConstructor)2 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)2 ClassWithVariousMembers (com.tngtech.archunit.lang.syntax.elements.GivenCodeUnitsTest.ClassWithVariousMembers)2 JavaClass (com.tngtech.archunit.core.domain.JavaClass)1