-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method support for function callMethod #1228
Comments
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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: