@Test public void shouldCommitIfExecuteSucceeds() throws Exception { final JDBCBase.ConnectionBlock mockConnectionBlock = mock(JDBCBase.ConnectionBlock.class); initializeJDBCTestSubclass(); jdbcTestSubclass.execute(mockConnectionBlock); verify(mockConnection, times(2)).commit(); verify(mockConnection, times(0)).close(); }
protected final void execute(ConnectionBlock connectionBlock) throws Exception { checkState(initialized); setupConnection(); checkNotNull(connection); boolean committed = false; try { connectionBlock.use(connection); connection.commit(); committed = true; } finally { if (!committed) { connection.rollback(); cleanupConnection(); } } }
JDBCBase { protected final void execute(ConnectionBlock connectionBlock) throws Exception { checkState(initialized); setupConnection(); checkNotNull(connection); boolean committed = false; try { connectionBlock.use(connection); connection.commit(); committed = true; } finally { if (!committed) { connection.rollback(); cleanupConnection(); } } } }
JDBCBase { protected final void execute(ConnectionBlock connectionBlock) throws Exception { checkState(initialized); setupConnection(); checkNotNull(connection); boolean committed = false; try { connectionBlock.use(connection); connection.commit(); committed = true; } finally { if (!committed) { connection.rollback(); cleanupConnection(); } } } protected  JDBCBase(String url, String username, @Nullable String password); }
JDBCBase { protected final void execute(ConnectionBlock connectionBlock) throws Exception { checkState(initialized); setupConnection(); checkNotNull(connection); boolean committed = false; try { connectionBlock.use(connection); connection.commit(); committed = true; } finally { if (!committed) { connection.rollback(); cleanupConnection(); } } } protected  JDBCBase(String url, String username, @Nullable String password); synchronized final void initialize(); synchronized final void teardown(); }
JDBCBase { protected final void execute(ConnectionBlock connectionBlock) throws Exception { checkState(initialized); setupConnection(); checkNotNull(connection); boolean committed = false; try { connectionBlock.use(connection); connection.commit(); committed = true; } finally { if (!committed) { connection.rollback(); cleanupConnection(); } } } protected  JDBCBase(String url, String username, @Nullable String password); synchronized final void initialize(); synchronized final void teardown();  }