ProductItems { public static Function<ProductItemPrice, ProductItem> item() { return new Function<ProductItemPrice, ProductItem>() { @Override public ProductItem apply(ProductItemPrice productItemPrice) { Set<ProductItemCategory> categories = productItemPrice.getCategories(); ProductItem item = productItemPrice.getItem(); ProductItem.Builder builder = productItemPrice.getItem().toBuilder(); if (item.getCategories().size() == 0 && categories.size() != 0) { builder.categories(categories); } return builder.build(); } }; }  static Function<ProductItem, Float> capacity(); static Function<ProductItem, String> description(); static Function<ProductItem, ProductItemPrice> price(); static Function<ProductItemPrice, ProductItem> item();  }
@Test public void testItemCallGetsCategory() { ProductItemPrice price = ProductItemPrice.builder().id(1) .categories(category) .item(item) .build(); ProductItem newItem = item().apply(price); assertEquals(newItem.getCategories(), ImmutableSet.of(category)); }
@Test public void testItemCallNoCategoryOnPrice() { ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category)).build(); ProductItemPrice price = ProductItemPrice.builder().id(1) .item(item1) .build(); ProductItem newItem = item().apply(price); assertEquals(newItem.getCategories(), ImmutableSet.of(category)); }
@Test public void testItemCallCategoryExists() { ProductItemCategory category2 = ProductItemCategory.builder() .id(12) .categoryCode("new category") .build(); ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category2)).build(); ProductItemPrice price = ProductItemPrice.builder().id(1) .categories(category) .item(item1) .build(); ProductItem newItem = item().apply(price); assertEquals(newItem.getCategories(), ImmutableSet.of(category2)); }