TransformStreams { public Map<Product, Long> p06_getProductCount(Customer customer) { return customer.getOrders().stream() .flatMap(order -> order.getOrderLines().stream()) .collect(groupingBy(OrderLine::getProduct, summingLong(OrderLine::getCount))); }  List<OrderDto> p01_toDtos(List<Order> orders); Set<PaymentMethod> p02_getUsedPaymentMethods(Customer customer); SortedSet<LocalDate> p03_getOrderDatesAscending(Customer customer); Map<Long, Order> p04_mapOrdersById(Customer customer); Map<PaymentMethod, List<Order>> p05_getProductsByPaymentMethod(Customer customer); Map<Product, Long> p06_getProductCount(Customer customer); List<Product> p07_getAllOrderedProducts(Customer customer); String p08_getProductsJoined(Customer customer); Long p09_getApproximateTotalOrdersPrice(Customer customer); List<OrderLine> p10_readOrderFromFile(File file);  }
@Test public void p06_getProductCount() { Product chair = new Product("Chair"); Product table = new Product("Table"); Order order1 = new Order( new OrderLine(chair, 3)); Order order2 = new Order( new OrderLine(table, 1), new OrderLine(chair, 1)); Map<Product, Long> actual = service.p06_getProductCount(new Customer(order1, order2)); Map<Product, Long> expected = new HashMap<Product, Long>(){{ put(chair, 4L); put(table, 1L); }}; assertEquals(expected, actual); }