### Question:
Travel2ServiceImpl implements Travel2Service { @Override public Response query(TripInfo info, HttpHeaders headers) { String startingPlaceName = info.getStartingPlace(); String endPlaceName = info.getEndPlace(); String startingPlaceId = queryForStationId(startingPlaceName, headers); String endPlaceId = queryForStationId(endPlaceName, headers); ArrayList<TripResponse> list = new ArrayList<>(); ArrayList<Trip> allTripList = repository.findAll(); for (Trip tempTrip : allTripList) { Route tempRoute = getRouteByRouteId(tempTrip.getRouteId(), headers); if (tempRoute.getStations().contains(startingPlaceId) && tempRoute.getStations().contains(endPlaceId) && tempRoute.getStations().indexOf(startingPlaceId) < tempRoute.getStations().indexOf(endPlaceId)) { TripResponse response = getTickets(tempTrip, tempRoute, startingPlaceId, endPlaceId, startingPlaceName, endPlaceName, info.getDepartureTime(), headers); if (response == null) { return new Response<>(0, noCnontent, null); } list.add(response); } } return new Response<>(1, "Success Query", list); }  @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers);  }### Answer:
@Test public void testQuery() { TripInfo info = new TripInfo(); Response<String> response1 = new Response<>(null, null, ""); ResponseEntity<Response<String>> re1 = new ResponseEntity<>(response1, HttpStatus.OK); Mockito.when(restTemplate.exchange( Mockito.anyString(), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.any(ParameterizedTypeReference.class))) .thenReturn(re1); ArrayList<Trip> tripList = new ArrayList<>(); Trip trip = new Trip(); trip.setRouteId("route_id"); tripList.add(trip); Mockito.when(repository.findAll()).thenReturn(tripList); Route route = new Route(); route.setStations(new ArrayList<>()); Response response2 = new Response(1, null, route); ResponseEntity<Response> re2 = new ResponseEntity<>(response2, HttpStatus.OK); Mockito.when(restTemplate.exchange( Mockito.anyString(), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.any(Class.class))) .thenReturn(re2); Response result = travel2ServiceImpl.query(info, headers); Assert.assertEquals(new Response<>(1, "Success Query", new ArrayList<>()), result); }