From 1af4e39815cf3be5df3bb2fdd2c85ffee3c103fc Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Thu, 5 Mar 2015 19:38:00 +0000 Subject: [PATCH] Fix tests --- .../themoviedbapi/ArtworkResults.java | 66 +++++++++++++++++++ .../themoviedbapi/methods/TmdbMoviesTest.java | 24 +++---- .../methods/TmdbTVEpisodesTest.java | 15 ++--- .../methods/TmdbTVSeasonsTest.java | 25 +++---- .../themoviedbapi/methods/TmdbTVTest.java | 26 +++----- 5 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 src/test/java/com/omertron/themoviedbapi/ArtworkResults.java diff --git a/src/test/java/com/omertron/themoviedbapi/ArtworkResults.java b/src/test/java/com/omertron/themoviedbapi/ArtworkResults.java new file mode 100644 index 000000000..44326d7cb --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/ArtworkResults.java @@ -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 . + * + */ +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 results; + + public ArtworkResults() { + results = new EnumMap(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 entry : results.entrySet()) { + assertFalse(entry.getKey() + " was also found", entry.getValue()); + } + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index 378bccfe9..737f4baa8 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -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 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