diff --git a/src/main/java/com/omertron/themoviedbapi/model/person/CreditBasic.java b/src/main/java/com/omertron/themoviedbapi/model/person/CreditBasic.java index a732e974a..19a3ce4a1 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/person/CreditBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model/person/CreditBasic.java @@ -1,3 +1,4 @@ + /* * Copyright (c) 2004-2015 Stuart Boston * diff --git a/src/test/java/com/omertron/themoviedbapi/TestSuite.java b/src/test/java/com/omertron/themoviedbapi/TestSuite.java index dd9c10258..d2a8d40bb 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestSuite.java +++ b/src/test/java/com/omertron/themoviedbapi/TestSuite.java @@ -24,7 +24,13 @@ import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.tv.TVBasic; import com.omertron.themoviedbapi.results.ResultList; import com.omertron.themoviedbapi.interfaces.IIdentification; +import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model.tv.TVEpisodeInfo; +import com.omertron.themoviedbapi.model.tv.TVInfo; +import com.omertron.themoviedbapi.model.tv.TVSeasonInfo; import java.util.List; +import java.util.Random; +import org.apache.commons.lang3.StringUtils; import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -36,9 +42,18 @@ public class TestSuite { throw new UnsupportedOperationException("Utility class"); } + public static int randomRating() { + return new Random().nextInt(10) + 1; + } + public static void test(ResultList result) { + assertNotNull("Null result list", result); + assertFalse("Empty result list", result.isEmpty()); + test(result.getResults()); + } + + public static void test(List result) { assertNotNull("Null results", result); - assertNotNull("Null collection", result.getResults()); assertFalse("Empty results", result.isEmpty()); } @@ -59,6 +74,38 @@ public class TestSuite { assertTrue("No first air date", isNotBlank(test.getFirstAirDate())); } + public static void test(TVInfo test) { + assertTrue("No ID", test.getId() > 0); + assertFalse("No runtime", test.getEpisodeRunTime().isEmpty()); + assertFalse("No genres", test.getGenres().isEmpty()); + assertTrue("No season count", test.getNumberOfSeasons() > 0); + assertTrue("No episode count", test.getNumberOfEpisodes() > 0); + } + + public static void test(TVEpisodeInfo test) { + assertTrue("No ID", test.getId() > 0); + assertTrue("No name", StringUtils.isNotBlank(test.getName())); + assertTrue("No crew", test.getCrew().size() > 0); + assertTrue("No guest stars", test.getGuestStars().size() > 0); + } + + public static void test(Person test) { + assertTrue("Missing bio", StringUtils.isNotBlank(test.getBiography())); + assertTrue("Missing birthday", StringUtils.isNotBlank(test.getBirthday())); + assertTrue("Missing homepage", StringUtils.isNotBlank(test.getHomepage())); + assertTrue("Missing name", StringUtils.isNotBlank(test.getName())); + assertTrue("Missing birth place", StringUtils.isNotBlank(test.getPlaceOfBirth())); + assertTrue("Missing artwork", StringUtils.isNotBlank(test.getProfilePath())); + assertTrue("Missing bio", test.getPopularity() > 0F); + } + + public static void test(TVSeasonInfo test) { + assertTrue("No ID", test.getId() > 0); + assertTrue("No name", StringUtils.isNotBlank(test.getName())); + assertTrue("No overview", StringUtils.isNotBlank(test.getOverview())); + assertTrue("No episodes", test.getEpisodes().size() > 0); + } + public static void testId(ResultList result, int id, String message) { testId(result.getResults(), id, message); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 7e90ccd60..98f4019bf 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -30,12 +30,10 @@ import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.tv.TVBasic; import com.omertron.themoviedbapi.results.ResultList; -import java.util.Random; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Before; @@ -97,8 +95,8 @@ public class TmdbAccountTest extends AbstractTests { public void testGetUserLists() throws MovieDbException { LOG.info("getUserLists"); ResultList results = instance.getUserLists(getSessionId(), getAccountId()); - assertNotNull("No list found", results); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); + for (UserList result : results.getResults()) { TestSuite.test(result); } @@ -113,7 +111,8 @@ public class TmdbAccountTest extends AbstractTests { public void testGetFavoriteMovies() throws MovieDbException { LOG.info("getFavoriteMovies"); ResultList results = instance.getFavoriteMovies(getSessionId(), getAccountId()); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); + for (MovieBasic result : results.getResults()) { TestSuite.test(result); } @@ -128,7 +127,8 @@ public class TmdbAccountTest extends AbstractTests { public void testGetFavoriteTv() throws MovieDbException { LOG.info("getFavoriteTv"); ResultList results = instance.getFavoriteTv(getSessionId(), getAccountId()); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); + for (TVBasic result : results.getResults()) { TestSuite.test(result); } @@ -173,7 +173,7 @@ public class TmdbAccountTest extends AbstractTests { public void testGetRatedMovies() throws MovieDbException { LOG.info("getRatedMovies"); ResultList results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); } /** @@ -185,7 +185,7 @@ public class TmdbAccountTest extends AbstractTests { public void testGetRatedTV() throws MovieDbException { LOG.info("getRatedTV"); ResultList results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); for (TVBasic result : results.getResults()) { TestSuite.test(result); } @@ -200,8 +200,7 @@ public class TmdbAccountTest extends AbstractTests { public void testGetWatchListMovie() throws MovieDbException { LOG.info("getWatchListMovie"); ResultList results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); - assertNotNull("No rated list found", results); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); for (MovieBasic result : results.getResults()) { TestSuite.test(result); } @@ -216,8 +215,7 @@ public class TmdbAccountTest extends AbstractTests { public void testGetWatchListTV() throws MovieDbException { LOG.info("getWatchListTV"); ResultList results = instance.getWatchListTV(getSessionId(), getAccountId(), null, null, null); - assertNotNull("No rated list found", results); - assertFalse("No entries found", results.isEmpty()); + TestSuite.test(results); for (TVBasic result : results.getResults()) { TestSuite.test(result); } @@ -286,12 +284,12 @@ public class TmdbAccountTest extends AbstractTests { result = instance.getGuestRatedMovies(guestSession, language, page, sortBy); } - assertFalse("No movies found!", result.isEmpty()); + TestSuite.test(result); } private void postGuestRating(String guestSessionId, int movieId) throws MovieDbException { TmdbMovies tmdbMovies = new TmdbMovies(getApiKey(), getHttpTools()); - Integer rating = new Random().nextInt(10) + 1; + int rating = TestSuite.randomRating(); LOG.info("Posting rating of '{}' to ID {} for guest session '{}'", rating, movieId, guestSessionId); StatusCode sc = tmdbMovies.postMovieRating(movieId, rating, null, guestSessionId); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java index 203743ad5..98ca8dd4f 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java @@ -21,11 +21,11 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.model.change.ChangeListItem; import com.omertron.themoviedbapi.results.ResultList; import com.omertron.themoviedbapi.tools.MethodBase; import org.junit.AfterClass; -import static org.junit.Assert.assertFalse; import org.junit.BeforeClass; import org.junit.Test; @@ -59,7 +59,7 @@ public class TmdbChangesTest extends AbstractTests { public void testGetMovieChangesList() throws MovieDbException { LOG.info("getMovieChangesList"); ResultList result = instance.getChangeList(MethodBase.MOVIE, null, null, null); - assertFalse("No Movie changes.", result.isEmpty()); + TestSuite.test(result); } /** @@ -71,7 +71,7 @@ public class TmdbChangesTest extends AbstractTests { public void testGetPersonChangesList() throws MovieDbException { LOG.info("getPersonChangesList"); ResultList result = instance.getChangeList(MethodBase.PERSON, null, null, null); - assertFalse("No Person changes.", result.isEmpty()); + TestSuite.test(result); } /** @@ -83,6 +83,6 @@ public class TmdbChangesTest extends AbstractTests { public void testGetTVChangesList() throws MovieDbException { LOG.info("getTVChangesList"); ResultList result = instance.getChangeList(MethodBase.TV, null, null, null); - assertFalse("No TV changes.", result.isEmpty()); + TestSuite.test(result); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java index 7c36e3d4f..78d5a8ccf 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java @@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.model.artwork.Artwork; import com.omertron.themoviedbapi.model.collection.CollectionInfo; import com.omertron.themoviedbapi.results.ResultList; @@ -73,7 +74,7 @@ public class TmdbCollectionsTest extends AbstractTests { public void testGetCollectionImages() throws MovieDbException { LOG.info("getCollectionImages"); ResultList result = instance.getCollectionImages(ID_COLLECTION_STAR_WARS, LANGUAGE_DEFAULT); - assertFalse("No artwork found", result.getResults().isEmpty()); + TestSuite.test(result); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java index aca000c3a..7c6765f2d 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java @@ -21,12 +21,12 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.model.company.Company; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.results.ResultList; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Before; @@ -85,6 +85,6 @@ public class TmdbCompaniesTest extends AbstractTests { public void testGetCompanyMovies() throws MovieDbException { LOG.info("getCompanyMovies"); ResultList result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); - assertFalse("No company movies found", result.isEmpty()); + TestSuite.test(result); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java index d523f10ab..c634294a1 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java @@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.model.config.Configuration; import com.omertron.themoviedbapi.model.config.JobDepartment; import com.omertron.themoviedbapi.results.ResultList; @@ -106,9 +107,7 @@ public class TmdbConfigurationTest extends AbstractTests { public void testGetJobs() throws MovieDbException { LOG.info("getJobs"); ResultList result = instance.getJobs(); - assertNotNull("Null results", result); - assertFalse("Empty results", result.getResults().isEmpty()); - assertTrue("No results", result.getResults().size() > 0); + TestSuite.test(result); } /** diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java index 9f99c0149..6c0511fde 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java @@ -21,13 +21,13 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.model.discover.Discover; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.tv.TVBasic; import com.omertron.themoviedbapi.results.ResultList; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.assertFalse; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -73,7 +73,7 @@ public class TmdbDiscoverTest extends AbstractTests { discover.year(2013).language(LANGUAGE_ENGLISH); ResultList result = instance.getDiscoverMovies(discover); - assertFalse("No movies discovered", result.isEmpty()); + TestSuite.test(result); } /** @@ -88,7 +88,7 @@ public class TmdbDiscoverTest extends AbstractTests { discover.year(2013).language(LANGUAGE_ENGLISH); ResultList result = instance.getDiscoverTV(discover); - assertFalse("No TV shows discovered", result.isEmpty()); + TestSuite.test(result); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbEpisodesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbEpisodesTest.java index 95925907b..c4dcc23c6 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbEpisodesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbEpisodesTest.java @@ -23,6 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.ArtworkResults; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.TestID; +import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.omertron.themoviedbapi.model.StatusCode; import com.omertron.themoviedbapi.model.artwork.Artwork; @@ -35,8 +36,6 @@ import com.omertron.themoviedbapi.model.tv.TVEpisodeInfo; import com.omertron.themoviedbapi.results.ResultList; import java.util.ArrayList; import java.util.List; -import java.util.Random; -import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; @@ -97,10 +96,7 @@ public class TmdbEpisodesTest extends AbstractTests { for (TestID test : TV_IDS) { TVEpisodeInfo result = instance.getEpisodeInfo(test.getTmdb(), seasonNumber, episodeNumber, language, appendToResponse); - assertTrue("No ID", result.getId() > 0); - assertTrue("No name", StringUtils.isNotBlank(result.getName())); - assertTrue("No crew", result.getCrew().size() > 0); - assertTrue("No guest stars", result.getGuestStars().size() > 0); + TestSuite.test(result); } } @@ -196,9 +192,8 @@ public class TmdbEpisodesTest extends AbstractTests { int seasonNumber = 1; int episodeNumber = 1; - ArtworkResults results = new ArtworkResults(); - for (TestID test : TV_IDS) { + ArtworkResults results = new ArtworkResults(); ResultList result = instance.getEpisodeImages(test.getTmdb(), seasonNumber, episodeNumber); assertFalse("No artwork", result.isEmpty()); for (Artwork artwork : result.getResults()) { @@ -225,7 +220,7 @@ public class TmdbEpisodesTest extends AbstractTests { String guestSessionID = null; for (TestID test : TV_IDS) { - Integer rating = new Random().nextInt(10) + 1; + int rating = TestSuite.randomRating(); StatusCode result = instance.postEpisodeRating(test.getTmdb(), seasonNumber, episodeNumber, rating, getSessionId(), guestSessionID); assertEquals("failed to post rating", 12, result.getCode()); } @@ -246,7 +241,7 @@ public class TmdbEpisodesTest extends AbstractTests { for (TestID test : TV_IDS) { ResultList