### Question:
RebookServiceImpl implements RebookService { @Override public Response payDifference(RebookInfo info, HttpHeaders httpHeaders) { Response queryOrderResult = getOrderByRebookInfo(info, httpHeaders); if (queryOrderResult.getStatus() == 0) { return new Response<>(0, queryOrderResult.getMsg(), null); } Order order = (Order) queryOrderResult.getData(); TripAllDetailInfo gtdi = new TripAllDetailInfo(); gtdi.setFrom(queryForStationName(order.getFrom(), httpHeaders)); gtdi.setTo(queryForStationName(order.getTo(), httpHeaders)); gtdi.setTravelDate(info.getDate()); gtdi.setTripId(info.getTripId()); Response gtdrResposne = getTripAllDetailInformation(gtdi, info.getTripId(), httpHeaders); TripAllDetail gtdr = (TripAllDetail) gtdrResposne.getData(); String ticketPrice = "0"; if (info.getSeatType() == SeatClass.FIRSTCLASS.getCode()) { ticketPrice = gtdr.getTripResponse().getPriceForConfortClass(); } else if (info.getSeatType() == SeatClass.SECONDCLASS.getCode()) { ticketPrice = gtdr.getTripResponse().getPriceForEconomyClass(); } String oldPrice = order.getPrice(); BigDecimal priceOld = new BigDecimal(oldPrice); BigDecimal priceNew = new BigDecimal(ticketPrice); if (payDifferentMoney(info.getOrderId(), info.getTripId(), info.getLoginId(), priceNew.subtract(priceOld).toString(), httpHeaders)) { return updateOrder(order, info, gtdr, ticketPrice, httpHeaders); } else { return new Response<>(0, "Can't pay the difference,please try again", null); } }  @Override Response rebook(RebookInfo info, HttpHeaders httpHeaders); @Override Response payDifference(RebookInfo info, HttpHeaders httpHeaders); Ticket dipatchSeat(Date date, String tripId, String startStationId, String endStataionId, int seatType, HttpHeaders httpHeaders);  }### Answer:
@Test public void testPayDifference() { RebookInfo info = new RebookInfo(); info.setTripId("G"); info.setOldTripId("G"); info.setLoginId("login_id"); info.setDate(new Date()); info.setSeatType(0); Order order = new Order(); order.setFrom("from_station"); order.setTo("to_station"); order.setPrice("0"); Response<Order> response = new Response<>(1, null, order); ResponseEntity<Response<Order>> re = new ResponseEntity<>(response, HttpStatus.OK); TripAllDetail tripAllDetail = new TripAllDetail(); Response<TripAllDetail> response2 = new Response<>(0, null, tripAllDetail); ResponseEntity<Response<TripAllDetail>> re2 = new ResponseEntity<>(response2, HttpStatus.OK); Mockito.when(restTemplate.exchange( Mockito.anyString(), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.any(ParameterizedTypeReference.class))) .thenReturn(re).thenReturn(re2); Response response3 = new Response<>(0, null, ""); ResponseEntity<Response> re3 = new ResponseEntity<>(response3, HttpStatus.OK); Mockito.when(restTemplate.exchange( Mockito.anyString(), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.any(Class.class))) .thenReturn(re3); Response result = rebookServiceImpl.payDifference(info, headers); Assert.assertEquals(new Response<>(0, "Can't pay the difference,please try again", null), result); }