Closed omuomugin closed 5 months ago
This is mostly a logical confusion (that happened to me several times, too):
For different and mutually exclusive properties X and Y, a rule
M should (not have X) or should (not have Y).
is always satisfied:
Your rule should work as expected when you use
M should (not have X) and should (not have Y).
To answer the actual question: For methods with void
return type, method.getRawReturnType()
returns a JavaClass
equivalent to void.class
, whose name is "void"
.
FYI: ArchUnit also has another way to describe anti-patterns:
no M should (have X) or should (have Y).
So the most concise definition of your rule is probably:
noMethods().that().areAnnotatedWith(ApiResponse.class).should().haveRawReturnType("void")
is always satisfied:
This is so right !! Thanks for your help
noMethods().that().areAnnotatedWith(ApiResponse.class).should().haveRawReturnType("void")
this worked as expected!
I'm trying to check that method which is annotated with
ApiResponse
should return with something.neither of check is not working. Is there any way to check return type is
void
? (code below is Kotlin, feel free to ask me to write in Java)