JdbcUtil { public static Connection getConnection(AdaptrisMessage msg, AdaptrisConnection adpCon) throws SQLException { Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY); if (conn != null && !conn.isClosed()) { return conn; } else { return adpCon.retrieveConnection(DatabaseConnection.class).connect(); } }  static void closeQuietly(AutoCloseable... closeables); static void rollback(Savepoint svp, Connection sqlConnection); static void rollback(Connection sqlConnection); static void commit(Connection sqlConnection); static Savepoint createSavepoint(Connection sqlConnection); static Connection testConnection(Connection sqlConnection, String testStatement, boolean debugMode); static Properties mergeConnectionProperties(Properties p, String username, String password); static Connection getConnection(AdaptrisMessage msg, AdaptrisConnection adpCon); static void rollback(Connection sqlConnection, AdaptrisMessage msg); static void commit(Connection sqlConnection, AdaptrisMessage msg);  }
@Test public void testGetConnection() throws Exception { Connection metadata = mock(Connection.class); Connection closed = mock(Connection.class); Connection configured = mock(Connection.class); Mockito.when(configured.getAutoCommit()).thenReturn(true); Mockito.when(closed.isClosed()).thenReturn(true); JdbcConnection jdbcCon = new MyJdbcConnection(configured); try { LifecycleHelper.initAndStart(jdbcCon); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); msg.getObjectHeaders().put(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY, metadata); assertEquals(metadata, getConnection(msg, jdbcCon)); msg.getObjectHeaders().put(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY, closed); assertEquals(configured, getConnection(msg, jdbcCon)); msg.getObjectHeaders().clear(); assertEquals(configured, getConnection(msg, jdbcCon)); } finally { LifecycleHelper.stopAndClose(jdbcCon); } }