I am testing a method with an expected exception. I also need to verify that some cleanup code was called (on a mocked object) after the exception is thrown, but it looks li
More elegant solution with catch-exception
@Test
public void testExpectedException()
{
MockedObject mockObj = mock(MockedObject.class);
MySubject subject = new MySubject(mockObj);
when(subject).someMethodThrowingException();
then(caughtException())
.isInstanceOf(MyException.class)
.hasMessage("My exception message.");
verify(mockObj).someCleanup(eq(...));
}