Complete the code to check if the method throws the expected exception.
assertThrows([1].class, () -> calculator.divide(10, 0));
The ArithmeticException is expected when dividing by zero.
Complete the code to verify the exception message contains the expected text.
Exception exception = assertThrows(IllegalArgumentException.class, () -> parser.parse(null)); assertTrue(exception.getMessage().[1]("input cannot be null"));
We use contains to check if the exception message includes the expected text.
Fix the error in the test code to properly catch the exception.
try { service.process(null); fail("Expected [1] to be thrown"); } catch (NullPointerException e) { // test passes }
The test expects a NullPointerException when passing null to process.
Fill both blanks to assert that the method throws the correct exception with the expected message.
IllegalArgumentException thrown = assertThrows([1].class, () -> validator.validate("")); assertEquals("[2]", thrown.getMessage());
The method throws IllegalArgumentException with message "Input cannot be empty" when input is empty.
Fill all three blanks to test that the method throws the expected exception type, and the message contains the correct text.
Exception exception = assertThrows([1].class, () -> fileReader.readFile(null)); String expectedMessage = "[2]"; assertTrue(exception.getMessage().[3](expectedMessage));
The test expects IllegalArgumentException with a message containing "File path must not be null".