Let's say I have a method with some of the parameters annotated with javax @Nonnull annotation.
public Something supply(@Nonnull SomeObject someObject) {
(...)
if (someObject == null) throw new ValidationException("Required parameter is null");
(...)
}
IDE correctly notifies me, when I try to call this method with explicit null argument, like this:
somethingSupplier.supply(null);
Now what I want to do is create unit test, that checks if proper exception will be thrown, if for some reason the argument passed to this method happens to be null (let's say it's some kind of validation exception).
If I try to call this method like in above example, IDE will warn me about passing null to @Nonnull... but this is exactly what I want to do here. I can annotate the call or the method or even the test class with @SuppressWarnings("ConstantConditions")
, but it clutters the code and I might not get warned about other unintentional errors I make in code.
So the question is if I can somehow disable the inspection for @Nonnull in test classes? Or perhaps I shouldn't unit test those cases at all?