use of com.tngtech.archunit.core.domain.AccessTarget in project git-machete-intellij-plugin by VirtusLab.
the class UiThreadUnsafeMethodInvocationsTestSuite method only_ui_thread_unsafe_methods_should_call_other_ui_thread_unsafe_methods.
@Test
public void only_ui_thread_unsafe_methods_should_call_other_ui_thread_unsafe_methods() {
methods().that().areNotAnnotatedWith(UIThreadUnsafe.class).should(new ArchCondition<JavaMethod>("never call any ${UIThreadUnsafeName} methods") {
@Override
public void check(JavaMethod method, ConditionEvents events) {
// which would in turn heavily reduce readability, hence potentially leading to bugs in the long run.
if (method.getName().startsWith("access$") || method.getName().startsWith("lambda$")) {
return;
}
method.getCallsFromSelf().forEach(access -> {
AccessTarget accessTarget = access.getTarget();
if (accessTarget.isAnnotatedWith(UIThreadUnsafe.class)) {
String message = "a non-${UIThreadUnsafeName} method ${method.getFullName()} " + "calls a ${UIThreadUnsafeName} method ${accessTarget.getFullName()}";
events.add(SimpleConditionEvent.violated(method, message));
}
});
}
}).check(importedClasses);
}
Aggregations