### Question:
TravelServiceImpl implements TravelService { @Override public Response getRouteByTripId(String tripId, HttpHeaders headers) { Route route = null; if (null != tripId && tripId.length() >= 2) { TripId tripId1 = new TripId(tripId); Trip trip = repository.findByTripId(tripId1); if (trip != null) { route = getRouteByRouteId(trip.getRouteId(), headers); } } if (route != null) { return new Response<>(1, success, route); } 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 testGetRouteByTripId1() { Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(null); Response result = travelServiceImpl.getRouteByTripId("K1255", headers); Assert.assertEquals(new Response<>(0, "No Content", null), result); }
@Test public void testGetRouteByTripId2() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Route route = new Route(); Response response = new Response(1, null, route); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( Mockito.anyString(), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.any(Class.class))) .thenReturn(re); Response result = travelServiceImpl.getRouteByTripId("K1255", headers); Assert.assertEquals("Success", result.getMsg()); }