### Question:
InsidePaymentServiceImpl implements InsidePaymentService { @Override public Response payDifference(PaymentInfo info, HttpHeaders headers) { String userId = info.getUserId(); Payment payment = new Payment(); payment.setOrderId(info.getOrderId()); payment.setPrice(info.getPrice()); payment.setUserId(info.getUserId()); List<Payment> payments = paymentRepository.findByUserId(userId); List<Money> addMonies = addMoneyRepository.findByUserId(userId); Iterator<Payment> paymentsIterator = payments.iterator(); Iterator<Money> addMoniesIterator = addMonies.iterator(); BigDecimal totalExpand = new BigDecimal("0"); while (paymentsIterator.hasNext()) { Payment p = paymentsIterator.next(); totalExpand.add(new BigDecimal(p.getPrice())); } totalExpand.add(new BigDecimal(info.getPrice())); BigDecimal money = new BigDecimal("0"); while (addMoniesIterator.hasNext()) { Money addMoney = addMoniesIterator.next(); money.add(new BigDecimal(addMoney.getMoney())); } if (totalExpand.compareTo(money) > 0) { Payment outsidePaymentInfo = new Payment(); outsidePaymentInfo.setOrderId(info.getOrderId()); outsidePaymentInfo.setUserId(userId); outsidePaymentInfo.setPrice(info.getPrice()); HttpEntity requestEntityOutsidePaySuccess = new HttpEntity(outsidePaymentInfo, headers); ResponseEntity<Response> reOutsidePaySuccess = restTemplate.exchange( "http: HttpMethod.POST, requestEntityOutsidePaySuccess, Response.class); Response outsidePaySuccess = reOutsidePaySuccess.getBody(); if (outsidePaySuccess.getStatus() == 1) { payment.setType(PaymentType.E); paymentRepository.save(payment); return new Response<>(1, "Pay Difference Success", null); } else { return new Response<>(0, "Pay Difference Failed", null); } } else { payment.setType(PaymentType.E); paymentRepository.save(payment); } return new Response<>(1, "Pay Difference Success", null); }  @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 testPayDifference() { PaymentInfo info = new PaymentInfo("user_id", "order_id", "G", "1.0"); List<Payment> payments = new ArrayList<>(); List<Money> monies = new ArrayList<>(); Money money = new Money(); money.setMoney("2.0"); monies.add(money); Mockito.when(paymentRepository.findByUserId(Mockito.anyString())).thenReturn(payments); Mockito.when(addMoneyRepository.findByUserId(Mockito.anyString())).thenReturn(monies); Mockito.when(paymentRepository.save(Mockito.any(Payment.class))).thenReturn(null); Response result = insidePaymentServiceImpl.payDifference(info, headers); Assert.assertEquals(new Response<>(1, "Pay Difference Success", null), result); }