Complete the code to test that the method throws NullPointerException.
assertThrows([1].class, () -> myObject.myMethod(null));
The assertThrows method expects the exception class that should be thrown. Here, NullPointerException.class is correct to test for a null argument.
Complete the code to test that the method throws either IOException or SQLException.
assertThrows([1].class, () -> myObject.myMethod());
Using Exception.class covers multiple checked exceptions like IOException and SQLException in one test.
Fix the error in the test that expects multiple exceptions using assertThrows.
assertThrows([1].class, () -> myObject.myMethod());
You cannot use the '|' operator inside assertThrows. Instead, use the common superclass Exception.class to catch multiple exceptions.
Fill both blanks to correctly test that either IllegalArgumentException or NullPointerException is thrown.
Throwable thrown = assertThrows([1].class, () -> myObject.myMethod([2]));
Both IllegalArgumentException and NullPointerException extend RuntimeException, so using RuntimeException.class works. Passing null triggers NullPointerException.
Fill all three blanks to test multiple exceptions and check the exception message.
Exception exception = assertThrows([1].class, () -> myObject.myMethod([2])); assertTrue(exception.getMessage().[3]("error"));
Using Exception.class covers multiple exceptions. Passing null triggers an exception. Checking if the message contains the word "error" verifies the error details.