### Question:
FieldFacetToQueryApplier { public void applyFieldFacet(SolrQuery query, String fieldName, String fieldValuePrefix) { Preconditions.checkNotNull(query); Preconditions.checkNotNull(fieldName); Preconditions.checkArgument(StringUtils.isNotBlank(fieldName)); String fieldParamPrefix = "f." + fieldName + "."; query.setFacet(true); query.add(fieldParamPrefix + FacetParams.FACET_SORT, FacetParams.FACET_SORT_INDEX); query.add(FacetParams.FACET_FIELD, fieldName); if (!StringUtils.isBlank(fieldValuePrefix)) { query.add(fieldParamPrefix + FacetParams.FACET_PREFIX, fieldValuePrefixAdder.prefixWithSeparator(fieldValuePrefix)); } }  void applyFieldFacet(SolrQuery query, String fieldName, String fieldValuePrefix); @Autowired void setFieldValuePrefixAdder(FieldValuePrefixAdder fieldValuePrefixAdder);  }### Answer:
@Test public void applyFieldFacet_FieldPrefixNotEmpty() { SolrQuery query = new SolrQuery(); when(fieldValuePrefixAdder.prefixWithSeparator("fieldPrefix")).thenReturn("fieldPrefix#"); fieldFacetToQueryApplier.applyFieldFacet(query, "fieldName", "fieldPrefix"); assertThat(query.getParams("facet"), arrayContaining("true")); assertThat(query.getParams("facet.field"), arrayContaining("fieldName")); assertThat(query.getParams("f.fieldName.facet.prefix"), arrayContaining("fieldPrefix#")); assertThat(query.getParams("f.fieldName.facet.sort"), arrayContaining(FacetParams.FACET_SORT_INDEX)); }
@Test public void applyFieldFacet_FieldPrefixBlank() { SolrQuery query = new SolrQuery(); fieldFacetToQueryApplier.applyFieldFacet(query, "fieldName", " "); assertThat(query.getParams("facet"), arrayContaining("true")); assertThat(query.getParams("facet.field"), arrayContaining("fieldName")); assertThat(query.getParams("f.fieldName.facet.sort"), arrayContaining(FacetParams.FACET_SORT_INDEX)); assertNull(query.getParams("f.fieldName.facet.prefix")); }