Post

Java getMessage vs toString For NullPointerException

1
2
3
4
5
6
7
8
9
10
@Test
public class testNullPointerException {
    Throwable expectedException = assertThrow(NullPointerException.class, () -> {
        throw new NullPointerException();
    });
    assertAll("Expect NullPointerException.getMessage() is Null; .toString() is 'null'"
        assertNull(expectedException.getMessage());
        assertEquals("", expectedException.toString());
    );
}
This post is licensed under CC BY 4.0 by the author.