PriceFilteredNavigationSupportImpl extends AbstractFilteredNavigationSupportImpl implements PriceFilteredNavigationSupport { List<FilteredNavigationRecord> getPriceNavigationRecords(final PriceTierTree priceTierTree, final String currency, final Shop customerShop) { final List<PriceTierNode> priceTierNodes = getPriceTierNodes(priceTierTree, currency, customerShop); final List<FilteredNavigationRecord> result = new ArrayList<>(priceTierNodes.size()); for (PriceTierNode priceTierNode : priceTierNodes) { result.add( new FilteredNavigationRecordImpl( ProductSearchQueryBuilder.PRODUCT_PRICE, ProductSearchQueryBuilder.PRODUCT_PRICE, priceNavigation.composePriceRequestParams( currency, priceTierNode.getFrom(), priceTierNode.getTo() ), 0 ) ); } return result; } PriceFilteredNavigationSupportImpl(final SearchQueryFactory searchQueryFactory,
                                              final ProductService productService,
                                              final CategoryService categoryService,
                                              final ShopService shopService,
                                              final PriceNavigation priceNavigation); @Override @Cacheable(value = "filteredNavigationSupport-priceFilteredNavigationRecords") List<FilteredNavigationRecord> getFilteredNavigationRecords(final NavigationContext navigationContext,
                                                                       final Long categoryId,
                                                                       final String currency,
                                                                       final String locale,
                                                                       final String recordName);  }
@Test public void testGetPriceNavigationRecords() { final PriceTierTree priceTierTree = this.context.mock(PriceTierTree.class, "priceTierTree"); final PriceTierNode priceTierNode1 = this.context.mock(PriceTierNode.class, "priceTierNode1"); final PriceTierNode priceTierNode2 = this.context.mock(PriceTierNode.class, "priceTierNode2"); final PriceTierNode priceTierNode3 = this.context.mock(PriceTierNode.class, "priceTierNode3"); final PriceNavigation priceNavigation = this.context.mock(PriceNavigation.class, "priceNavigation"); this.context.checking(new Expectations() {{ allowing(priceTierTree).getPriceTierNodes("EUR"); will(returnValue(Arrays.asList(priceTierNode1, priceTierNode2, priceTierNode3))); allowing(priceTierNode1).getFrom(); will(returnValue(new BigDecimal("0"))); allowing(priceTierNode1).getTo(); will(returnValue(new BigDecimal("100"))); allowing(priceNavigation).composePriceRequestParams("EUR", new BigDecimal("0"), new BigDecimal("100")); will(returnValue("EUR-_-0-_-100")); allowing(priceTierNode2).getFrom(); will(returnValue(new BigDecimal("100"))); allowing(priceTierNode2).getTo(); will(returnValue(new BigDecimal("300"))); allowing(priceNavigation).composePriceRequestParams("EUR", new BigDecimal("100"), new BigDecimal("300")); will(returnValue("EUR-_-100-_-300")); allowing(priceTierNode3).getFrom(); will(returnValue(new BigDecimal("300"))); allowing(priceTierNode3).getTo(); will(returnValue(new BigDecimal("500"))); allowing(priceNavigation).composePriceRequestParams("EUR", new BigDecimal("300"), new BigDecimal("500")); will(returnValue("EUR-_-300-_-500")); allowing(priceTierTree).getPriceTierNodes("UAH"); will(returnValue(Collections.emptyList())); }}); final PriceFilteredNavigationSupportImpl support = new PriceFilteredNavigationSupportImpl(null, null, null, null, priceNavigation); List<FilteredNavigationRecord> navigationRecords = support.getPriceNavigationRecords(priceTierTree, "EUR", null); assertNotNull(navigationRecords); assertEquals(3, navigationRecords.size()); assertEquals("EUR-_-0-_-100", navigationRecords.get(0).getValue()); assertEquals("EUR-_-100-_-300", navigationRecords.get(1).getValue()); assertEquals("EUR-_-300-_-500", navigationRecords.get(2).getValue()); navigationRecords = support.getPriceNavigationRecords(priceTierTree, "UAH", null); assertNotNull(navigationRecords); assertEquals(0, navigationRecords.size()); }