IDE: Intellij
I am using Lombok's NonNull annotation to automatically generate Null Pointer Checks and throw exceptions on Method Arguments and Return Types.
On writing Unit Tests, the 'null' method Arguments do throw the exception, but the null return types do not throw exceptions.
import lombok.NonNull;
public @NonNull String function( @NonNull String input) {
return null;
}
The following Test fails:
@Test
public void
whenReturnTypeIsNull_ThenIllegalArgumentExceptionIsThrown(){
assertThrows(IllegalArgumentException.class, ()-> testClass.function() );
}
With the Message:
Expected java.lang.IllegalArgumentException to be thrown, but nothing was thrown