DefaultDatabase implements Database { @Override public int countSql(String sql) { LOG.info("Count sql"); Connection connection = openConnection(); Statement statement = null; ResultSet rs = null; try { statement = connection.createStatement(); LOG.debug("Execute: {}", sql); rs = statement.executeQuery(sql); rs.next(); return rs.getInt(1); } catch (SQLException e) { throw new IllegalStateException("Fail to execute SQL: " + sql, e); } finally { closeQuietly(rs); closeQuietly(statement); closeQuietly(connection); } } DefaultDatabase(Configuration config);  DefaultDatabase(DatabaseClient client); void start(); void stop(); @Override Map<String, String> getSonarProperties(); @Override DatabaseClient getClient(); @Override Database truncate(String tableName); @Override int countSql(String sql); @Override List<Map<String, String>> executeSql(String sql); @Override Connection openConnection(); @Override DefaultDatabase closeQuietly(@Nullable Connection connection); @Override void killOtherConnections();  }
@Test public void countSql() { assertThat(db.countSql("select count(kee) from metrics")).isEqualTo(2); }
@Test public void countSql_fail_if_bad_sql() { thrown.expect(RuntimeException.class); db.countSql("this is not sql"); }