-
Hi, We have some code which roughly looks like this: private static final Set<String> WHITELISTED_MANAGER_CLASSES = ImmutableSet.of(
SomeManager.class.getName(),
SomeOtherManager.class.getName()
// [...]
);
@Test
void whitelisted_managers_call_SomeDBLayerClass_methods() {
classes()
.that( describe( "are declared in whitelisted manager classes", target -> WHITELISTED_MANAGER_CLASSES.contains( target.getName() ) ) )
.should().callMethodWhere( target( is( declaredIn( SomeDBLayerClass.class ) ) ) )
.check( classes );
} This works fine; this check ensures that all the listed
Is there any way to get rid of this? 🤔 Basically, it seems to log every single method call from these (whitelisted) classes in question. It would be enough to just log the class name in this case. I guess the ArchUnit reporter can be customized somehow? (The reason for this test in the first place is to ensure that the whitelist is kept up-to-date. Whenever a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
In this case it would help to reformulate the rule. I would try formulating it like this
|
Beta Was this translation helpful? Give feedback.
-
I think you can achieve your goal with a custom // ...
.should(new ArchCondition<JavaClass>("call a method in SomeDBLayerClass") {
@Override
public void check(JavaClass javaClass, ConditionEvents conditionEvents) {
if (javaClass.getMethodCallsFromSelf().stream().noneMatch(call -> call.getTargetOwner().isEquivalentTo(SomeDBLayerClass.class))) {
conditionEvents.add(SimpleConditionEvent.violated(javaClass, javaClass.getName() + " does not call a method in SomeDBLayerClass"));
}
}
}) // ... |
Beta Was this translation helpful? Give feedback.
I think you can achieve your goal with a custom
ArchCondition
: