### Question:
TravelServiceImpl implements TravelService { @Override public Response adminQueryAll(HttpHeaders headers) { List<Trip> trips = repository.findAll(); ArrayList<AdminTrip> adminTrips = new ArrayList<>(); for (Trip trip : trips) { AdminTrip adminTrip = new AdminTrip(); adminTrip.setTrip(trip); adminTrip.setRoute(getRouteByRouteId(trip.getRouteId(), headers)); adminTrip.setTrainType(getTrainType(trip.getTrainTypeId(), headers)); adminTrips.add(adminTrip); } if (!adminTrips.isEmpty()) { return new Response<>(1, success, adminTrips); } else { return new Response<>(0, noContent, null); } }  @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, 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 testAdminQueryAll1() { 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(); 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); TrainType trainType = new TrainType(); Response<TrainType> response = new Response<>(null, null, trainType); ResponseEntity<Response<TrainType>> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( Mockito.anyString(), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.any(ParameterizedTypeReference.class))) .thenReturn(re); Response result = travelServiceImpl.adminQueryAll(headers); Assert.assertEquals("Success", result.getMsg()); }
@Test public void testAdminQueryAll2() { ArrayList<Trip> tripList = new ArrayList<>(); Mockito.when(repository.findAll()).thenReturn(tripList); Response result = travelServiceImpl.adminQueryAll(headers); Assert.assertEquals(new Response<>(0, noCnontent, null), result); }