@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(); } };
@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(); } };
@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 testHardwareWithPrivateCore() { cpuItem = cpuItem.toBuilder() .description("Private 2 x 2.0 GHz Cores") .build(); Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem)); assertEquals("123,456,789", hardware.getId()); List<? extends Processor> processors = hardware.getProcessors(); assertEquals(1, processors.size()); assertEquals(2.0, processors.get(0).getCores()); assertEquals(2, hardware.getRam()); List<? extends Volume> volumes = hardware.getVolumes(); assertEquals(1, volumes.size()); assertEquals(100F, volumes.get(0).getSize()); }
@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)); }