Search in sources :

Example 1 with AccessesSimulator

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

the class ArchConditionsTest method never_call_method_where_target_owner_is_assignable_to.

@Test
public void never_call_method_where_target_owner_is_assignable_to() {
    JavaClass callingClass = importClassWithContext(CallingClass.class);
    AccessesSimulator simulateCall = simulateCall();
    JavaClass someClass = importClassWithContext(SomeClass.class);
    JavaMethod doNotCallMe = someClass.getMethod("doNotCallMe");
    JavaMethodCall callTodoNotCallMe = simulateCall.from(callingClass.getMethod("call"), 0).to(doNotCallMe);
    ArchCondition<JavaClass> condition = never(callMethodWhere(target(name("doNotCallMe")).and(target(owner(assignableTo(SomeSuperclass.class))))));
    assertThat(condition).checking(callingClass).containViolations(callTodoNotCallMe.getDescription());
    condition = never(callMethodWhere(target(name("doNotCallMe")).and(target(owner(type(SomeSuperclass.class))))));
    assertThat(condition).checking(callingClass).containNoViolation();
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) JavaMethod(com.tngtech.archunit.core.domain.JavaMethod) JavaMethodCall(com.tngtech.archunit.core.domain.JavaMethodCall) AccessesSimulator(com.tngtech.archunit.core.domain.TestUtils.AccessesSimulator) Test(org.junit.Test)

Aggregations

JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)1 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)1 AccessesSimulator (com.tngtech.archunit.core.domain.TestUtils.AccessesSimulator)1 Test (org.junit.Test)1