Search in sources :

Example 16 with ConditionEvents

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

the class CodeUnitsShouldTest method types_match_for_methods.

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

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

Example 17 with ConditionEvents

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

the class FieldAccessConditionTest method checkCondition.

private ConditionEvents checkCondition(FieldAccessCondition getFieldCondition, JavaFieldAccess access) {
    ConditionEvents events = new ConditionEvents();
    getFieldCondition.check(access, events);
    return events;
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents)

Example 18 with ConditionEvents

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

the class FieldAccessConditionTest method assertViolatedWithMessage.

private void assertViolatedWithMessage(FieldAccessCondition getFieldCondition, JavaFieldAccess access, String accessDescription) {
    ConditionEvents events = checkCondition(getFieldCondition, access);
    boolean satisfied = !events.containViolation();
    assertThat(satisfied).as("Events are satisfied").isFalse();
    assertThat(events.getAllowed()).isEmpty();
    assertDescription(access, accessDescription, messageOf(events.getViolating()));
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents)

Example 19 with ConditionEvents

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

the class NeverConditionTest method inverts_condition.

@Test
@UseDataProvider("conditions")
public void inverts_condition(ArchCondition<Object> condition) {
    ConditionEvents events = new ConditionEvents();
    condition.check(new Object(), events);
    condition.finish(events);
    assertThat(events).containAllowed(ORIGINALLY_NO_MISMATCH);
    assertThat(events).containViolations(ORIGINALLY_MISMATCH);
    events = new ConditionEvents();
    never(condition).check(new Object(), events);
    never(condition).finish(events);
    assertThat(events).containAllowed(ORIGINALLY_MISMATCH);
    assertThat(events).containViolations(ORIGINALLY_NO_MISMATCH);
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 20 with ConditionEvents

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

the class ClassAccessesFieldConditionTest method condition_works.

@Theory
public void condition_works(NegativeTestCase testCase) {
    ConditionEvents events = new ConditionEvents();
    testCase.condition.check(CALLER_CLASS, events);
    assertThat(events).haveOneViolationMessageContaining(testCase.violationMessageParts());
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Theory(org.junit.experimental.theories.Theory)

Aggregations

ConditionEvents (com.tngtech.archunit.lang.ConditionEvents)53 ArchCondition (com.tngtech.archunit.lang.ArchCondition)31 JavaClass (com.tngtech.archunit.core.domain.JavaClass)25 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)22 SimpleConditionEvent (com.tngtech.archunit.lang.SimpleConditionEvent)22 Test (org.junit.Test)15 List (java.util.List)9 SourcePredicates.isJavaClass (org.apache.flink.architecture.common.SourcePredicates.isJavaClass)9 DescribedPredicate (com.tngtech.archunit.base.DescribedPredicate)8 JavaMember (com.tngtech.archunit.core.domain.JavaMember)7 Collectors (java.util.stream.Collectors)7 JavaParameterizedType (com.tngtech.archunit.core.domain.JavaParameterizedType)6 JavaType (com.tngtech.archunit.core.domain.JavaType)6 HasName (com.tngtech.archunit.core.domain.properties.HasName)6 Collections (java.util.Collections)6 Stream (java.util.stream.Stream)6 JavaField (com.tngtech.archunit.core.domain.JavaField)5 ConditionEvent (com.tngtech.archunit.lang.ConditionEvent)4 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)4 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)3