GroupBy { public void toSql(final StringBuilder builder) { builder.append(" GROUP BY "); for (final Pair<Func, Attribute> groupBy : _groupBys) { if (groupBy.first() != null) { String func = groupBy.first().toString(); func = func.replaceFirst("@", groupBy.second().table + "." + groupBy.second().columnName); builder.append(func); } else { builder.append(groupBy.second().table + "." + groupBy.second().columnName); } builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); if (_having != null) { _having.toSql(builder); } } GroupBy(final J builder); GroupBy<J, T, R> group(final Object useless); GroupBy<J, T, R> group(final Func func, final Object useless); J having(final Func func, final Object obj, final Op op, final Object value); void toSql(final StringBuilder builder);  }
@Test public void testToSql() { final StringBuilder sb = new StringBuilder("BASE"); final GroupByExtension groupBy = new GroupByExtension(new SearchBaseExtension(String.class, String.class)); final Attribute att = new Attribute("TEST_TABLE", "TEST_COLUMN"); final Pair<Func, Attribute> pair1 = new Pair<SearchCriteria.Func, Attribute>(SearchCriteria.Func.FIRST, att); final Pair<Func, Attribute> pair2 = new Pair<SearchCriteria.Func, Attribute>(SearchCriteria.Func.MAX, att); groupBy._groupBys = new ArrayList<Pair<Func, Attribute>>(); groupBy._groupBys.add(pair1); groupBy._groupBys.add(pair2); groupBy.having(SearchCriteria.Func.COUNT, att, Op.GT, "SOME_VALUE"); groupBy.toSql(sb); assertTrue("It didn't create the expected SQL query.", sb.toString().equals(EXPECTED_QUERY)); }