### Question:
InsidePaymentServiceImpl implements InsidePaymentService { @Override public void initPayment(Payment payment, HttpHeaders headers) { Payment paymentTemp = paymentRepository.findById(payment.getId()); if (paymentTemp == null) { paymentRepository.save(payment); } else { InsidePaymentServiceImpl.LOGGER.info("[Inside Payment Service][Init Payment] Already Exists: {}", payment.getId()); } }  @Override Response pay(PaymentInfo info, HttpHeaders headers); @Override Response createAccount(AccountInfo info, HttpHeaders headers); @Override Response addMoney(String userId, String money, HttpHeaders headers); @Override Response queryAccount(HttpHeaders headers); String queryAccount(String userId, HttpHeaders headers); @Override Response queryPayment(HttpHeaders headers); @Override Response drawBack(String userId, String money, HttpHeaders headers); @Override Response payDifference(PaymentInfo info, HttpHeaders headers); @Override Response queryAddMoney(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); @Autowired
    public AddMoneyRepository addMoneyRepository; @Autowired
    public PaymentRepository paymentRepository; @Autowired
    public RestTemplate restTemplate; }### Answer:
@Test public void testInitPayment1() { Payment payment = new Payment(); Mockito.when(paymentRepository.findById(Mockito.anyString())).thenReturn(null); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); insidePaymentServiceImpl.initPayment(payment, headers); Mockito.verify(paymentRepository, times(1)).save(Mockito.any(Payment.class)); }
@Test public void testInitPayment2() { Payment payment = new Payment(); Mockito.when(paymentRepository.findById(Mockito.anyString())).thenReturn(payment); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); insidePaymentServiceImpl.initPayment(payment, headers); Mockito.verify(paymentRepository, times(0)).save(Mockito.any(Payment.class)); }