### Question:
GroupByStage implements TranslationStage { @Override public void perform(TranslatorContext context) { if (!hasAggregate(context)) { return; } for(ResultNodeDescriptor resultNode : context.getResultNodeList()) { if(resultNode.isAggregate()) { continue; } context.getSelectBuilder().groupBy(resultNode.getNode().deepCopy()); } }  @Override void perform(TranslatorContext context);  }### Answer:
@Test public void emptyContext() { GroupByStage stage = new GroupByStage(); stage.perform(context); Node node = context.getSelectBuilder().build(); assertEquals(0, node.getChildrenCount()); }
@Test public void noAggregates() { context.addResultNode(new ColumnNode("t0", "column", null, null)); GroupByStage stage = new GroupByStage(); stage.perform(context); Node node = context.getSelectBuilder().build(); assertEquals(0, node.getChildrenCount()); }
@Test public void groupByWithAggregates() { context.addResultNode(new ColumnNode("t0", "column", null, null)); context.addResultNode(new EmptyNode(), true, PropertyFactory.COUNT, "count"); GroupByStage stage = new GroupByStage(); stage.perform(context); Node node = context.getSelectBuilder().build(); assertEquals(1, node.getChildrenCount()); assertThat(node.getChild(0), instanceOf(GroupByNode.class)); assertEquals(1, node.getChild(0).getChildrenCount()); assertThat(node.getChild(0).getChild(0), instanceOf(ColumnNode.class)); ColumnNode columnNode = (ColumnNode)node.getChild(0).getChild(0); assertEquals("t0", columnNode.getTable()); assertEquals("column", columnNode.getColumn()); }