I am testing a method with an expected exception. I also need to verify that some code was called (on a mocked object) after the exception is thrown, but verification is being ignored. Here is the code:
public class ExceptionHandler { @Autowired private Sender sender; public void handle(Exception exception) throws Exception { if (!SomeException.class.isAssignableFrom(exception.getClass())) { sender.sendMessage(ExceptionUtils.getStackTrace(exception)); } throw exception; } } Here is the test code:
@Mock private Sender sender; @InjectMocks private ExceptionHandler handler; @Test public void testHandler() throws Exception { SomeException someException = new SomeException(); try { handler.handle(someException); } catch (SomeException thrownResult) { assertEquals(someException, thrownResult); } verify(sender, times(1)).sendMessage(Mockito.anyString()); }