### Question:
PaymentServiceImpl implements PaymentService { @Override public Response pay(Payment info, HttpHeaders headers){ if(paymentRepository.findByOrderId(info.getOrderId()) == null){ Payment payment = new Payment(); payment.setOrderId(info.getOrderId()); payment.setPrice(info.getPrice()); payment.setUserId(info.getUserId()); paymentRepository.save(payment); return new Response<>(1, "Pay Success", null); }else{ return new Response<>(0, "Pay Failed, order not found with order id" +info.getOrderId(), null); } }  @Override Response pay(Payment info, HttpHeaders headers); @Override Response addMoney(Payment info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers);  }### Answer:
@Test public void testPay1() { Payment info = new Payment(); Mockito.when(paymentRepository.findByOrderId(Mockito.anyString())).thenReturn(null); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); Response result = paymentServiceImpl.pay(info, headers); Assert.assertEquals(new Response<>(1, "Pay Success", null), result); }
@Test public void testPay2() { Payment info = new Payment(); Mockito.when(paymentRepository.findByOrderId(Mockito.anyString())).thenReturn(info); Response result = paymentServiceImpl.pay(info, headers); Assert.assertEquals(new Response<>(0, "Pay Failed, order not found with order id", null), result); }