### Question:
QueryUtil { public static JSONObject extractAggregationValue(SearchResponse response) { JSONObject jsonResp = new JSONObject(); List<String> name = new ArrayList<>(Arrays.asList("aggregations", "sum#sum", "scripted_metric#agg")); try { jsonResp = new JSONObject(response.toString()); Iterator keysIterator = jsonResp.keys(); jsonResp = getJsonObject(jsonResp, name, keysIterator); } catch (JSONException e) { LOGGER.error(e.getMessage()); } return jsonResp; } private  QueryUtil(); static JSONObject extractAggregationValue(SearchResponse response); static ArrayList toList(JSONArray array); static Map<String, Object> toMap(JSONObject object); static JSONObject extractAggregationStr(String response);  }### Answer:
@Test public void extractAggregationValue() { int docId = 0, docId1 = 1, docId2 = 2, docId3 = 3, docId4 = 400, docId5 = 5000; SearchHit[] hit = new SearchHit[6]; hit[0] = new SearchHit(docId); hit[1] = new SearchHit(docId1); hit[2] = new SearchHit(docId2); hit[3] = new SearchHit(docId3); hit[4] = new SearchHit(docId4); hit[5] = new SearchHit(docId5); SearchHits hits = new SearchHits(hit, 30000, 450); Aggregations aggregations = new Aggregations(new ArrayList()); List<Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>>> suggestions = new ArrayList(); suggestions.add(new Suggest.Suggestion("sug1", 1)); suggestions.add(new Suggest.Suggestion("sug2", 2)); suggestions.add(new Suggest.Suggestion("sug3", 3)); suggestions.add(new Suggest.Suggestion("sug4", 4)); suggestions.add(new Suggest.Suggestion("sug5", 50)); Suggest suggest = new Suggest(suggestions); SearchProfileShardResults profileResults = new SearchProfileShardResults(Collections.emptyMap()); SearchResponseSections internalResponse = new SearchResponseSections(hits, aggregations, suggest, false, false, profileResults, 0); ShardSearchFailure[] shardFailures = new ShardSearchFailure[0]; SearchResponse.Clusters clusters = SearchResponse.Clusters.EMPTY; SearchResponse sRes = new SearchResponse(internalResponse, "id1", 1, 1, 1, 1, shardFailures, clusters); JSONObject res = QueryUtil.extractAggregationValue(sRes); assertNotNull(res.get("suggest")); assertNotNull(res.get("hits")); }