I want to do null checks for my method arguments, like parameters should not be null. Is it okay to use something like this assertNotNull("Map should not be null", filePaths);
in my Java code?
I'm trying to avoid
if(filePaths == null){
throw new IllegalArgumentException("Maps cannot be null");
}
just to keep my code clean from all those null checks. I know I can write a Validator
class of my own and have overloaded notNull
methods but is there something existing and simple to use to not re-invent the wheel.
The only drawback I see of using JUnit
Assert
is that it throws AssertionError
and not IllegalArgumentException
and so forth.
Preconditions
?Guava
, but it looks like worth giving shot