@Test @Parameters({"margaux, 1", "marGauX, 1", "Pauillac, 1", "PESSAC, 1", "beer, 0"}) public void shouldAllowBuyingForValidProductType(String productType, int callCount) { Map<String, String> payload = new HashMap() {{ put("type", productType); }}; when(ordersRepository.getAllProcessedOrders()).thenReturn( new HashMap() {{ put(productType, 1L); }} ); shopService.processBuyOrder(payload); verify(ordersRepository, times(callCount)).incrementProcessedOrdersForProduct(productType); verify(rabbitTemplate, times(callCount)).convertAndSend(mapArgumentCaptor.capture()); if (callCount > 0) { assertThat(mapArgumentCaptor.getValue().get("payload").get("items").get(productType)).isEqualTo(callCount); } }
public void processBuyOrder(Map<String, String> payload) { String productType = ofNullable(payload.get("type")).orElse("").toLowerCase(); if (validType.contains(productType)) { ordersRepository.incrementProcessedOrdersForProduct(payload.get("type")); rabbitTemplate.convertAndSend(new HashMap<String, Object>() {{ put("type", "SHOP_STATE"); put("payload", new HashMap<String, Object>() {{ put("items", ordersRepository.getAllProcessedOrders()); }}); }}); } }
ShopService { public void processBuyOrder(Map<String, String> payload) { String productType = ofNullable(payload.get("type")).orElse("").toLowerCase(); if (validType.contains(productType)) { ordersRepository.incrementProcessedOrdersForProduct(payload.get("type")); rabbitTemplate.convertAndSend(new HashMap<String, Object>() {{ put("type", "SHOP_STATE"); put("payload", new HashMap<String, Object>() {{ put("items", ordersRepository.getAllProcessedOrders()); }}); }}); } } }
ShopService { public void processBuyOrder(Map<String, String> payload) { String productType = ofNullable(payload.get("type")).orElse("").toLowerCase(); if (validType.contains(productType)) { ordersRepository.incrementProcessedOrdersForProduct(payload.get("type")); rabbitTemplate.convertAndSend(new HashMap<String, Object>() {{ put("type", "SHOP_STATE"); put("payload", new HashMap<String, Object>() {{ put("items", ordersRepository.getAllProcessedOrders()); }}); }}); } }  }
ShopService { public void processBuyOrder(Map<String, String> payload) { String productType = ofNullable(payload.get("type")).orElse("").toLowerCase(); if (validType.contains(productType)) { ordersRepository.incrementProcessedOrdersForProduct(payload.get("type")); rabbitTemplate.convertAndSend(new HashMap<String, Object>() {{ put("type", "SHOP_STATE"); put("payload", new HashMap<String, Object>() {{ put("items", ordersRepository.getAllProcessedOrders()); }}); }}); } }  void processBuyOrder(Map<String, String> payload); Optional<Boolean> isShopOpen(); void openShop(); void closeShop(); }
ShopService { public void processBuyOrder(Map<String, String> payload) { String productType = ofNullable(payload.get("type")).orElse("").toLowerCase(); if (validType.contains(productType)) { ordersRepository.incrementProcessedOrdersForProduct(payload.get("type")); rabbitTemplate.convertAndSend(new HashMap<String, Object>() {{ put("type", "SHOP_STATE"); put("payload", new HashMap<String, Object>() {{ put("items", ordersRepository.getAllProcessedOrders()); }}); }}); } }  void processBuyOrder(Map<String, String> payload); Optional<Boolean> isShopOpen(); void openShop(); void closeShop();  }