### Question:
FreeformQuery extends AbstractTransactionalQuery implements
        QueryDelegate { @Override public int getCount() throws SQLException { int count = countByDelegate(); if (count < 0) { Statement statement = null; ResultSet rs = null; Connection conn = getConnection(); try { statement = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = statement.executeQuery(queryString); if (rs.last()) { count = rs.getRow(); } else { count = 0; } } finally { releaseConnection(conn, statement, rs); } } return count; } @SuppressWarnings("unused") private  FreeformQuery(); @Deprecated  FreeformQuery(String queryString, List<String> primaryKeyColumns,
            JDBCConnectionPool connectionPool);  FreeformQuery(String queryString, JDBCConnectionPool connectionPool,
            String... primaryKeyColumns); @Override int getCount(); @Override @SuppressWarnings({ "deprecation", "finally" }) ResultSet getResults(int offset, int pagelength); @Override @SuppressWarnings("deprecation") boolean implementationRespectsPagingLimits(); @Override void setFilters(List<Filter> filters); @Override void setOrderBy(List<OrderBy> orderBys); @Override int storeRow(RowItem row); @Override boolean removeRow(RowItem row); @Override synchronized void beginTransaction(); @Override synchronized void commit(); @Override synchronized void rollback(); @Override List<String> getPrimaryKeyColumns(); String getQueryString(); FreeformQueryDelegate getDelegate(); void setDelegate(FreeformQueryDelegate delegate); @Override @SuppressWarnings("deprecation") boolean containsRowWithKey(Object... keys);  }### Answer:
@Test public void getCount_simpleQuery_returnsFour() throws SQLException { FreeformQuery query = new FreeformQuery("SELECT * FROM people", Arrays.asList("ID"), connectionPool); Assert.assertEquals(4, query.getCount()); }
@Test public void getCount_moreComplexQuery_returnsThree() throws SQLException { FreeformQuery query = new FreeformQuery( "SELECT * FROM people WHERE \"NAME\" LIKE '%lle'", connectionPool, new String[] { "ID" }); Assert.assertEquals(3, query.getCount()); }
@Test public void getCount_normalState_releasesConnection() throws SQLException { FreeformQuery query = new FreeformQuery( "SELECT * FROM people WHERE \"NAME\" LIKE '%lle'", connectionPool, "ID"); query.getCount(); query.getCount(); Connection c = connectionPool.reserveConnection(); Assert.assertNotNull(c); connectionPool.releaseConnection(c); }