So it may be, that I have a basical missunderstanding in Java. Lets assume I have a method, which gets an Object as parameter. Does it even make sense or is it possible to test, what happens, when I pass null?:
@Test(expected = NullPointerException.class)
public void test_nullPointer() {
doThrow(new NullPointerException()).when(myService).getSomeInformation(null);
classUnderTest.doSomething(null);
verify(myService).getSomeInformation(isNull(myObject.class));
}
Of course this doesn't work. But it's what I am currently trying to realise, if of course it even makes sense to do so.
Edit: The myService.getSomeInformation(myObject obj) gets called, when I call classUnderTest.doSomething(myObject obj). So it passes the obj to myService to return something based on the obj.
The thing is, I just want to ensure, that if any other class would call classUnderTest.doSomething(null), a uncatched NullPointerException is thrown. It's just the question if this is even necessary, testing this behaviour. And if yes, how to realise it.