### Question:
TravelServiceImpl implements TravelService { @Override public Response getTrainTypeByTripId(String tripId, HttpHeaders headers) { TripId tripId1 = new TripId(tripId); TrainType trainType = null; Trip trip = repository.findByTripId(tripId1); if (trip != null) { trainType = getTrainType(trip.getTrainTypeId(), headers); } if (trainType != null) { return new Response<>(1, success, trainType); } 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 testGetTrainTypeByTripId() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); 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.getTrainTypeByTripId("K1255", headers); Assert.assertEquals(new Response<>(1, "Success", trainType), result); }