Search in sources :

Example 41 with ConditionEvents

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

the class JavaAccessConditionTest method assertThatOnlyAccessToSomeClassFor.

private ConditionEventsAssertion assertThatOnlyAccessToSomeClassFor(JavaClass clazz, JavaAccessCondition<JavaAccess<?>> condition) {
    Set<JavaAccess<?>> accesses = filterByTarget(clazz.getAccessesFromSelf(), SomeClass.class);
    ConditionEvents events = new ConditionEvents();
    for (JavaAccess<?> access : accesses) {
        condition.check(access, events);
    }
    return assertThat(events);
}
Also used : JavaAccess(com.tngtech.archunit.core.domain.JavaAccess) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents)

Example 42 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(PositiveTestCase testCase) {
    ConditionEvents events = new ConditionEvents();
    testCase.condition.check(CALLER_CLASS, events);
    assertThat(events).containNoViolation();
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Theory(org.junit.experimental.theories.Theory)

Example 43 with ConditionEvents

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

the class ClassCallsCodeUnitConditionTest method call_with_wrong_method_name_doesnt_match.

@Test
public void call_with_wrong_method_name_doesnt_match() {
    ConditionEvents events = checkCondition(callMethodWhere(target(name("wrong")).and(target(rawParameterTypes(TargetClass.appendStringParams))).and(target(owner(type(TargetClass.class))))));
    assertThat(events).haveOneViolationMessageContaining(VIOLATION_MESSAGE_PARTS);
}
Also used : TargetClass(com.tngtech.archunit.lang.conditions.testobjects.TargetClass) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Test(org.junit.Test)

Example 44 with ConditionEvents

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

the class ClassCallsCodeUnitConditionTest method call_without_argument_doesnt_match.

@Test
public void call_without_argument_doesnt_match() {
    ConditionEvents events = checkCondition(callMethodWhere(target(rawParameterTypes(new Class[0])).and(target(name(TargetClass.appendStringMethod)).and(target(owner(type(TargetClass.class)))))));
    assertThat(events).haveOneViolationMessageContaining(VIOLATION_MESSAGE_PARTS);
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Test(org.junit.Test)

Example 45 with ConditionEvents

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

the class ContainsOnlyConditionTest method inverting_works.

@Test
public void inverting_works() throws Exception {
    ConditionEvents events = new ConditionEvents();
    containOnlyElementsThat(IS_SERIALIZABLE).check(TWO_SERIALIZABLE_OBJECTS, events);
    assertThat(events).containNoViolation();
    assertThat(events.getAllowed()).as("Exactly one allowed event occurred").hasSize(1);
    assertThat(getInverted(events)).containViolations(messageForTwoTimes(isSerializableMessageFor(SerializableObject.class)));
}
Also used : ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) Test(org.junit.Test)

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