@Test public void testcount() throws Exception { when(connection.createStatement()).thenReturn(statement); when(statement.executeQuery(anyString())).thenReturn(rs); when(rs.next()).thenReturn(true, false); when(rs.getInt(anyString())).thenReturn(5); doNothing().when(rs).close(); doNothing().when(connection).close(); doNothing().when(statement).close(); mockStatic(DriverManager.class); when(DriverManager.getConnection(anyString(), any(Properties.class))).thenReturn(connection); ReflectionTestUtils.setField(repository, "userName", ""); ReflectionTestUtils.setField(repository, "password", ""); ReflectionTestUtils.setField(repository, "dbURL", ""); int a = repository.count("query"); assertTrue(a == 5); }
public int count(String query) { int result = 0; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); stmt = conn.createStatement(); rs = stmt.executeQuery(query); while (rs.next()) { result = rs.getInt("count"); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (stmt != null) { stmt.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (conn != null) { conn.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } } return result; }
PacmanRedshiftRepository { public int count(String query) { int result = 0; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); stmt = conn.createStatement(); rs = stmt.executeQuery(query); while (rs.next()) { result = rs.getInt("count"); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (stmt != null) { stmt.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (conn != null) { conn.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } } return result; } }
PacmanRedshiftRepository { public int count(String query) { int result = 0; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); stmt = conn.createStatement(); rs = stmt.executeQuery(query); while (rs.next()) { result = rs.getInt("count"); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (stmt != null) { stmt.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (conn != null) { conn.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } } return result; }  }
PacmanRedshiftRepository { public int count(String query) { int result = 0; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); stmt = conn.createStatement(); rs = stmt.executeQuery(query); while (rs.next()) { result = rs.getInt("count"); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (stmt != null) { stmt.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (conn != null) { conn.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } } return result; }  int count(String query); List<Map<String, String>> executeQuery(String query); int[] batchUpdate(List<String> queries); }
PacmanRedshiftRepository { public int count(String query) { int result = 0; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); stmt = conn.createStatement(); rs = stmt.executeQuery(query); while (rs.next()) { result = rs.getInt("count"); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (stmt != null) { stmt.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } try { if (conn != null) { conn.close(); } } catch (Exception ex) { LOGGER.error(AssetConstants.ERROR_COUNT , ex); } } return result; }  int count(String query); List<Map<String, String>> executeQuery(String query); int[] batchUpdate(List<String> queries);  }