@Test public void getProducts() { productListModel = context.request().adaptTo(ProductListImpl.class); Collection<ProductListItem> products = productListModel.getProducts(); Assert.assertNotNull(products); Assert.assertEquals(4, products.size()); NumberFormat priceFormatter = NumberFormat.getCurrencyInstance(Locale.US); List<ProductListItem> results = products.stream().collect(Collectors.toList()); for (int i = 0; i < results.size(); i++) { ProductInterface productInterface = this.products.getItems().get(i); ProductListItem item = results.get(i); Assert.assertEquals(productInterface.getName(), item.getTitle()); Assert.assertEquals(productInterface.getSku(), item.getSKU()); Assert.assertEquals(productInterface.getUrlKey(), item.getSlug()); Assert.assertEquals(String.format(PRODUCT_PAGE + ".%s.html", productInterface.getUrlKey()), item.getURL()); Assert.assertEquals(productInterface.getPriceRange().getMinimumPrice().getFinalPrice().getValue(), item.getPrice(), 0); Assert.assertEquals(productInterface.getPriceRange().getMinimumPrice().getFinalPrice().getCurrency().toString(), item .getCurrency()); priceFormatter.setCurrency(Currency.getInstance(productInterface.getPriceRange().getMinimumPrice().getFinalPrice().getCurrency() .toString())); Assert.assertEquals(priceFormatter.format(productInterface.getPriceRange().getMinimumPrice().getFinalPrice().getValue()), item .getFormattedPrice()); ProductImage smallImage = productInterface.getSmallImage(); if (smallImage == null) { Assert.assertNull(item.getImageURL()); } else { Assert.assertEquals(smallImage.getUrl(), item.getImageURL()); } Assert.assertEquals(productInterface instanceof GroupedProduct, item.getPriceRange().isStartPrice()); } SearchResultsSet searchResultsSet = productListModel.getSearchResultsSet(); List<SearchAggregation> searchAggregations = searchResultsSet.getSearchAggregations(); Assert.assertEquals(7, searchAggregations.size()); SearchAggregation priceAggregation = searchAggregations.stream().filter(a -> a.getIdentifier().equals("price")).findFirst().get(); Assert.assertEquals(3, priceAggregation.getOptions().size()); Assert.assertEquals(3, priceAggregation.getOptionCount()); Assert.assertTrue(priceAggregation.getOptions().stream().anyMatch(o -> o.getDisplayLabel().equals("30-40"))); Assert.assertTrue(priceAggregation.getOptions().stream().anyMatch(o -> o.getDisplayLabel().equals("40-*"))); Assert.assertTrue(priceAggregation.getOptions().stream().anyMatch(o -> o.getDisplayLabel().equals("14"))); }
@Nonnull @Override public Collection<ProductListItem> getProducts() { if (usePlaceholderData) { CategoryProducts categoryProducts = getCategory().getProducts(); ProductToProductListItemConverter converter = new ProductToProductListItemConverter(productPage, request, urlProvider); return categoryProducts.getItems().stream() .map(converter) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { return getSearchResultsSet().getProductListItems(); } }
ProductListImpl extends ProductCollectionImpl implements ProductList { @Nonnull @Override public Collection<ProductListItem> getProducts() { if (usePlaceholderData) { CategoryProducts categoryProducts = getCategory().getProducts(); ProductToProductListItemConverter converter = new ProductToProductListItemConverter(productPage, request, urlProvider); return categoryProducts.getItems().stream() .map(converter) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { return getSearchResultsSet().getProductListItems(); } } }
ProductListImpl extends ProductCollectionImpl implements ProductList { @Nonnull @Override public Collection<ProductListItem> getProducts() { if (usePlaceholderData) { CategoryProducts categoryProducts = getCategory().getProducts(); ProductToProductListItemConverter converter = new ProductToProductListItemConverter(productPage, request, urlProvider); return categoryProducts.getItems().stream() .map(converter) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { return getSearchResultsSet().getProductListItems(); } }  }
ProductListImpl extends ProductCollectionImpl implements ProductList { @Nonnull @Override public Collection<ProductListItem> getProducts() { if (usePlaceholderData) { CategoryProducts categoryProducts = getCategory().getProducts(); ProductToProductListItemConverter converter = new ProductToProductListItemConverter(productPage, request, urlProvider); return categoryProducts.getItems().stream() .map(converter) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { return getSearchResultsSet().getProductListItems(); } }  @Nullable @Override String getTitle(); @Override boolean showTitle(); @Override String getImage(); @Override boolean showImage(); @Nonnull @Override Collection<ProductListItem> getProducts(); @Nonnull @Override SearchResultsSet getSearchResultsSet(); @Override AbstractCategoryRetriever getCategoryRetriever(); }
ProductListImpl extends ProductCollectionImpl implements ProductList { @Nonnull @Override public Collection<ProductListItem> getProducts() { if (usePlaceholderData) { CategoryProducts categoryProducts = getCategory().getProducts(); ProductToProductListItemConverter converter = new ProductToProductListItemConverter(productPage, request, urlProvider); return categoryProducts.getItems().stream() .map(converter) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { return getSearchResultsSet().getProductListItems(); } }  @Nullable @Override String getTitle(); @Override boolean showTitle(); @Override String getImage(); @Override boolean showImage(); @Nonnull @Override Collection<ProductListItem> getProducts(); @Nonnull @Override SearchResultsSet getSearchResultsSet(); @Override AbstractCategoryRetriever getCategoryRetriever();  }