### Question:
AggregationOptionToSearchAggregationOptionConverter implements Function<AggregationOption, SearchAggregationOption> { @Override public SearchAggregationOption apply(final AggregationOption aggregationOption) { SearchAggregationOptionImpl searchAggregationOption = new SearchAggregationOptionImpl(); if (filterAttributeMetadata != null && FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN.equals(filterAttributeMetadata .getAttributeInputType())) { searchAggregationOption.setDisplayLabel(("0".equalsIgnoreCase(aggregationOption.getLabel()) ? "No" : "Yes")); } else { searchAggregationOption.setDisplayLabel(aggregationOption.getLabel()); } searchAggregationOption.setCount(aggregationOption.getCount()); searchAggregationOption.setFilterValue(aggregationOption.getValue()); Map<String, String> newFilters = new HashMap<>(filters); newFilters.put(attributeCode, aggregationOption.getValue()); searchAggregationOption.setAddFilterMap(newFilters.entrySet().stream() .filter(item -> !item.getKey().equals("page")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); return searchAggregationOption; } AggregationOptionToSearchAggregationOptionConverter(final String attributeCode,
                                                               final FilterAttributeMetadata filterAttributeMetadata,
                                                               final Map<String, String> filters); @Override SearchAggregationOption apply(final AggregationOption aggregationOption);  }### Answer:
@Test public void testShouldSetCount() { FilterAttributeMetadataImpl filterAttributeMetadata = new FilterAttributeMetadataImpl(); filterAttributeMetadata.setAttributeInputType(FilterAttributeMetadataImpl.INPUT_TYPE_SELECT); filterAttributeMetadata.setAttributeCode(BLACK_ATTRIBUTE); converterUnderTest = new AggregationOptionToSearchAggregationOptionConverter(BLACK_ATTRIBUTE, filterAttributeMetadata, existingFilters); final SearchAggregationOption resultOption = converterUnderTest.apply(aggregationOption); assertThat(resultOption.getCount()).isEqualTo(BLACK_COUNT); }
@Test public void testShouldSetDisplayLabel() { FilterAttributeMetadataImpl filterAttributeMetadata = new FilterAttributeMetadataImpl(); filterAttributeMetadata.setAttributeInputType(FilterAttributeMetadataImpl.INPUT_TYPE_SELECT); filterAttributeMetadata.setAttributeCode(BLACK_ATTRIBUTE); converterUnderTest = new AggregationOptionToSearchAggregationOptionConverter(BLACK_ATTRIBUTE, filterAttributeMetadata, existingFilters); final SearchAggregationOption resultOption = converterUnderTest.apply(aggregationOption); assertThat(resultOption.getDisplayLabel()).isEqualTo(BLACK_LABEL); }
@Test public void testShouldSetDisplayLabelForBooleanValues() { FilterAttributeMetadataImpl filterAttributeMetadata = new FilterAttributeMetadataImpl(); filterAttributeMetadata.setAttributeInputType(FilterAttributeMetadataImpl.INPUT_TYPE_BOOLEAN); filterAttributeMetadata.setAttributeCode("blah"); converterUnderTest = new AggregationOptionToSearchAggregationOptionConverter(BLACK_ATTRIBUTE, filterAttributeMetadata, existingFilters); when(aggregationOption.getLabel()).thenReturn("0"); final SearchAggregationOption resultOption = converterUnderTest.apply(aggregationOption); assertThat(resultOption.getDisplayLabel()).isEqualTo("No"); }
@Test public void testShouldSetFilterValue() { FilterAttributeMetadataImpl filterAttributeMetadata = new FilterAttributeMetadataImpl(); filterAttributeMetadata.setAttributeInputType(FilterAttributeMetadataImpl.INPUT_TYPE_SELECT); filterAttributeMetadata.setAttributeCode(BLACK_ATTRIBUTE); converterUnderTest = new AggregationOptionToSearchAggregationOptionConverter(BLACK_ATTRIBUTE, filterAttributeMetadata, existingFilters); final SearchAggregationOption resultOption = converterUnderTest.apply(aggregationOption); assertThat(resultOption.getFilterValue()).isEqualTo(BLACK_VALUE); }