### Question:
PoolerRows { @BadSmell("This first if is really weird") public Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths) { if (rows.isEmpty() && paths.size() > 0 && paths.get(0).get(0).equals("fake_aggregation_for_group_all_rows")) { return Arrays.asList(new QueryResultRow("", null)); } Map<String, QueryResultRow> map = new HashMap<String, QueryResultRow>(); for (QueryResultRow row : rows) { String key = toKey(row, paths); QueryResultRow groupedRow = map.get(key); if (groupedRow == null) { groupedRow = row; map.put(key, groupedRow); } groupedRow.addGroupedRow(row); } return map.values(); }  @BadSmell("This first if is really weird") Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths);  }### Answer:
@Test public void testAggregateOneColumn() { List<QueryResultRow> rows; Collection<QueryResultRow> aggregatedRows; List<List<String>> paths = new ArrayList<List<String>>(); paths.add(Arrays.asList("a", "stringValue")); rows = new ArrayList<QueryResultRow>(); rows.add(new QueryResultRow("a", new A("a1"))); rows.add(new QueryResultRow("a", new A("a1"))); aggregatedRows = new PoolerRows().group(rows, paths); assertEquals(1, aggregatedRows.size()); assertEquals(2, aggregatedRows.iterator().next().getGroupedRows().size()); rows = new ArrayList<QueryResultRow>(); rows.add(new QueryResultRow("a", new A("a1"))); rows.add(new QueryResultRow("a", new A("a1"))); rows.add(new QueryResultRow("a", new A("a2"))); aggregatedRows = new PoolerRows().group(rows, paths); assertEquals(2, aggregatedRows.size()); }
@Test public void testAggregateMoreThanOneColumn() { List<QueryResultRow> rows; List<List<String>> paths = new ArrayList<List<String>>(); Collection<QueryResultRow> aggregatedRows; rows = new ArrayList<QueryResultRow>(); rows.add(new QueryResultRow("a", new A("a1", 1))); rows.add(new QueryResultRow("a", new A("a1", 1))); rows.add(new QueryResultRow("a", new A("a1", 2))); rows.add(new QueryResultRow("a", new A("a2", 1))); paths.add(Arrays.asList("a", "stringValue")); paths.add(Arrays.asList("a", "intValue")); aggregatedRows = new PoolerRows().group(rows, paths); assertEquals(3, aggregatedRows.size()); }