### Question:
AdminTravelServiceImpl implements AdminTravelService { @Override public Response addTravel(TravelInfo request, HttpHeaders headers) { Response resultResponse; String requestUrl; if (request.getTrainTypeId().charAt(0) == 'G' || request.getTrainTypeId().charAt(0) == 'D') { requestUrl = "http: } else { requestUrl = "http: } HttpEntity requestEntity = new HttpEntity(request, headers); ResponseEntity<Response> re = restTemplate.exchange( requestUrl, HttpMethod.POST, requestEntity, Response.class); resultResponse = re.getBody(); if (resultResponse.getStatus() == 1) { AdminTravelServiceImpl.LOGGER.info("[Admin Travel Service][Admin add new travel]"); return new Response<>(1, "[Admin Travel Service][Admin add new travel]", null); } else { return new Response<>(0, "Admin add new travel failed", null); } }  @Override Response getAllTravels(HttpHeaders headers); @Override Response addTravel(TravelInfo request, HttpHeaders headers); @Override Response updateTravel(TravelInfo request, HttpHeaders headers); @Override Response deleteTravel(String tripId, HttpHeaders headers);  }### Answer:
@Test public void testAddTravel1() { TravelInfo request = new TravelInfo(null, null, "G", null, null, null, null, null, null); HttpEntity requestEntity2 = new HttpEntity<>(request, headers); Response response = new Response<>(0, null, null); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity2, Response.class)).thenReturn(re); Response result = adminTravelServiceImpl.addTravel(request, headers); Assert.assertEquals(new Response<>(0, "Admin add new travel failed", null), result); }
@Test public void testAddTravel2() { TravelInfo request = new TravelInfo(null, null, "G", null, null, null, null, null, null); HttpEntity<TravelInfo> requestEntity2 = new HttpEntity<>(request, headers); Response response = new Response<>(1, null, null); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity2, Response.class)).thenReturn(re); Response result = adminTravelServiceImpl.addTravel(request, headers); Assert.assertEquals(new Response<>(1, "[Admin Travel Service][Admin add new travel]", null), result); }
@Test public void testAddTravel3() { TravelInfo request = new TravelInfo(null, null, "K", null, null, null, null, null, null); HttpEntity<TravelInfo> requestEntity2 = new HttpEntity<>(request, headers); Response response = new Response<>(0, null, null); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity2, Response.class)).thenReturn(re); Response result = adminTravelServiceImpl.addTravel(request, headers); Assert.assertEquals(new Response<>(0, "Admin add new travel failed", null), result); }
@Test public void testAddTravel4() { TravelInfo request = new TravelInfo(null, null, "K", null, null, null, null, null, null); HttpEntity<TravelInfo> requestEntity2 = new HttpEntity<>(request, headers); Response response = new Response<>(1, null, null); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity2, Response.class)).thenReturn(re); Response result = adminTravelServiceImpl.addTravel(request, headers); Assert.assertEquals(new Response<>(1, "[Admin Travel Service][Admin add new travel]", null), result); }