Skip to content

Commit

Permalink
test genres api
Browse files Browse the repository at this point in the history
  • Loading branch information
c-eg committed Feb 12, 2024
1 parent 943a066 commit 0570a68
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java
Original file line number Diff line number Diff line change
@@ -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<Genre> 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<Genre> genres = tmdbGenre.getTvList("en");
assertNotNull(genres);
assertFalse(genres.isEmpty());

Genre genre = genres.get(0);
assertNotNull(genre);
testForNullFieldsAndNewItems(genre);
}
}
80 changes: 80 additions & 0 deletions src/test/resources/api_responses/genres/movie_list.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
68 changes: 68 additions & 0 deletions src/test/resources/api_responses/genres/tv_list.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit 0570a68

Please sign in to comment.