### Question:
FreeformQuery extends AbstractTransactionalQuery implements
        QueryDelegate { @Override @SuppressWarnings("deprecation") public boolean containsRowWithKey(Object... keys) throws SQLException { String query = null; boolean contains = false; if (delegate != null) { if (delegate instanceof FreeformStatementDelegate) { try { StatementHelper sh = ((FreeformStatementDelegate) delegate) .getContainsRowQueryStatement(keys); PreparedStatement pstmt = null; ResultSet rs = null; Connection c = getConnection(); try { pstmt = c.prepareStatement(sh.getQueryString()); sh.setParameterValuesToStatement(pstmt); rs = pstmt.executeQuery(); contains = rs.next(); return contains; } finally { releaseConnection(c, pstmt, rs); } } catch (UnsupportedOperationException e) { } } try { query = delegate.getContainsRowQueryString(keys); } catch (UnsupportedOperationException e) { query = modifyWhereClause(keys); } } else { query = modifyWhereClause(keys); } Statement statement = null; ResultSet rs = null; Connection conn = getConnection(); try { statement = conn.createStatement(); rs = statement.executeQuery(query); contains = rs.next(); } finally { releaseConnection(conn, statement, rs); } return contains; } @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 containsRowWithKeys_simpleQueryWithExistingKeys_returnsTrue() throws SQLException { FreeformQuery query = new FreeformQuery("SELECT * FROM people", Arrays.asList("ID"), connectionPool); Assert.assertTrue(query.containsRowWithKey(1)); }
@Test public void containsRowWithKeys_simpleQueryWithNonexistingKeys_returnsTrue() throws SQLException { FreeformQuery query = new FreeformQuery("SELECT * FROM people", Arrays.asList("ID"), connectionPool); Assert.assertFalse(query.containsRowWithKey(1337)); }
@Test public void containsRowWithKeys_simpleQueryWithInvalidKeys_shouldFail() throws SQLException { FreeformQuery query = new FreeformQuery("SELECT * FROM people", Arrays.asList("ID"), connectionPool); Assert.assertFalse(query.containsRowWithKey(38796)); }
@Test public void containsRowWithKeys_queryContainingWhereClauseAndExistingKeys_returnsTrue() throws SQLException { FreeformQuery query = new FreeformQuery( "SELECT * FROM people WHERE \"NAME\" LIKE '%lle'", Arrays.asList("ID"), connectionPool); Assert.assertTrue(query.containsRowWithKey(1)); }
@Test public void containsRowWithKeys_queryContainingLowercaseWhereClauseAndExistingKeys_returnsTrue() throws SQLException { FreeformQuery query = new FreeformQuery( "select * from people where \"NAME\" like '%lle'", Arrays.asList("ID"), connectionPool); Assert.assertTrue(query.containsRowWithKey(1)); }
@Test public void containsRowWithKeys_nullKeys_shouldFailAndReleaseConnections() throws SQLException { FreeformQuery query = new FreeformQuery( "select * from people where \"NAME\" like '%lle'", Arrays.asList("ID"), connectionPool); try { query.containsRowWithKey(new Object[] { null }); } catch (SQLException e) { connectionPool.reserveConnection(); connectionPool.reserveConnection(); } }