ProductItemsToHardware implements Function<Iterable<ProductItem>, Hardware> { public static Function<List<ProductItem>, String> hardwareId() { return new Function<List<ProductItem>, String>() { @Override public String apply(List<ProductItem> productItems) { StringBuilder builder = new StringBuilder(); for (ProductItem item : productItems) { ProductItemPrice price = ProductItems.price().apply(item); builder.append(price.getId()).append(","); } return builder.toString().substring(0, builder.lastIndexOf(",")); } }; } @Inject  ProductItemsToHardware();  ProductItemsToHardware(Pattern cpuDescriptionRegex, Pattern diskCategoryRegex); @Override Hardware apply(Iterable<ProductItem> items); static Function<List<ProductItem>, String> hardwareId();  }
@Test public void testHardwareId() { ProductItem item1 = ProductItem.builder().prices(ProductItemPrice.builder().id(123).build()).build(); ProductItem item2 = ProductItem.builder().prices(ProductItemPrice.builder().id(456).build()).build(); ProductItem item3 = ProductItem.builder().prices(ProductItemPrice.builder().id(789).build()).build(); String id = hardwareId().apply(ImmutableList.of(item1, item2, item3)); assertEquals("123,456,789", id); }