@Test
public void groupByDBObjectBuilderTest() throws MongoValidationException, ExecutionException {

    // GroupBy with one column
    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);
    assertTrue("useAggregations should be true",
                    (Boolean) Whitebox.getInternalState(groupByDBObjectBuilder, "useAggregation"));
    DBObject aggregationOperation = new BasicDBObject("$first", "$" + SELECTED_FIELD);
    DBObject internalProjectDBObject = (DBObject) Whitebox.getInternalState(groupByDBObjectBuilder, "groupQuery");
    Assert.assertEquals("The groupby command is not the expected", "$" + GROUP_COLUMN,
                    internalProjectDBObject.get("_id"));
    Assert.assertEquals("The groupby operand is not the expected", aggregationOperation,
                    internalProjectDBObject.get(SELECTED_FIELD));
    // GroupBy with several columns
    groupBy = getGroupBy(GROUP_COLUMN, GROUP_COLUMN_SECONDARY);
    groupByDBObjectBuilder = new GroupByDBObjectBuilder(groupBy, colSelected);
    groupByDBObjectBuilder = new GroupByDBObjectBuilder(groupBy, colSelected);
    assertTrue("useAggregations should be true",
                    (Boolean) Whitebox.getInternalState(groupByDBObjectBuilder, "useAggregation"));
    aggregationOperation = new BasicDBObject("$first", "$" + SELECTED_FIELD);
    DBObject groupColumnsFields = new BasicDBObject(GROUP_COLUMN, "$" + GROUP_COLUMN);
    groupColumnsFields.put(GROUP_COLUMN_SECONDARY, "$" + GROUP_COLUMN_SECONDARY);
    internalProjectDBObject = (DBObject) Whitebox.getInternalState(groupByDBObjectBuilder, "groupQuery");
    Assert.assertEquals("The groupby command is not the expected", groupColumnsFields,
                    internalProjectDBObject.get("_id"));
    Assert.assertEquals("The groupby operand is not the expected", aggregationOperation,
                    internalProjectDBObject.get(SELECTED_FIELD));
}