From 0570a68d9a8ca7e82aad69dfdca9e1990cca0be6 Mon Sep 17 00:00:00 2001 From: Conor Egan <68134729+c-eg@users.noreply.github.com> Date: Mon, 12 Feb 2024 22:49:40 +0000 Subject: [PATCH] test genres api --- .../movito/themoviedbapi/TmdbGenresTest.java | 61 ++++++++++++++ .../api_responses/genres/movie_list.json | 80 +++++++++++++++++++ .../api_responses/genres/tv_list.json | 68 ++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java create mode 100644 src/test/resources/api_responses/genres/movie_list.json create mode 100644 src/test/resources/api_responses/genres/tv_list.json diff --git a/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java b/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java new file mode 100644 index 0000000..191bc65 --- /dev/null +++ b/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java @@ -0,0 +1,61 @@ +package info.movito.themoviedbapi; + +import info.movito.themoviedbapi.model.Genre; +import info.movito.themoviedbapi.tools.RequestType; +import info.movito.themoviedbapi.tools.TmdbException; +import info.movito.themoviedbapi.util.TestUtils; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import static info.movito.themoviedbapi.TmdbGenre.TMDB_METHOD_GENRE; +import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; +import static info.movito.themoviedbapi.util.TestUtils.testForNullFieldsAndNewItems; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.when; + +/** + * Tests for {@link TmdbGenre}. + */ +public class TmdbGenresTest extends AbstractTmdbApiTest { + /** + * Tests {@link TmdbGenre#getMovieList(String)} with an expected result. + */ + @Test + public void testGetMovieList() throws IOException, TmdbException { + String body = TestUtils.readTestFile("api_responses/genres/movie_list.json"); + URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_GENRE + "/movie/list?language=en"); + when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body); + + TmdbGenre tmdbGenre = new TmdbGenre(getTmdbApi()); + List genres = tmdbGenre.getMovieList("en"); + assertNotNull(genres); + assertFalse(genres.isEmpty()); + + Genre genre = genres.get(0); + assertNotNull(genre); + testForNullFieldsAndNewItems(genre); + } + + /** + * Tests {@link TmdbGenre#getTvList(String)} with an expected result. + */ + @Test + public void testGetTvList() throws IOException, TmdbException { + String body = TestUtils.readTestFile("api_responses/genres/tv_list.json"); + URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_GENRE + "/tv/list?language=en"); + when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body); + + TmdbGenre tmdbGenre = new TmdbGenre(getTmdbApi()); + List genres = tmdbGenre.getTvList("en"); + assertNotNull(genres); + assertFalse(genres.isEmpty()); + + Genre genre = genres.get(0); + assertNotNull(genre); + testForNullFieldsAndNewItems(genre); + } +} diff --git a/src/test/resources/api_responses/genres/movie_list.json b/src/test/resources/api_responses/genres/movie_list.json new file mode 100644 index 0000000..1c110c1 --- /dev/null +++ b/src/test/resources/api_responses/genres/movie_list.json @@ -0,0 +1,80 @@ +{ + "genres": [ + { + "id": 28, + "name": "Action" + }, + { + "id": 12, + "name": "Abenteuer" + }, + { + "id": 16, + "name": "Animation" + }, + { + "id": 35, + "name": "Komödie" + }, + { + "id": 80, + "name": "Krimi" + }, + { + "id": 99, + "name": "Dokumentarfilm" + }, + { + "id": 18, + "name": "Drama" + }, + { + "id": 10751, + "name": "Familie" + }, + { + "id": 14, + "name": "Fantasy" + }, + { + "id": 36, + "name": "Historie" + }, + { + "id": 27, + "name": "Horror" + }, + { + "id": 10402, + "name": "Musik" + }, + { + "id": 9648, + "name": "Mystery" + }, + { + "id": 10749, + "name": "Liebesfilm" + }, + { + "id": 878, + "name": "Science Fiction" + }, + { + "id": 10770, + "name": "TV-Film" + }, + { + "id": 53, + "name": "Thriller" + }, + { + "id": 10752, + "name": "Kriegsfilm" + }, + { + "id": 37, + "name": "Western" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/api_responses/genres/tv_list.json b/src/test/resources/api_responses/genres/tv_list.json new file mode 100644 index 0000000..5d3a4ca --- /dev/null +++ b/src/test/resources/api_responses/genres/tv_list.json @@ -0,0 +1,68 @@ +{ + "genres": [ + { + "id": 10759, + "name": "Action & Adventure" + }, + { + "id": 16, + "name": "Animation" + }, + { + "id": 35, + "name": "Komödie" + }, + { + "id": 80, + "name": "Krimi" + }, + { + "id": 99, + "name": "Dokumentarfilm" + }, + { + "id": 18, + "name": "Drama" + }, + { + "id": 10751, + "name": "Familie" + }, + { + "id": 10762, + "name": "Kids" + }, + { + "id": 9648, + "name": "Mystery" + }, + { + "id": 10763, + "name": "News" + }, + { + "id": 10764, + "name": "Reality" + }, + { + "id": 10765, + "name": "Sci-Fi & Fantasy" + }, + { + "id": 10766, + "name": "Soap" + }, + { + "id": 10767, + "name": "Talk" + }, + { + "id": 10768, + "name": "War & Politics" + }, + { + "id": 37, + "name": "Western" + } + ] +} \ No newline at end of file