Fix tests
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2015 Stuart Boston
|
||||
*
|
||||
* This file is part of TheMovieDB API.
|
||||
*
|
||||
* TheMovieDB API is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* TheMovieDB API is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.omertron.themoviedbapi;
|
||||
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ArtworkResults {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ArtworkResults.class);
|
||||
private final Map<ArtworkType, Boolean> results;
|
||||
|
||||
public ArtworkResults() {
|
||||
results = new EnumMap<ArtworkType, Boolean>(ArtworkType.class);
|
||||
for (ArtworkType at : ArtworkType.values()) {
|
||||
results.put(at, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void found(ArtworkType artworkType) {
|
||||
results.put(artworkType, Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void validateResults(ArtworkType expectedType) {
|
||||
validateResults(new ArtworkType[]{expectedType});
|
||||
}
|
||||
|
||||
public void validateResults(ArtworkType expectedType1, ArtworkType expectedType2) {
|
||||
validateResults(new ArtworkType[]{expectedType1, expectedType2});
|
||||
}
|
||||
|
||||
public void validateResults(ArtworkType[] expectedTypes) {
|
||||
LOG.trace("Results: {}", results);
|
||||
for (ArtworkType artworkType : expectedTypes) {
|
||||
assertTrue("No " + artworkType.name() + " found", results.get(artworkType));
|
||||
results.remove(artworkType);
|
||||
}
|
||||
|
||||
for (Map.Entry<ArtworkType, Boolean> entry : results.entrySet()) {
|
||||
assertFalse(entry.getKey() + " was also found", entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ package com.omertron.themoviedbapi.methods;
|
||||
import com.omertron.themoviedbapi.AbstractTests;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
|
||||
import com.omertron.themoviedbapi.ArtworkResults;
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.TestID;
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
@@ -194,26 +195,17 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
String[] appendToResponse = null;
|
||||
|
||||
boolean foundBackdrop = false;
|
||||
boolean foundPoster = false;
|
||||
boolean foundOther = false;
|
||||
ArtworkResults results = new ArtworkResults();
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<Artwork> result = instance.getMovieImages(test.getTmdb(), language, appendToResponse);
|
||||
assertFalse("No artwork", result.isEmpty());
|
||||
for (Artwork artwork : result.getResults()) {
|
||||
if (artwork.getArtworkType() == ArtworkType.BACKDROP) {
|
||||
foundBackdrop = true;
|
||||
continue;
|
||||
} else if (artwork.getArtworkType() == ArtworkType.POSTER) {
|
||||
foundPoster = true;
|
||||
continue;
|
||||
}
|
||||
foundOther = true;
|
||||
results.found(artwork.getArtworkType());
|
||||
}
|
||||
assertTrue("No backdrops", foundBackdrop);
|
||||
assertTrue("No posters", foundPoster);
|
||||
assertFalse("Something else found!", foundOther);
|
||||
|
||||
// We should only have posters & backdrops
|
||||
results.validateResults(ArtworkType.POSTER, ArtworkType.BACKDROP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,11 +255,13 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
String[] appendToResponse = null;
|
||||
boolean found = false;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<Video> result = instance.getMovieVideos(test.getTmdb(), language, appendToResponse);
|
||||
assertFalse("No videos", result.isEmpty());
|
||||
found = found || !result.isEmpty();
|
||||
}
|
||||
assertTrue("No videos", found);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.omertron.themoviedbapi.methods;
|
||||
import com.omertron.themoviedbapi.AbstractTests;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
|
||||
import com.omertron.themoviedbapi.ArtworkResults;
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.TestID;
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
@@ -197,21 +198,17 @@ public class TmdbTVEpisodesTest extends AbstractTests {
|
||||
int seasonNumber = 1;
|
||||
int episodeNumber = 1;
|
||||
|
||||
boolean foundStill = false;
|
||||
boolean foundOther = false;
|
||||
ArtworkResults results = new ArtworkResults();
|
||||
|
||||
for (TestID test : TV_IDS) {
|
||||
TmdbResultsList<Artwork> result = instance.getEpisodeImages(test.getTmdb(), seasonNumber, episodeNumber);
|
||||
assertFalse("No artwork", result.isEmpty());
|
||||
for (Artwork artwork : result.getResults()) {
|
||||
if (artwork.getArtworkType() == ArtworkType.STILL) {
|
||||
foundStill = true;
|
||||
continue;
|
||||
}
|
||||
foundOther = true;
|
||||
results.found(artwork.getArtworkType());
|
||||
}
|
||||
assertTrue("No stills", foundStill);
|
||||
assertFalse("Something else found!", foundOther);
|
||||
|
||||
// We should only have posters & backdrops
|
||||
results.validateResults(ArtworkType.STILL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.doConfiguration;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
|
||||
import com.omertron.themoviedbapi.ArtworkResults;
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.TestID;
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
@@ -191,26 +192,17 @@ public class TmdbTVSeasonsTest extends AbstractTests {
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
String[] includeImageLanguage = null;
|
||||
|
||||
boolean foundBackdrop = false;
|
||||
boolean foundPoster = false;
|
||||
boolean foundOther = false;
|
||||
ArtworkResults results = new ArtworkResults();
|
||||
|
||||
for (TestID test : TV_IDS) {
|
||||
TmdbResultsList<Artwork> result = instance.getSeasonImages(test.getTmdb(), seasonNumber, language, includeImageLanguage);
|
||||
assertFalse("No artwork", result.isEmpty());
|
||||
for (Artwork artwork : result.getResults()) {
|
||||
if (artwork.getArtworkType() == ArtworkType.BACKDROP) {
|
||||
foundBackdrop = true;
|
||||
continue;
|
||||
} else if (artwork.getArtworkType() == ArtworkType.POSTER) {
|
||||
foundPoster = true;
|
||||
continue;
|
||||
}
|
||||
foundOther = true;
|
||||
results.found(artwork.getArtworkType());
|
||||
}
|
||||
assertTrue("No backdrops", foundBackdrop);
|
||||
assertTrue("No posters", foundPoster);
|
||||
assertFalse("Something else found!", foundOther);
|
||||
|
||||
// We should only have posters
|
||||
results.validateResults(ArtworkType.POSTER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,11 +217,14 @@ public class TmdbTVSeasonsTest extends AbstractTests {
|
||||
|
||||
int seasonNumber = 0;
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
boolean found = false;
|
||||
|
||||
for (TestID test : TV_IDS) {
|
||||
TmdbResultsList<Video> result = instance.getSeasonVideos(test.getTmdb(), seasonNumber, language);
|
||||
assertFalse("No videos", result.isEmpty());
|
||||
found = found || !result.isEmpty();
|
||||
}
|
||||
|
||||
assertTrue("No videos", found);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.omertron.themoviedbapi.methods;
|
||||
import com.omertron.themoviedbapi.AbstractTests;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
|
||||
import com.omertron.themoviedbapi.ArtworkResults;
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.TestID;
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
@@ -77,7 +78,7 @@ public class TmdbTVTest extends AbstractTests {
|
||||
|
||||
TV_IDS.add(new TestID("The Walking Dead", "tt1520211", 1402, "Andrew Lincoln"));
|
||||
TV_IDS.add(new TestID("Supernatural", "tt0460681", 1622, "Misha Collins"));
|
||||
TV_IDS.add(new TestID("The Big Bang Theory", "tt0898266", 1418,"Kaley Cuoco"));
|
||||
TV_IDS.add(new TestID("The Big Bang Theory", "tt0898266", 1418, "Kaley Cuoco"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,26 +239,17 @@ public class TmdbTVTest extends AbstractTests {
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
String[] includeImageLanguage = null;
|
||||
|
||||
boolean foundBackdrop = false;
|
||||
boolean foundPoster = false;
|
||||
boolean foundOther = false;
|
||||
ArtworkResults results = new ArtworkResults();
|
||||
|
||||
for (TestID test : TV_IDS) {
|
||||
TmdbResultsList<Artwork> result = instance.getTVImages(test.getTmdb(), language, includeImageLanguage);
|
||||
assertFalse("No artwork", result.isEmpty());
|
||||
for (Artwork artwork : result.getResults()) {
|
||||
if (artwork.getArtworkType() == ArtworkType.BACKDROP) {
|
||||
foundBackdrop = true;
|
||||
continue;
|
||||
} else if (artwork.getArtworkType() == ArtworkType.POSTER) {
|
||||
foundPoster = true;
|
||||
continue;
|
||||
}
|
||||
foundOther = true;
|
||||
results.found(artwork.getArtworkType());
|
||||
}
|
||||
assertTrue("No backdrops", foundBackdrop);
|
||||
assertTrue("No posters", foundPoster);
|
||||
assertFalse("Something else found!", foundOther);
|
||||
|
||||
// We should only have posters & backdrops
|
||||
results.validateResults(ArtworkType.POSTER, ArtworkType.BACKDROP);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -339,11 +331,13 @@ public class TmdbTVTest extends AbstractTests {
|
||||
LOG.info("getTVVideos");
|
||||
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
boolean found = false;
|
||||
|
||||
for (TestID test : TV_IDS) {
|
||||
TmdbResultsList<Video> result = instance.getTVVideos(test.getTmdb(), language);
|
||||
assertFalse("No videos", result.isEmpty());
|
||||
found = found || !result.isEmpty();
|
||||
}
|
||||
assertTrue("No videos", found);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user