DBUtils { public static void closeQuietly(java.sql.ResultSet resultSet){ if (resultSet == null) return; try { Statement statement = resultSet.getStatement(); if (statement != null){ statement.close(); } }catch(Exception e){ } try{ resultSet.close(); }catch (Exception e){ } }  static Closeable wrapAsCloseable(final ResultSet resultSet); static boolean setAutoCommit(final Connection connection, final boolean value); static void commit(final Connection connection); static boolean rollback(final Connection connection); static void closeQuietly(java.sql.ResultSet resultSet); static void closeQuietly(Statement statement); static void closeQuietly(Connection connection); static String getDBTypeForClass(final Class<?> valueType); static void setValueToPreparedStatement(int index, final PreparedStatement preparedStatement, Object value); static int setValuesToPreparedStatement(final int startIndex, final PreparedStatement preparedStatement, final Iterable values); @SuppressWarnings("unchecked") static T getValueFromResultSet(int index, final ResultSet resultSet, final Class<T> type); static String sanitizeForTableName(String input);  }
@Test public void testCloseResultSetQuietly() throws Exception { Statement statement = mock(Statement.class); ResultSet resultSet = mock(ResultSet.class); when(resultSet.getStatement()).thenReturn(statement); DBUtils.closeQuietly(resultSet); verify(resultSet, times(1)).close(); verify(statement, times(1)).close(); }
@Test public void testCloseResultSetQuietly_NullStatement() throws Exception { ResultSet resultSet = mock(ResultSet.class); when(resultSet.getStatement()).thenReturn(null); DBUtils.closeQuietly(resultSet); verify(resultSet, times(1)).close(); }
@Test public void testCloseResultSetQuietly_Null() throws Exception { ResultSet resultSet = null; DBUtils.closeQuietly(resultSet); }
@Test public void testCloseResultSetQuietly_ResultSetCloseException() throws Exception { Statement statement = mock(Statement.class); ResultSet resultSet = mock(ResultSet.class); when(resultSet.getStatement()).thenReturn(statement); doThrow(new SQLException("SQL Exception")).when(resultSet).close(); DBUtils.closeQuietly(resultSet); verify(resultSet, times(1)).close(); verify(statement, times(1)).close(); }
@Test public void testCloseResultSetQuietly_StatementCloseException() throws Exception { Statement statement = mock(Statement.class); ResultSet resultSet = mock(ResultSet.class); when(resultSet.getStatement()).thenReturn(statement); doThrow(new SQLException("SQL Exception")).when(statement).close(); DBUtils.closeQuietly(resultSet); verify(resultSet, times(1)).close(); verify(statement, times(1)).close(); }
@Test public void testCloseStatementQuietly() throws Exception { Statement statement = mock(Statement.class); DBUtils.closeQuietly(statement); verify(statement, times(1)).close(); }
@Test public void testCloseStatementQuietly_Null() throws Exception { Statement statement = null; DBUtils.closeQuietly(statement); }
@Test public void testCloseStatementQuietly_Exception() throws Exception { Statement statement = mock(Statement.class); doThrow(new SQLException("SQL Exception")).when(statement).close(); DBUtils.closeQuietly(statement); verify(statement, times(1)).close(); }
@Test public void testCloseConnectionQuietly() throws Exception { Connection connection = mock(Connection.class); DBUtils.closeQuietly(connection); verify(connection, times(1)).close(); }
@Test public void testCloseConnectionQuietly_Null() throws Exception { Connection connection = null; DBUtils.closeQuietly(connection); }
@Test public void testCloseConnectionQuietly_Exception() throws Exception { Connection connection = mock(Connection.class); doThrow(new SQLException("SQL Exception")).when(connection).close(); DBUtils.closeQuietly(connection); verify(connection, times(1)).close(); }