@Test
public void testParseBuckets() {

    for (String input : Arrays.asList("{" + afterKey + ", " + bucketsArr + "}", "{" + bucketsArr + "}")) {
        JsonObject compositeAggregationJson = gson.fromJson(
                input.replace('\'', '\"'), JsonObject.class);
        CompositeAggregation compositeAggregation = new CompositeAggregation("composite", compositeAggregationJson);
        List<CompositeAggregation.Entry> buckets = compositeAggregation.getBuckets();
        assertNotNull(buckets);
        assertEquals(2, buckets.size());
        assertEquals("val", buckets.get(0).getKey().get("field").getAsString());
        assertEquals(Long.valueOf(1L), buckets.get(0).getCount());
        assertTrue(buckets.get(0).getTermsAggregation("sub_agg").getBuckets().isEmpty());
        assertEquals("valA", buckets.get(1).getKey().get("field").getAsString());
        assertEquals(Long.valueOf(2L), buckets.get(1).getCount());
        assertTrue(buckets.get(1).getTermsAggregation("sub_agg").getBuckets().isEmpty());
    }
}