### Question:
PaymentServiceImpl implements PaymentService { @Override public void initPayment(Payment payment, HttpHeaders headers){ Payment paymentTemp = paymentRepository.findById(payment.getId()); if(paymentTemp == null){ paymentRepository.save(payment); }else{ PaymentServiceImpl.LOGGER.info("[Payment Service][Init Payment] Already Exists: {}", payment.getId()); } }  @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 testInitPayment1() { Payment payment = new Payment(); Mockito.when(paymentRepository.findById(Mockito.anyString())).thenReturn(null); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); paymentServiceImpl.initPayment(payment, headers); Mockito.verify(paymentRepository, Mockito.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); paymentServiceImpl.initPayment(payment, headers); Mockito.verify(paymentRepository, Mockito.times(0)).save(Mockito.any(Payment.class)); }