diff --git a/src/main/java/info/movito/themoviedbapi/AbstractTmdbApi.java b/src/main/java/info/movito/themoviedbapi/AbstractTmdbApi.java index 5f276c7..6f60cbf 100644 --- a/src/main/java/info/movito/themoviedbapi/AbstractTmdbApi.java +++ b/src/main/java/info/movito/themoviedbapi/AbstractTmdbApi.java @@ -2,8 +2,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import info.movito.themoviedbapi.model.core.responses.ResponseStatus; import info.movito.themoviedbapi.model.core.responses.TmdbResponseException; @@ -11,8 +9,7 @@ import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.TmdbResponseCode; -import lombok.AccessLevel; -import lombok.Getter; +import info.movito.themoviedbapi.util.JsonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,11 +29,7 @@ public abstract class AbstractTmdbApi { public static final String PARAM_SORT_BY = "sort_by"; - @Getter(AccessLevel.PROTECTED) - private static final ObjectMapper objectMapper = new ObjectMapper() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - private static final ObjectReader responseStatusReader = objectMapper.readerFor(ResponseStatus.class); + private static final ObjectReader RESPONSE_STATUS_READER = JsonUtil.OBJECT_MAPPER.readerFor(ResponseStatus.class); private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTmdbApi.class); @@ -107,7 +100,7 @@ protected T mapJsonResult(ApiUrl apiUrl, String jsonBody, TypeReference r * @return the mapped class. */ protected T mapJsonResult(ApiUrl apiUrl, String jsonBody, RequestType requestType, Class clazz) throws TmdbException { - return mapJsonResult(apiUrl, jsonBody, requestType, objectMapper.readerFor(clazz)); + return mapJsonResult(apiUrl, jsonBody, requestType, JsonUtil.OBJECT_MAPPER.readerFor(clazz)); } /** @@ -122,7 +115,7 @@ protected T mapJsonResult(ApiUrl apiUrl, String jsonBody, RequestType reques */ protected T mapJsonResult(ApiUrl apiUrl, String jsonBody, RequestType requestType, TypeReference resultClass) throws TmdbException { - return mapJsonResult(apiUrl, jsonBody, requestType, objectMapper.readerFor(resultClass)); + return mapJsonResult(apiUrl, jsonBody, requestType, JsonUtil.OBJECT_MAPPER.readerFor(resultClass)); } /** @@ -141,7 +134,7 @@ private T mapJsonResult(ApiUrl apiUrl, String jsonBody, RequestType requestT try { // check if the response was successful. tmdb have their own codes for successful and unsuccessful responses. // some 2xx codes are not successful. See: https://developer.themoviedb.org/docs/errors for more info. - ResponseStatus responseStatus = responseStatusReader.readValue(jsonResponse); + ResponseStatus responseStatus = RESPONSE_STATUS_READER.readValue(jsonResponse); TmdbResponseCode tmdbResponseCode = responseStatus.getStatusCode(); if (tmdbResponseCode != null) { @@ -156,7 +149,7 @@ else if (!tmdbResponseCode.isSuccess()) { } } catch (JsonProcessingException exception) { - // ignore, not an error - caused by responseStatusReader.readValue(jsonResponse); + // ignore, not an error - caused by RESPONSE_STATUS_READER.readValue(jsonResponse); // this is necessary because if some requests fail (including 2xx responses), the response is a json object } catch (InterruptedException exception) { diff --git a/src/main/java/info/movito/themoviedbapi/TmdbAccount.java b/src/main/java/info/movito/themoviedbapi/TmdbAccount.java index d91e515..408c72f 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbAccount.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbAccount.java @@ -14,7 +14,7 @@ import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.sortby.AccountSortBy; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; /** * The movie database api for accounts. See the @@ -89,7 +89,7 @@ private ResponseStatus changeFavoriteStatus(Integer accountId, String sessionId, body.put("media_id", mediaId); body.put("favorite", isFavorite); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } @@ -135,7 +135,7 @@ private ResponseStatus changeWatchListStatus(Integer accountId, String sessionId body.put("media_id", mediaId); body.put("watchlist", isWatchList); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } diff --git a/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java b/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java index 2df4000..111ffeb 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java @@ -10,7 +10,7 @@ import info.movito.themoviedbapi.tools.ApiUrl; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; /** * The movie database api for authentication. See the @@ -105,7 +105,7 @@ public RequestToken createAuthenticatedRequestToken(RequestToken token, String u body.put("username", username); body.put("password", password); body.put(PARAM_REQUEST_TOKEN, token.getRequestToken()); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, RequestToken.class); } @@ -128,7 +128,7 @@ public Session createSession(RequestToken token) throws TmdbException { HashMap body = new HashMap<>(); body.put(PARAM_REQUEST_TOKEN, token.getRequestToken()); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, Session.class); } @@ -151,7 +151,7 @@ public ResponseStatusDelete deleteSession(String sessionId) throws TmdbException HashMap body = new HashMap<>(); body.put("session_id", sessionId); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.DELETE, ResponseStatusDelete.class); } diff --git a/src/main/java/info/movito/themoviedbapi/TmdbChanges.java b/src/main/java/info/movito/themoviedbapi/TmdbChanges.java index 6235aa5..4921fb1 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbChanges.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbChanges.java @@ -1,11 +1,13 @@ package info.movito.themoviedbapi; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + import info.movito.themoviedbapi.model.changes.ChangesResultsPage; import info.movito.themoviedbapi.tools.ApiUrl; import info.movito.themoviedbapi.tools.TmdbException; -import static info.movito.themoviedbapi.util.Utils.calculateDaysDifference; - /** * The movie database api for changes. See the * documentation for more info. @@ -94,4 +96,19 @@ public ChangesResultsPage getTvChangesList(String startDate, String endDate, Int return mapJsonResult(apiUrl, ChangesResultsPage.class); } + + /** + * Calculate the difference in days between two date strings. + * + * @param startDateString the start date string, in format: YYYY-MM-DD. + * @param endDateString the end date string, in format: YYYY-MM-DD. + * @return the difference in days. + */ + private static long calculateDaysDifference(String startDateString, String endDateString) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate startDate = LocalDate.parse(startDateString, formatter); + LocalDate endDate = LocalDate.parse(endDateString, formatter); + + return ChronoUnit.DAYS.between(startDate, endDate); + } } diff --git a/src/main/java/info/movito/themoviedbapi/TmdbLists.java b/src/main/java/info/movito/themoviedbapi/TmdbLists.java index 350a112..0e11fbf 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbLists.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbLists.java @@ -9,7 +9,7 @@ import info.movito.themoviedbapi.tools.ApiUrl; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; /** * The movie database api for lists. See the @@ -42,7 +42,7 @@ public ResponseStatus addMovie(Integer listId, String sessionId, Integer movieId HashMap body = new HashMap<>(); body.put("media_id", movieId); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } @@ -100,7 +100,7 @@ public MovieListCreationStatus create(String sessionId, String name, String desc body.put("description", description); body.put("language", language); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, MovieListCreationStatus.class); } @@ -153,7 +153,7 @@ public ResponseStatus removeMovie(Integer listId, String sessionId, Integer movi HashMap body = new HashMap<>(); body.put("media_id", movieId); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } } diff --git a/src/main/java/info/movito/themoviedbapi/TmdbMovies.java b/src/main/java/info/movito/themoviedbapi/TmdbMovies.java index b00d275..b25d99d 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbMovies.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbMovies.java @@ -22,7 +22,7 @@ import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.appendtoresponse.MovieAppendToResponse; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; /** * The movie database api for movies. See the @@ -325,7 +325,7 @@ public ResponseStatus addRating(int movieId, String guestSessionId, String sessi HashMap body = new HashMap<>(); body.put("value", rating); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } diff --git a/src/main/java/info/movito/themoviedbapi/TmdbTvEpisodes.java b/src/main/java/info/movito/themoviedbapi/TmdbTvEpisodes.java index d6c87f0..d80c5fd 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbTvEpisodes.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbTvEpisodes.java @@ -15,7 +15,7 @@ import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.appendtoresponse.TvEpisodesAppendToResponse; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import static info.movito.themoviedbapi.TmdbTvSeasons.TMDB_METHOD_TV_SEASON; import static info.movito.themoviedbapi.TmdbTvSeries.TMDB_METHOD_TV; @@ -213,7 +213,7 @@ public ResponseStatus addRating(int seriesId, int seasonNumber, int episodeNumbe HashMap body = new HashMap<>(); body.put("value", rating); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } diff --git a/src/main/java/info/movito/themoviedbapi/TmdbTvSeries.java b/src/main/java/info/movito/themoviedbapi/TmdbTvSeries.java index 9fbf3e2..77922c2 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbTvSeries.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbTvSeries.java @@ -25,7 +25,7 @@ import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.appendtoresponse.TvSeriesAppendToResponse; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; /** * The movie database api for tv series. See the @@ -368,7 +368,7 @@ public ResponseStatus addRating(int seriesId, String guestSessionId, String sess HashMap body = new HashMap<>(); body.put("value", rating); - String jsonBody = Utils.convertToJson(getObjectMapper(), body); + String jsonBody = JsonUtil.toJson(body); return mapJsonResult(apiUrl, jsonBody, RequestType.POST, ResponseStatus.class); } diff --git a/src/main/java/info/movito/themoviedbapi/model/movies/KeywordResults.java b/src/main/java/info/movito/themoviedbapi/model/movies/KeywordResults.java index d480824..16a3f4a 100644 --- a/src/main/java/info/movito/themoviedbapi/model/movies/KeywordResults.java +++ b/src/main/java/info/movito/themoviedbapi/model/movies/KeywordResults.java @@ -12,5 +12,5 @@ @EqualsAndHashCode(callSuper = true) public class KeywordResults extends IdElement { @JsonProperty("keywords") - List keywords; + private List keywords; } diff --git a/src/main/java/info/movito/themoviedbapi/util/JsonUtil.java b/src/main/java/info/movito/themoviedbapi/util/JsonUtil.java new file mode 100644 index 0000000..2a3e501 --- /dev/null +++ b/src/main/java/info/movito/themoviedbapi/util/JsonUtil.java @@ -0,0 +1,36 @@ +package info.movito.themoviedbapi.util; + +import java.util.Map; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +/** + * JSON Utility. + */ +public final class JsonUtil { + public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + private static final ObjectWriter MAP_WRITER = OBJECT_MAPPER.writerFor(Map.class); + + private JsonUtil() { + } + + /** + * Converts a Map to a JSON String. + * + * @param map the map to convert. + * @return the json. + */ + public static String toJson(Map map) { + try { + return MAP_WRITER.writeValueAsString(map); + } + catch (JsonProcessingException jpe) { + throw new RuntimeException("json conversion failed", jpe); + } + } +} diff --git a/src/main/java/info/movito/themoviedbapi/util/ModelUtil.java b/src/main/java/info/movito/themoviedbapi/util/ModelUtil.java new file mode 100644 index 0000000..5186b37 --- /dev/null +++ b/src/main/java/info/movito/themoviedbapi/util/ModelUtil.java @@ -0,0 +1,37 @@ +package info.movito.themoviedbapi.util; + +import java.util.Collection; +import java.util.List; + +import info.movito.themoviedbapi.model.core.NamedIdElement; +import info.movito.themoviedbapi.model.core.NamedStringIdElement; + +/** + * TMDB API Model Utility. + */ +public final class ModelUtil { + private ModelUtil() { + } + + /** + * Gets a list of names (from the name field) from the items in the collection provided. + * For model classes extending {@link NamedIdElement}. + * + * @param collection the collection. + * @return the list of names. + */ + public static List getNames(Collection collection) { + return collection.stream().map(NamedIdElement::getName).toList(); + } + + /** + * Gets a list of names (from the name field) from the items in the collection provided. + * For model classes extending {@link NamedStringIdElement}. + * + * @param collection the collection. + * @return the list of names. + */ + public static List getNamesString(Collection collection) { + return collection.stream().map(NamedStringIdElement::getName).toList(); + } +} diff --git a/src/main/java/info/movito/themoviedbapi/util/Utils.java b/src/main/java/info/movito/themoviedbapi/util/Utils.java deleted file mode 100644 index e97c0c3..0000000 --- a/src/main/java/info/movito/themoviedbapi/util/Utils.java +++ /dev/null @@ -1,44 +0,0 @@ -package info.movito.themoviedbapi.util; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * Utility class. - */ -public final class Utils { - private Utils() { - } - - /** - * Use Jackson to convert Map to json string. - */ - public static String convertToJson(ObjectMapper objectMapper, Map map) { - try { - return objectMapper.writeValueAsString(map); - } - catch (JsonProcessingException jpe) { - throw new RuntimeException("json conversion failed", jpe); - } - } - - /** - * Calculate the difference in days between two date strings. - * - * @param startDateString the start date string, in format: YYYY-MM-DD. - * @param endDateString the end date string, in format: YYYY-MM-DD. - * @return the difference in days. - */ - public static long calculateDaysDifference(String startDateString, String endDateString) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - LocalDate startDate = LocalDate.parse(startDateString, formatter); - LocalDate endDate = LocalDate.parse(endDateString, formatter); - - return ChronoUnit.DAYS.between(startDate, endDate); - } -} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index bb9fb15..d85c08c 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -82,4 +82,5 @@ exports info.movito.themoviedbapi.tools.builders.discover; exports info.movito.themoviedbapi.tools.sortby; exports info.movito.themoviedbapi.tools.model.time; + exports info.movito.themoviedbapi.util; } diff --git a/src/test/java/info/movito/themoviedbapi/TmdbAccountTest.java b/src/test/java/info/movito/themoviedbapi/TmdbAccountTest.java index 169fc8b..015a94a 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbAccountTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbAccountTest.java @@ -11,17 +11,17 @@ import info.movito.themoviedbapi.model.rated.RatedMovieResultsPage; import info.movito.themoviedbapi.model.rated.RatedTvEpisodeResultsPage; import info.movito.themoviedbapi.model.rated.RatedTvSeriesResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.TmdbResponseCode; import info.movito.themoviedbapi.tools.sortby.AccountSortBy; -import info.movito.themoviedbapi.util.TestUtils; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbAccount.TMDB_METHOD_ACCOUNT; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; @@ -64,7 +64,7 @@ public void testAddFavourite() throws TmdbException, IOException { requestBody.put("media_type", mediaType.toString()); requestBody.put("media_id", mediaId); requestBody.put("favorite", true); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String body = TestUtils.readTestFile("api_responses/account/add_favourite.json"); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); @@ -90,7 +90,7 @@ public void testRemoveFavorite() throws TmdbException, IOException { requestBody.put("media_type", mediaType.toString()); requestBody.put("media_id", mediaId); requestBody.put("favorite", false); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String body = TestUtils.readTestFile("api_responses/account/add_favourite.json"); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); @@ -116,7 +116,7 @@ public void testAddToWatchList() throws IOException, TmdbException { requestBody.put("media_type", mediaType.toString()); requestBody.put("media_id", mediaId); requestBody.put("watchlist", true); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String body = TestUtils.readTestFile("api_responses/account/add_to_watchlist.json"); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); @@ -142,7 +142,7 @@ public void testRemoveFromWatchList() throws IOException, TmdbException { requestBody.put("media_type", mediaType.toString()); requestBody.put("media_id", mediaId); requestBody.put("watchlist", false); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String body = TestUtils.readTestFile("api_responses/account/add_to_watchlist.json"); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); diff --git a/src/test/java/info/movito/themoviedbapi/TmdbAuthenticationTest.java b/src/test/java/info/movito/themoviedbapi/TmdbAuthenticationTest.java index 4c51751..2fdbad8 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbAuthenticationTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbAuthenticationTest.java @@ -9,16 +9,16 @@ import info.movito.themoviedbapi.model.core.responses.ResponseStatusAuthentication; import info.movito.themoviedbapi.model.core.responses.ResponseStatusDelete; import info.movito.themoviedbapi.model.core.responses.TmdbResponseException; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; -import info.movito.themoviedbapi.util.TestUtils; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbAuthentication.TMDB_METHOD_AUTH; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; import static info.movito.themoviedbapi.tools.TmdbResponseCode.INVALID_API_KEY; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -103,7 +103,7 @@ public void testCreateSession() throws TmdbException, IOException { HashMap requestBody = new HashMap<>(); requestBody.put("request_token", requestTokenStr); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String url = TMDB_API_BASE_URL + TMDB_METHOD_AUTH + "/session/new"; String body = TestUtils.readTestFile("api_responses/authentication/create_session.json"); @@ -140,7 +140,7 @@ public void testCreateAuthenticatedRequestToken() throws TmdbException, IOExcept requestBody.put("username", "username"); requestBody.put("password", "password"); requestBody.put("request_token", requestToken.getRequestToken()); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String url = TMDB_API_BASE_URL + TMDB_METHOD_AUTH + "/token/validate_with_login"; String body = TestUtils.readTestFile("api_responses/authentication/create_session_with_login.json"); @@ -170,7 +170,7 @@ public void testCreateSessionWithLoginUnsuccessfulRequestToken() { public void testDeleteSession() throws TmdbException, IOException { HashMap requestBody = new HashMap<>(); requestBody.put("session_id", "sessionId"); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String url = TMDB_API_BASE_URL + TMDB_METHOD_AUTH + "/session"; String body = TestUtils.readTestFile("api_responses/authentication/delete_session.json"); diff --git a/src/test/java/info/movito/themoviedbapi/TmdbCertificationsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbCertificationsTest.java index a26f575..5e3dbf7 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbCertificationsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbCertificationsTest.java @@ -3,16 +3,16 @@ import java.io.IOException; import info.movito.themoviedbapi.model.certifications.CertificationResults; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbCertifications.TMDB_METHOD_CERTIFICATIONS; import static info.movito.themoviedbapi.TmdbCertifications.TMDB_METHOD_MOVIE_CERTIFICATIONS; import static info.movito.themoviedbapi.TmdbCertifications.TMDB_METHOD_TV_CERTIFICATIONS; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbChangesTest.java b/src/test/java/info/movito/themoviedbapi/TmdbChangesTest.java index 72f1dab..5c8ff89 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbChangesTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbChangesTest.java @@ -3,17 +3,17 @@ import java.io.IOException; import info.movito.themoviedbapi.model.changes.ChangesResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbChanges.TMDB_METHOD_CHANGES; import static info.movito.themoviedbapi.TmdbChanges.TMDB_METHOD_MOVIE; import static info.movito.themoviedbapi.TmdbChanges.TMDB_METHOD_PERSON; import static info.movito.themoviedbapi.TmdbChanges.TMDB_METHOD_TV; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbCollectionsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbCollectionsTest.java index 09f77ab..72e8299 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbCollectionsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbCollectionsTest.java @@ -6,14 +6,14 @@ import info.movito.themoviedbapi.model.collections.CollectionInfo; import info.movito.themoviedbapi.model.collections.Images; import info.movito.themoviedbapi.model.collections.Translation; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbCollections.TMDB_METHOD_COLLECTION; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java b/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java index 73e30fb..a8eb773 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java @@ -5,14 +5,14 @@ import info.movito.themoviedbapi.model.companies.AlternativeNamesResultsPage; import info.movito.themoviedbapi.model.companies.Company; import info.movito.themoviedbapi.model.core.image.ImageResults; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbCompanies.TMDB_METHOD_COMPANY; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbConfigurationTest.java b/src/test/java/info/movito/themoviedbapi/TmdbConfigurationTest.java index b2204e6..8f10fd1 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbConfigurationTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbConfigurationTest.java @@ -8,14 +8,14 @@ import info.movito.themoviedbapi.model.configuration.Job; import info.movito.themoviedbapi.model.configuration.Timezone; import info.movito.themoviedbapi.model.core.Language; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbConfiguration.TMDB_METHOD_CONFIGURATION; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbDiscoverTest.java b/src/test/java/info/movito/themoviedbapi/TmdbDiscoverTest.java index 080bfca..8757d8d 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbDiscoverTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbDiscoverTest.java @@ -4,18 +4,18 @@ import info.movito.themoviedbapi.model.core.MovieResultsPage; import info.movito.themoviedbapi.model.core.TvSeriesResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.builders.discover.DiscoverMovieParamBuilder; import info.movito.themoviedbapi.tools.builders.discover.DiscoverTvParamBuilder; -import info.movito.themoviedbapi.util.TestUtils; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbDiscover.TMDB_METHOD_DISCOVER; import static info.movito.themoviedbapi.TmdbDiscover.TMDB_METHOD_MOVIE; import static info.movito.themoviedbapi.TmdbDiscover.TMDB_METHOD_TV; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbFindTest.java b/src/test/java/info/movito/themoviedbapi/TmdbFindTest.java index 740c24a..65d6e6e 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbFindTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbFindTest.java @@ -5,11 +5,11 @@ import java.util.List; import info.movito.themoviedbapi.model.find.FindResults; +import info.movito.themoviedbapi.testutil.AbstractJsonMappingValidator; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.model.time.ExternalSource; -import info.movito.themoviedbapi.util.AbstractJsonMappingValidator; -import info.movito.themoviedbapi.util.TestUtils; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbFind.TMDB_METHOD_FIND; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java b/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java index e0f598e..fded85a 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbGenresTest.java @@ -4,14 +4,14 @@ import java.util.List; import info.movito.themoviedbapi.model.core.Genre; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbGenre.TMDB_METHOD_GENRE; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbGuestSessionsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbGuestSessionsTest.java index 6c3404f..d72ba08 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbGuestSessionsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbGuestSessionsTest.java @@ -5,15 +5,15 @@ import info.movito.themoviedbapi.model.rated.RatedMovieResultsPage; import info.movito.themoviedbapi.model.rated.RatedTvEpisodeResultsPage; import info.movito.themoviedbapi.model.rated.RatedTvSeriesResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.sortby.AccountSortBy; -import info.movito.themoviedbapi.util.TestUtils; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbGuestSessions.TMDB_METHOD_GUEST_SESSIONS; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java index d462d43..5b0b107 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java @@ -3,14 +3,14 @@ import java.io.IOException; import info.movito.themoviedbapi.model.keywords.Keyword; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbKeywords.TMDB_METHOD_KEYWORD; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbListsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbListsTest.java index df06f38..c79a272 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbListsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbListsTest.java @@ -7,16 +7,16 @@ import info.movito.themoviedbapi.model.lists.ListDetails; import info.movito.themoviedbapi.model.lists.ListItemStatus; import info.movito.themoviedbapi.model.lists.MovieListCreationStatus; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.TmdbResponseCode; -import info.movito.themoviedbapi.util.TestUtils; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbLists.TMDB_METHOD_LIST; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; @@ -40,7 +40,7 @@ public void testAddMovie() throws IOException, TmdbException { HashMap requestBody = new HashMap<>(); requestBody.put("media_id", 456); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); @@ -91,7 +91,7 @@ public void testCreate() throws IOException, TmdbException { requestBody.put("name", "testName"); requestBody.put("description", "testDescription"); requestBody.put("language", "en-US"); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); @@ -139,7 +139,7 @@ public void testRemoveMovie() throws IOException, TmdbException { HashMap requestBody = new HashMap<>(); requestBody.put("media_id", 456); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); when(getTmdbUrlReader().readUrl(url, jsonBody, RequestType.POST)).thenReturn(body); diff --git a/src/test/java/info/movito/themoviedbapi/TmdbMovieListsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbMovieListsTest.java index f99be59..07df3be 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbMovieListsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbMovieListsTest.java @@ -4,14 +4,14 @@ import info.movito.themoviedbapi.model.core.MovieResultsPage; import info.movito.themoviedbapi.model.movielists.MovieResultsPageWithDates; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbMovieLists.TMDB_METHOD_MOVIE_LISTS; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbMoviesTest.java b/src/test/java/info/movito/themoviedbapi/TmdbMoviesTest.java index 8b5c1b3..508237c 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbMoviesTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbMoviesTest.java @@ -21,18 +21,18 @@ import info.movito.themoviedbapi.model.movies.ReleaseDateResults; import info.movito.themoviedbapi.model.movies.Translations; import info.movito.themoviedbapi.model.movies.changes.ChangeResults; +import info.movito.themoviedbapi.testutil.AbstractJsonMappingValidator; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.TmdbResponseCode; import info.movito.themoviedbapi.tools.appendtoresponse.MovieAppendToResponse; -import info.movito.themoviedbapi.util.AbstractJsonMappingValidator; -import info.movito.themoviedbapi.util.TestUtils; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbMovies.TMDB_METHOD_MOVIE; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; @@ -355,7 +355,7 @@ public void testGetWatchProviders() throws IOException, TmdbException { public void testAddRating() throws IOException, TmdbException { HashMap requestBody = new HashMap<>(); requestBody.put("value", 2.1); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String url = TMDB_API_BASE_URL + TMDB_METHOD_MOVIE + "/123/rating"; String body = TestUtils.readTestFile("api_responses/movies/add_rating.json"); diff --git a/src/test/java/info/movito/themoviedbapi/TmdbNetworksTest.java b/src/test/java/info/movito/themoviedbapi/TmdbNetworksTest.java index b5f770e..fe4aebb 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbNetworksTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbNetworksTest.java @@ -5,14 +5,14 @@ import info.movito.themoviedbapi.model.core.image.ImageResults; import info.movito.themoviedbapi.model.networks.AlternativeNamesResults; import info.movito.themoviedbapi.model.networks.Network; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbNetworks.TMDB_METHOD_NETWORK; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbPeopleListsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbPeopleListsTest.java index df7a2df..ba594b5 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbPeopleListsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbPeopleListsTest.java @@ -3,14 +3,14 @@ import java.io.IOException; import info.movito.themoviedbapi.model.core.popularperson.PopularPersonResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbPeopleLists.TMDB_METHOD_PEOPLE_LISTS; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbPeopleTest.java b/src/test/java/info/movito/themoviedbapi/TmdbPeopleTest.java index f69a68b..2ce6456 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbPeopleTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbPeopleTest.java @@ -19,16 +19,16 @@ import info.movito.themoviedbapi.model.people.credits.TvCast; import info.movito.themoviedbapi.model.people.credits.TvCredits; import info.movito.themoviedbapi.model.people.credits.TvCrew; +import info.movito.themoviedbapi.testutil.AbstractJsonMappingValidator; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.appendtoresponse.PersonAppendToResponse; -import info.movito.themoviedbapi.util.AbstractJsonMappingValidator; -import info.movito.themoviedbapi.util.TestUtils; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbPeople.TMDB_METHOD_PERSON; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbReviewsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbReviewsTest.java index ca20188..83243cd 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbReviewsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbReviewsTest.java @@ -3,14 +3,14 @@ import java.io.IOException; import info.movito.themoviedbapi.model.reviews.Review; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbReviews.TMDB_METHOD_MOVIE_REVIEW; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTrendingTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTrendingTest.java index 56deec2..4122f6c 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTrendingTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTrendingTest.java @@ -6,15 +6,15 @@ import info.movito.themoviedbapi.model.core.TvSeriesResultsPage; import info.movito.themoviedbapi.model.core.multi.MultiResultsPage; import info.movito.themoviedbapi.model.core.popularperson.PopularPersonResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.model.time.TimeWindow; -import info.movito.themoviedbapi.util.TestUtils; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbTrending.TMDB_METHOD_TRENDING; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodeGroupsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodeGroupsTest.java index 99883df..53924a0 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodeGroupsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodeGroupsTest.java @@ -4,14 +4,14 @@ import info.movito.themoviedbapi.model.tv.episodegroups.EpisodeGroupType; import info.movito.themoviedbapi.model.tv.episodegroups.TvEpisodeGroups; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbTvEpisodeGroups.TMDB_METHOD_TV_EPISODE_GROUPS; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodesTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodesTest.java index edc4882..c469c9c 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodesTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTvEpisodesTest.java @@ -14,20 +14,20 @@ import info.movito.themoviedbapi.model.tv.episode.ExternalIds; import info.movito.themoviedbapi.model.tv.episode.Images; import info.movito.themoviedbapi.model.tv.episode.TvEpisodeDb; +import info.movito.themoviedbapi.testutil.AbstractJsonMappingValidator; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.TmdbResponseCode; import info.movito.themoviedbapi.tools.appendtoresponse.TvEpisodesAppendToResponse; -import info.movito.themoviedbapi.util.AbstractJsonMappingValidator; -import info.movito.themoviedbapi.util.TestUtils; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbTvEpisodes.TMDB_METHOD_TV_EPISODE; import static info.movito.themoviedbapi.TmdbTvSeasons.TMDB_METHOD_TV_SEASON; import static info.movito.themoviedbapi.TmdbTvSeries.TMDB_METHOD_TV; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; @@ -199,7 +199,7 @@ public void testGetVideos() throws IOException, TmdbException { public void testAddRating() throws IOException, TmdbException { HashMap requestBody = new HashMap<>(); requestBody.put("value", 2.1); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String url = TMDB_API_BASE_URL + TMDB_METHOD_TV + "/123/" + TMDB_METHOD_TV_SEASON + "/1/" + TMDB_METHOD_TV_EPISODE + "/1/rating"; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTvSearchTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTvSearchTest.java index 63e46a3..b745560 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTvSearchTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTvSearchTest.java @@ -14,13 +14,13 @@ import info.movito.themoviedbapi.model.search.CollectionResultsPage; import info.movito.themoviedbapi.model.search.CompanyResultsPage; import info.movito.themoviedbapi.model.search.KeywordResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTvSeasonsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTvSeasonsTest.java index d3fad14..f4133c1 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTvSeasonsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTvSeasonsTest.java @@ -14,17 +14,17 @@ import info.movito.themoviedbapi.model.tv.season.ExternalIds; import info.movito.themoviedbapi.model.tv.season.Images; import info.movito.themoviedbapi.model.tv.season.TvSeasonDb; +import info.movito.themoviedbapi.testutil.AbstractJsonMappingValidator; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.appendtoresponse.TvSeasonsAppendToResponse; -import info.movito.themoviedbapi.util.AbstractJsonMappingValidator; -import info.movito.themoviedbapi.util.TestUtils; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbTvSeasons.TMDB_METHOD_TV_SEASON; import static info.movito.themoviedbapi.TmdbTvSeries.TMDB_METHOD_TV; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesListsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesListsTest.java index fa537ff..e76bd21 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesListsTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesListsTest.java @@ -3,14 +3,14 @@ import java.io.IOException; import info.movito.themoviedbapi.model.core.TvSeriesResultsPage; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbTvSeries.TMDB_METHOD_TV; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesTest.java b/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesTest.java index 3c96062..64cb78b 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbTvSeriesTest.java @@ -24,18 +24,18 @@ import info.movito.themoviedbapi.model.tv.series.Translations; import info.movito.themoviedbapi.model.tv.series.TvSeriesDb; import info.movito.themoviedbapi.model.tv.series.TvSeriesListResultsPage; +import info.movito.themoviedbapi.testutil.AbstractJsonMappingValidator; +import info.movito.themoviedbapi.testutil.TestUtils; import info.movito.themoviedbapi.tools.RequestType; import info.movito.themoviedbapi.tools.TmdbException; import info.movito.themoviedbapi.tools.TmdbResponseCode; import info.movito.themoviedbapi.tools.appendtoresponse.TvSeriesAppendToResponse; -import info.movito.themoviedbapi.util.AbstractJsonMappingValidator; -import info.movito.themoviedbapi.util.TestUtils; -import info.movito.themoviedbapi.util.Utils; +import info.movito.themoviedbapi.util.JsonUtil; import org.junit.jupiter.api.Test; import static info.movito.themoviedbapi.TmdbTvSeries.TMDB_METHOD_TV; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; @@ -406,7 +406,7 @@ public void testGetWatchProviders() throws IOException, TmdbException { public void testAddRating() throws IOException, TmdbException { HashMap requestBody = new HashMap<>(); requestBody.put("value", 2.1); - String jsonBody = Utils.convertToJson(AbstractTmdbApi.getObjectMapper(), requestBody); + String jsonBody = JsonUtil.toJson(requestBody); String url = TMDB_API_BASE_URL + TMDB_METHOD_TV + "/123/rating"; String body = TestUtils.readTestFile("api_responses/tv_series/add_rating.json"); diff --git a/src/test/java/info/movito/themoviedbapi/TmdbWatchProvidersTest.java b/src/test/java/info/movito/themoviedbapi/TmdbWatchProvidersTest.java index 256700b..199de26 100644 --- a/src/test/java/info/movito/themoviedbapi/TmdbWatchProvidersTest.java +++ b/src/test/java/info/movito/themoviedbapi/TmdbWatchProvidersTest.java @@ -6,14 +6,14 @@ import info.movito.themoviedbapi.model.watchproviders.AvailableRegionResults; import info.movito.themoviedbapi.model.watchproviders.Provider; import info.movito.themoviedbapi.model.watchproviders.ProviderResults; +import info.movito.themoviedbapi.testutil.TestUtils; 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 static info.movito.themoviedbapi.TmdbWatchProviders.TMDB_METHOD_WATCH_PROVIDERS; +import static info.movito.themoviedbapi.testutil.TestUtils.validateAbstractJsonMappingFields; import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL; -import static info.movito.themoviedbapi.util.TestUtils.validateAbstractJsonMappingFields; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; diff --git a/src/test/java/info/movito/themoviedbapi/util/AbstractJsonMappingValidator.java b/src/test/java/info/movito/themoviedbapi/testutil/AbstractJsonMappingValidator.java similarity index 99% rename from src/test/java/info/movito/themoviedbapi/util/AbstractJsonMappingValidator.java rename to src/test/java/info/movito/themoviedbapi/testutil/AbstractJsonMappingValidator.java index 22429a1..c8f66d5 100644 --- a/src/test/java/info/movito/themoviedbapi/util/AbstractJsonMappingValidator.java +++ b/src/test/java/info/movito/themoviedbapi/testutil/AbstractJsonMappingValidator.java @@ -1,4 +1,4 @@ -package info.movito.themoviedbapi.util; +package info.movito.themoviedbapi.testutil; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/src/test/java/info/movito/themoviedbapi/util/TestUtils.java b/src/test/java/info/movito/themoviedbapi/testutil/TestUtils.java similarity index 96% rename from src/test/java/info/movito/themoviedbapi/util/TestUtils.java rename to src/test/java/info/movito/themoviedbapi/testutil/TestUtils.java index 96f181c..c225a8a 100644 --- a/src/test/java/info/movito/themoviedbapi/util/TestUtils.java +++ b/src/test/java/info/movito/themoviedbapi/testutil/TestUtils.java @@ -1,4 +1,4 @@ -package info.movito.themoviedbapi.util; +package info.movito.themoviedbapi.testutil; import java.io.IOException; import java.io.InputStream; diff --git a/src/test/java/info/movito/themoviedbapi/util/JsonUtilTest.java b/src/test/java/info/movito/themoviedbapi/util/JsonUtilTest.java new file mode 100644 index 0000000..bddbe34 --- /dev/null +++ b/src/test/java/info/movito/themoviedbapi/util/JsonUtilTest.java @@ -0,0 +1,52 @@ +package info.movito.themoviedbapi.util; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests for {@link JsonUtil}. + */ +public class JsonUtilTest { + /** + * Tests {@link JsonUtil#toJson(Map)}, with string keys and string values. + */ + @Test + public void testToJsonStringString() { + Map map = new HashMap<>(); + map.put("key1", "value1"); + map.put("key2", "value2"); + + String json = JsonUtil.toJson(map); + assertEquals("{\"key1\":\"value1\",\"key2\":\"value2\"}", json); + } + + /** + * Tests {@link JsonUtil#toJson(Map)}, with string keys and boolean values. + */ + @Test + public void testToJsonStringBoolean() { + Map map = new HashMap<>(); + map.put("key1", true); + map.put("key2", false); + + String json = JsonUtil.toJson(map); + assertEquals("{\"key1\":true,\"key2\":false}", json); + } + + /** + * Tests {@link JsonUtil#toJson(Map)}, with string keys and integer values. + */ + @Test + public void testToJsonStringInteger() { + Map map = new HashMap<>(); + map.put("key1", 1); + map.put("key2", 2); + + String json = JsonUtil.toJson(map); + assertEquals("{\"key1\":1,\"key2\":2}", json); + } +} diff --git a/src/test/java/info/movito/themoviedbapi/util/ModelUtilTest.java b/src/test/java/info/movito/themoviedbapi/util/ModelUtilTest.java new file mode 100644 index 0000000..da468de --- /dev/null +++ b/src/test/java/info/movito/themoviedbapi/util/ModelUtilTest.java @@ -0,0 +1,56 @@ +package info.movito.themoviedbapi.util; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import info.movito.themoviedbapi.model.keywords.Keyword; +import info.movito.themoviedbapi.model.tv.series.EpisodeGroup; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests for {@link ModelUtil}. + */ +public class ModelUtilTest { + /** + * Tests {@link ModelUtil#getNames(Collection)}. + */ + @Test + public void testGetNames() { + Keyword name1 = new Keyword(); + name1.setName("name1"); + Keyword name2 = new Keyword(); + name2.setName("name2"); + Keyword name3 = new Keyword(); + name3.setName("name3"); + + List keywords = Arrays.asList(name1, name2, name3); + + List names = ModelUtil.getNames(keywords); + assertEquals("name1", names.get(0)); + assertEquals("name2", names.get(1)); + assertEquals("name3", names.get(2)); + } + + /** + * Tests {@link ModelUtil#getNamesString(Collection)}. + */ + @Test + public void testGetNamesString() { + EpisodeGroup name1 = new EpisodeGroup(); + name1.setName("name1"); + EpisodeGroup name2 = new EpisodeGroup(); + name2.setName("name2"); + EpisodeGroup name3 = new EpisodeGroup(); + name3.setName("name3"); + + List episodeGroups = Arrays.asList(name1, name2, name3); + + List names = ModelUtil.getNamesString(episodeGroups); + assertEquals("name1", names.get(0)); + assertEquals("name2", names.get(1)); + assertEquals("name3", names.get(2)); + } +}