### Question:
MovieServiceImpl implements MovieService { @Override public MovieResultModel updateMovie(final MovieDto movieDto) throws MovieNotFoundException { final String url = String.format(UPDATE_URL, serviceProperties.getMovieServiceUrl(), LocaleContextHolder.getLocale().getLanguage()); try { return retryHandler.run( () -> { final ResponseEntity<MovieResultModel> response = restTemplate.postForEntity(url, movieDto, MovieResultModel.class); if (response.getStatusCode().equals(HttpStatus.CONFLICT)) { throw new MovieConditionalException(); } if (response.getStatusCode().equals(HttpStatus.NOT_FOUND)) { throw new MovieNotFoundException(); } return response.getBody(); }, ex -> ex instanceof MovieConditionalException); } catch (final MovieNotFoundException ex) { throw ex; } catch (final Exception ex) { final String errorMessage = String.format("An error occured while updating movie %s: %s", movieDto.getId(), ex.getMessage()); log.error(errorMessage, ex); throw new MoviePersistenceException(errorMessage, ex); } }  @Override MoviePagedResultModel searchMovies(final String text, final int pageNumber, final String sortField,
        final boolean isAscending); @Override MovieResultModel createMovie(final MovieDto movieDto); @Override MovieDto getMovie(final UUID id); @Override boolean isAuthorizedOnMovie(final String account, final UUID movieId); @Override boolean isAuthorizedOnMovie(final String account, final MovieDto movieDto); @Override MovieResultModel updateMovie(final MovieDto movieDto); @Override void deleteMovie(final UUID movieId); @Override void likeMovie(final String account, final UUID movieId); @Override void unlikeMovie(final String account, final UUID movieId); @Override boolean hasLiked(final String account, final UUID movieId);  }### Answer:
@Test public void test_updateMovie_success() throws Exception { final MovieResultModel expectedResult = mock(MovieResultModel.class); final MovieDto movieDto = new MovieDto(); final String url = MOVIE_SERVICE_URL + MOVIE_UPDATE_PATH; when(movieResultModelResponse.getBody()).thenReturn(expectedResult); when(movieResultModelResponse.getStatusCode()).thenReturn(HttpStatus.OK); when(restTemplate.postForEntity(url, movieDto, MovieResultModel.class)) .thenReturn(movieResultModelResponse); final MovieResultModel result = movieService.updateMovie(movieDto); assertEquals(expectedResult, result); }
@Test public void test_updateMovie_conflict() throws Exception { final MovieResultModel expectedResult = mock(MovieResultModel.class); final MovieDto movieDto = new MovieDto(); final String url = MOVIE_SERVICE_URL + MOVIE_UPDATE_PATH; when(movieResultModelResponse.getBody()).thenReturn(expectedResult); when(movieResultModelResponse.getStatusCode()) .thenReturn(HttpStatus.CONFLICT) .thenReturn(HttpStatus.OK); when(restTemplate.postForEntity(url, movieDto, MovieResultModel.class)) .thenReturn(movieResultModelResponse); final MovieResultModel result = movieService.updateMovie(movieDto); assertEquals(expectedResult, result); verify(restTemplate, times(2)).postForEntity(url, movieDto, MovieResultModel.class); }
@Test(expected = MoviePersistenceException.class) public void test_updateMovie_exception() throws Exception { final MovieDto movieDto = new MovieDto(); final String url = MOVIE_SERVICE_URL + MOVIE_UPDATE_PATH; when(restTemplate.postForEntity(url, movieDto, MovieResultModel.class)).thenThrow(new RuntimeException()); movieService.updateMovie(movieDto); }
@Test(expected = MovieNotFoundException.class) public void test_updateMovie_notFound() throws Exception { final MovieDto movieDto = new MovieDto(); final String url = MOVIE_SERVICE_URL + MOVIE_UPDATE_PATH; when(movieResultModelResponse.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND); when(restTemplate.postForEntity(url, movieDto, MovieResultModel.class)) .thenReturn(movieResultModelResponse); movieService.updateMovie(movieDto); }