### Question:
XFieldFacetExtractor { public List<FacetCount> extractFacetCounts(QueryResponse response, XField xField) { Preconditions.checkNotNull(response); Preconditions.checkNotNull(xField); String fieldName = xFieldNameMapper.mapXField(xField); RangeFacet<?, ?> facetRange = extractRangeFacet(response, fieldName); FacetField facetField = extractFieldFacet(response, fieldName); if (facetRange != null) { return convertRangeFacetCounts(facetRange); } if (facetField != null) { return convertFieldFacetCounts(facetField); } throw new RuntimeException("No field or range facet for field name " + fieldName + " in solr query response"); }  List<FacetCount> extractFacetCounts(QueryResponse response, XField xField); @Resource void setxFieldNameMapper(XFieldNameMapper xFieldNameMapper);  }### Answer:
@Test public void extractFacetCounts_RANGE_FACET() { Map<String, Integer> facetResultsCount = Maps.newHashMap(); facetResultsCount.put("key1", 1); facetResultsCount.put("key2", 5); QueryResponse response = createQueryResponseWithRangeFacet("judgmentDate", facetResultsCount); List<FacetCount> facetCounts = xFieldFacetExtractor.extractFacetCounts(response, XField.JUDGMENT_DATE); assertEquals(2, facetCounts.size()); assertEquals("key1", facetCounts.get(0).getValue()); assertEquals(1, facetCounts.get(0).getCount()); assertEquals("key2", facetCounts.get(1).getValue()); assertEquals(5, facetCounts.get(1).getCount()); }
@Test public void extractFacetCounts_FIELD_FACET() { Map<String, Integer> facetResultsCount = Maps.newHashMap(); facetResultsCount.put("key1", 1); facetResultsCount.put("key2", 5); QueryResponse response = createQueryResponseWithFieldFacet("judgmentDate", facetResultsCount); List<FacetCount> facetCounts = xFieldFacetExtractor.extractFacetCounts(response, XField.JUDGMENT_DATE); assertEquals(2, facetCounts.size()); assertEquals("key1", facetCounts.get(0).getValue()); assertEquals(1, facetCounts.get(0).getCount()); assertEquals("key2", facetCounts.get(1).getValue()); assertEquals(5, facetCounts.get(1).getCount()); }
@Test(expected = RuntimeException.class) public void extractFacetCounts_NO_FACET() { xFieldFacetExtractor.extractFacetCounts(new QueryResponse(), XField.JUDGMENT_DATE); }
@Test(expected = NullPointerException.class) public void extractFacet_NULL_RESPONSE() { xFieldFacetExtractor.extractFacetCounts(null, XField.JUDGMENT_DATE); }
@Test(expected = NullPointerException.class) public void extractFacet_NULL_XFIELD() { xFieldFacetExtractor.extractFacetCounts(new QueryResponse(), null); }