1@Test
2void testExpectedException() {
3
4 Assertions.assertThrows(NumberFormatException.class, () -> {
5 Integer.parseInt("One");
6 });
7
8}
1Throwable exceptionThatWasThrown = assertThrows(NullPointerException.class, () -> {
2 codeThatThrows;
3});
4
5assertThat(exceptionThatWasThrown.getMessage(), equalTo("Message I expected to be thrown"));