DatabaseAccessObject { protected static void closePreparedStatement(PreparedStatement pstmt, String errorMessage) { try { if (pstmt != null) { pstmt.close(); } } catch (SQLException e) { s_logger.warn(errorMessage, e); } }  void dropKey(Connection conn, String tableName, String key, boolean isForeignKey); void dropPrimaryKey(Connection conn, String tableName); void dropColumn(Connection conn, String tableName, String columnName); boolean columnExists(Connection conn, String tableName, String columnName);  }
@SuppressWarnings("static-access") @Test public void testClosePreparedStatementWhenPreparedStatementIsNull() throws Exception { PreparedStatement preparedStatement = null; String errorMessage = "some message"; dao.closePreparedStatement(preparedStatement, errorMessage); verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class)); }
@SuppressWarnings("static-access") @Test public void testClosePreparedStatementWhenPreparedStatementIsNotNullAndThereIsNoException() throws Exception { PreparedStatement preparedStatement = preparedStatementMock; String errorMessage = "some message"; dao.closePreparedStatement(preparedStatement, errorMessage); verify(preparedStatement, times(1)).close(); verify(loggerMock, times(0)).warn(anyString(), any(Throwable.class)); }
@SuppressWarnings("static-access") @Test public void testClosePreparedStatementWhenPreparedStatementIsNotNullAndThereIsException() throws Exception { SQLException sqlException = new SQLException(); doThrow(sqlException).when(preparedStatementMock).close(); PreparedStatement preparedStatement = preparedStatementMock; String errorMessage = "some message"; dao.closePreparedStatement(preparedStatement, errorMessage); verify(preparedStatement, times(1)).close(); verify(loggerMock, times(1)).warn(errorMessage, sqlException); }