GroupByDBObjectBuilder extends DBObjectBuilder { public DBObject build() { return new BasicDBObject("$group", groupQuery); } GroupByDBObjectBuilder(GroupBy groupBy, Set<Selector> selectColumns); DBObject build();  }
@Test public void buildTest() throws Exception { Set<Selector> colSelected = new HashSet<Selector>(Arrays.asList(new ColumnSelector(new ColumnName(CATALOG, TABLE, SELECTED_FIELD)))); GroupBy groupBy = getGroupBy(GROUP_COLUMN); GroupByDBObjectBuilder groupByDBObjectBuilder = new GroupByDBObjectBuilder(groupBy, colSelected); DBObject fakeGroupBy = new BasicDBObject("fake", 5); Whitebox.setInternalState(groupByDBObjectBuilder, "groupQuery", fakeGroupBy); Whitebox.setInternalState(groupByDBObjectBuilder, "useAggregation", true); DBObject groupByCommand = groupByDBObjectBuilder.build(); assertTrue("The groupBy command should have a root $group", groupByCommand.keySet().contains("$group")); assertEquals("The value is not the expected", fakeGroupBy, groupByCommand.get("$group")); }