Open rodrigobittencourtlima opened 7 months ago
I agree that this would be a nice addition to the API!
For now, you can use the following workaround:
@ArchTest
public final ArchRule methodShouldCallAudit = ArchRuleDefinition.methods().that()
.areAnnotatedWith(Transactional.class)
.should(ArchCondition.from(DescribedPredicate.describe("call Audit.audit(String, String)", method ->
method.getMethodCallsFromSelf().stream()
.map(JavaMethodCall::getTarget)
.anyMatch(methodCallTarget -> {
List<JavaClass> rawParameterTypes = methodCallTarget.getRawParameterTypes();
return methodCallTarget.getOwner().isEquivalentTo(Audit.class)
&& methodCallTarget.getName().equals("audit")
&& rawParameterTypes.size() == 2
&& rawParameterTypes.get(0).isEquivalentTo(String.class)
&& rawParameterTypes.get(1).isEquivalentTo(String.class);
})
)))
.as("Ensure system audit");
Amazing @hankem! Thank you!
Currently, it is possible to validate that certain classes must call a specific method from another class using the following rule:
It would be interesting to add the same possibility to methods, using something similar to: