Complete the code to check that the exception is thrown.
assertThrows(IllegalArgumentException.class, () -> methodThatThrows([1]));
The method expects a null input to throw IllegalArgumentException.
Complete the code to capture the exception and check its message.
Exception exception = assertThrows(IllegalArgumentException.class, () -> methodThatThrows(null)); assertEquals([1], exception.getMessage());
The exception message expected is "Invalid input".
Fix the error in the assertion to correctly check the exception message.
assertEquals([1], exception.getMessage());The expected message should be the first argument in assertEquals.
Fill both blanks to check exception type and message in one test.
Throwable thrown = assertThrows([1].class, () -> methodThatThrows(null)); assertTrue(thrown.getMessage().contains([2]));
The test checks that IllegalArgumentException is thrown and its message contains "Invalid".
Fill all three blanks to assert exception type, message, and cause.
IllegalArgumentException ex = assertThrows([1].class, () -> methodThatThrows(null)); assertEquals([2], ex.getMessage()); assertNotNull(ex.getCause()); assertTrue(ex.getCause() instanceof [3]);
The test asserts the exception type, exact message, and that the cause is a NullPointerException.
