@Test
public void shouldCreateSecondConnectionAfterFirstThrowsExceptionInsideExecute() throws Exception {

    final JDBCBase.ConnectionBlock mockConnectionBlock = mock(JDBCBase.ConnectionBlock.class);
    final List<Connection> connectionsUsed = Lists.newArrayList();
    // store the connections used
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            connectionsUsed.add((Connection) invocation.getArguments()[0]);
            // the first call will throw
            if (connectionsUsed.size() == 1) {
                throw new IllegalArgumentException("first invocation");
            }
            return null;
        }
    }).when(mockConnectionBlock).use(any(Connection.class));
    initializeJDBCTestSubclass();
    // check that the first call throws
    assertThatExceptionIsThrown(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            jdbcTestSubclass.execute(mockConnectionBlock);
            return null;
        }
    }, IllegalArgumentException.class);
    // and that we clean up properly
    InOrder inOrder = inOrder(mockConnection);
    inOrder.verify(mockConnection).rollback();
    inOrder.verify(mockConnection).close();
    // call again, and verify that the connection was replaced
    jdbcTestSubclass.execute(mockConnectionBlock);
    // check that we were handed two different connections in order!
    assertThat(connectionsUsed, hasSize(2));
    assertThat(connectionsUsed, contains(mockConnection, mockReplacedConnection));
}