BaselineAnalyticsFacetsReader { public static JsonObject generateFacetsTreeJson(List<Map<String, Object>> results) { TreeMultimap<String, FacetTreeItem> facetTreeMultimap = TreeMultimap.create(new HomoSapiensFirstComparator(), new OrganismPartFirstComparator()); for (Map<String, Object> experiment : results) { String species = (String) experiment.get("val"); @SuppressWarnings("unchecked") Map<String, Object> factorRoot = (Map<String, Object>) experiment.get("defaultQueryFactorType"); @SuppressWarnings("unchecked") List<Map<String, Object>> buckets = (List<Map<String, Object>>) factorRoot.get("buckets"); for (Map<String, Object> defaultQueryFactorType : buckets) { String key = (String) defaultQueryFactorType.get("val"); String name = Factor.convertToLowerCase(key); FacetTreeItem factor = FacetTreeItem.create(key, name); facetTreeMultimap.put(species, factor); } } return GSON.toJsonTree(facetTreeMultimap.asMap()).getAsJsonObject(); } protected  BaselineAnalyticsFacetsReader(); static JsonObject generateFacetsTreeJson(List<Map<String, Object>> results);  }
@Test public void extractTreeFacets() { List<Map<String, Object>> parsedJsonResponse = JsonPath.read(JSON_RESPONSE, BaselineAnalyticsSearchDao.FACET_TREE_PATH); JsonObject facetsTreeJson = BaselineAnalyticsFacetsReader.generateFacetsTreeJson(parsedJsonResponse); assertThat(facetsTreeJson, is(JSON_RESPONSE_FACETS)); }