Search in sources :

Example 36 with ConditionEvents

use of com.tngtech.archunit.lang.ConditionEvents 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)

Example 37 with ConditionEvents

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

the class ArchConditionAssertion method checking.

public ConditionEventsAssertion checking(T item) {
    ConditionEvents events = new ConditionEvents();
    actual.check(item, events);
    return assertThat(events);
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents)

Example 38 with ConditionEvents

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

the class NeverCondition method finish.

@Override
public void finish(ConditionEvents events) {
    ConditionEvents subEvents = new ConditionEvents();
    condition.finish(subEvents);
    for (ConditionEvent event : subEvents) {
        event.addInvertedTo(events);
    }
}
Also used : ConditionEvent(com.tngtech.archunit.lang.ConditionEvent) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents)

Example 39 with ConditionEvents

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

the class ConditionEventsAssertion method newAbstractIterableAssert.

@Override
protected ConditionEventsAssertion newAbstractIterableAssert(Iterable<? extends ConditionEvent> iterable) {
    ConditionEvents actual = new ConditionEvents();
    iterable.forEach(actual::add);
    return new ConditionEventsAssertion(actual);
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents)

Example 40 with ConditionEvents

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

the class FieldAccessConditionTest method assertSatisfiedWithMessage.

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

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