### Question:
PaymentServiceImpl implements PaymentService { @HystrixCommand(fallbackMethod = "processPaymentFallback") @Override public void processPayment(Payment payment) { System.out.println("ProcessPayment called()"); payment = paymentRepository.save(payment); String orderCompleteUpdater = "http: String orderId = payment.getOrderId(); if (orderId == null) { sendErrorMessage("Missing orderId in payment"); return; } Order order = orderRepository.findOrderById(orderId); if (order != null && validateCreditCardInfo(payment.getCreditCardInfo())) { if (order.getTotalPrice() != payment.getAmount()) { String errorMessage = "Payment amount: " + payment.getAmount() + " doesn't match with order price: " + order.getTotalPrice() + ", orderId = " + orderId; sendErrorMessage(errorMessage); return; } else { order.setPaymentId(payment.getId()); long deliveryTime = getDeliveryTime(); order.setDeliveryTime(deliveryTime); orderRepository.save(order); restTemplate.postForLocation(orderCompleteUpdater + "/api/orders", order); } } else { String errorMessage = order == null ? "Failed to retrieve order for orderId: " + orderId : "Invalid credit card information for orderId: " + orderId; sendErrorMessage(errorMessage); } } @Autowired  PaymentServiceImpl(RestTemplate restTemplate, OrderRepository orderRepository, PaymentRepository paymentRepository); @HystrixCommand(fallbackMethod = "processPaymentFallback") @Override void processPayment(Payment payment); void processPaymentFallback(Payment payment);  }### Answer:
@Test public void processPaymentSuccess() { when(paymentRepository.save(payment)).thenReturn(payment); when(orderRepository.findOrderById(ORDER_ID)).thenReturn(order); paymentService.processPayment(payment); verify(restTemplate).postForLocation(ORDER_COMPLETE_UPDATER + "/api/orders", order); }
@Test public void processPaymentFail_whenAmountMisMatch() { when(paymentRepository.save(payment)).thenReturn(payment); when(orderRepository.findOrderById(ORDER_ID)).thenReturn(order); payment.setAmount(ORDER_TOTAL_PRICE + 10); paymentService.processPayment(payment); verify(restTemplate).postForLocation(ORDER_COMPLETE_UPDATER + "/api/errors", "Payment amount: " + payment.getAmount() + " doesn't match with order price: " + ORDER_TOTAL_PRICE + ", orderId = " + ORDER_ID); }
@Test public void processPaymentFail_whenOrderNotFound() { when(paymentRepository.save(payment)).thenReturn(payment); when(orderRepository.findOrderById(ORDER_ID)).thenReturn(null); paymentService.processPayment(payment); verify(restTemplate).postForLocation(ORDER_COMPLETE_UPDATER + "/api/errors", "Failed to retrieve order for orderId: " + ORDER_ID); }