From 9e5a80d29af1b6365500388172d644bbe151d1cf Mon Sep 17 00:00:00 2001 From: Marouane Addou <105064179+marouaneaddou@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:00:32 +0000 Subject: [PATCH] test: add failure test cases (#81) --- .../serviceImpl/MovieServiceImplTest.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/filmexa/stream/modules/moviesExternal/serviceImpl/MovieServiceImplTest.java b/src/test/java/com/filmexa/stream/modules/moviesExternal/serviceImpl/MovieServiceImplTest.java index b45042e..2d605a4 100644 --- a/src/test/java/com/filmexa/stream/modules/moviesExternal/serviceImpl/MovieServiceImplTest.java +++ b/src/test/java/com/filmexa/stream/modules/moviesExternal/serviceImpl/MovieServiceImplTest.java @@ -6,7 +6,7 @@ /* By: maddou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/09/26 12:52:27 by marouan #+# #+# */ -/* Updated: 2026/09/28 22:57:52 by maddou ### ########.fr */ +/* Updated: 2026/09/29 12:05:18 by maddou ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; import org.springframework.data.domain.PageRequest; import org.junit.jupiter.api.extension.ExtendWith; @@ -54,6 +55,7 @@ import com.filmexa.stream.modules.moviesExternal.dto.request.MovieSearchQuery; import com.filmexa.stream.modules.moviesExternal.dto.response.MoviePageResponse; import com.filmexa.stream.modules.moviesExternal.dto.response.MovieResponse; +import com.filmexa.stream.common.exception.ExternalServiceException; import com.filmexa.stream.common.exception.InvalidPaginationException; import com.filmexa.stream.common.exception.NotFoundException; @@ -285,6 +287,42 @@ void shouldReturnMovieById( ) { .getTraierMovie( 27205); } + @Test + void shouldThrownNotFoundExceptionWhenRetrieveMovieById( ) { + when( movieProvider.getMovieById("en", 2014587) ) + .thenThrow( new NotFoundException("Movie deos not exist") ); + + + NotFoundException notFound = assertThrows( + NotFoundException.class, + () -> movieService.getMovieById( "en", 2014587 ) + ); + + assertThat(notFound.getMessage()) + .isEqualTo( "Movie deos not exist" ); + + verify( movieProvider ) + .getMovieById("en",2014587); + } + + @Test + void shouldthrowExternalServiceExceptionWhenServiceUnavailable( ) { + when( movieProvider.getMovieById("en", 2014587) ) + .thenThrow( new ExternalServiceException("External service is unavailable") ); + + + ExternalServiceException unavailable = assertThrows( + ExternalServiceException.class, + () -> movieService.getMovieById( "en", 2014587 ) + ); + + assertThat(unavailable.getMessage()) + .isEqualTo( "External service is unavailable" ); + + verify( movieProvider ) + .getMovieById("en",2014587); + } + @Test void shouldCallDiscoverMoviesWhenQueryIsNull() { MovieSearchQuery query = new MovieSearchQuery(