We expect that the next method call will throw an exception and then we are expecting that close will be called. If you run this test then you will find that it passes with green flying colours - but there's a problem, this is the implementation of the parse method:

As you can see it never calls the close method of the passed in ResultSet - so the test should have failed. It passes because the test has exited before it gets to verify the mock ResultSet for expected behaviour.

The way around this is to use an elegant try/finally block around the code under test like this:

If you make this change to the above test then it fails as expected, now I just need to fixed the code... So you now know how to test for thrown exceptions and ensure that your mock objects are verified as well!