public abstract class BaseTestCase {

    private static final boolean LOG_BODY = System.getenv("CI") == null;

    // Do NOT use this API key in your application, it is only for testing tmdb-java!
    private static final String TEST_API_KEY = "25da90e9f8f0b3892d8bdeb6c3d6267d";
    // limit requests for tests to avoid hitting TMDb rate limit (40 requests/10 seconds)
    @SuppressWarnings("UnstableApiUsage") private static final RateLimiter rateLimiter = RateLimiter.create(5);

    private static final Tmdb unauthenticatedInstance = new BaseTestCase.TestTmdb(TEST_API_KEY);
    private static final Tmdb authenticatedInstance  = new BaseTestCase.TestTmdb(TEST_API_KEY);

    protected static Tmdb getUnauthenticatedInstance() {
        return unauthenticatedInstance;
    }

    protected static Tmdb getAuthenticatedInstance() {
        return authenticatedInstance;
    }

    private static class TestTmdb extends Tmdb {
        public TestTmdb(String apiKey) {
            super(apiKey);
        }

        @Override
        protected void setOkHttpClientDefaults(OkHttpClient.Builder builder) {
            final Tmdb instance = this;
            builder.authenticator(new TmdbAuthenticator(instance));
            builder.addInterceptor(chain -> {
                rateLimiter.acquire();
                return TmdbInterceptor.handleIntercept(chain, instance);
            });
            // add logging, standard output is easier to read
            // but only log headers on CI to keep logs short
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor(System.out::println);
            logging.setLevel(LOG_BODY ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.BASIC);
            builder.addNetworkInterceptor(logging);
        }
    }

} public class BasePerson {

    public String profile_path;
    public Boolean adult;
    public Integer id;
    public String name;
    public Double popularity;
    public List<Media> known_for;

} public class BaseTvSeason {

    public Date air_date;
    public Integer id;
    public String poster_path;
    public Integer season_number;
    public Integer episode_count;
    
} public class FindResults {

    public List<BaseMovie> movie_results;
    public List<BasePerson> person_results;
    public List<BaseTvShow> tv_results;
    public List<BaseTvSeason> tv_season_results;
    public List<BaseTvEpisode> tv_episode_results;

} public class TvEpisode extends BaseTvEpisode {

    public List<CrewMember> crew;

    public List<CastMember> guest_stars;


    public Images images;
    public TvEpisodeExternalIds external_ids;
    public Credits credits;
    public Videos videos;
    public Translations translations;

} public static final Movie testMovie = new Movie(); public static final Person testPerson = new Person(); public static final TvEpisode testTvEpisode = new TvEpisode(); public static final TvSeason testTvSeason = new TvSeason(); public static final TvShow testTvShow = new TvShow(); public static void assertBaseMovie(BaseMovie movie) {
    assertThat(movie).isNotNull();
    assertThat(movie.id).isNotNull();
    assertThat(movie.title).isNotNull();
    assertThat(movie.original_language).isNotEmpty();
    assertThat(movie.overview).isNotNull();
    assertThat(movie.adult).isNotNull();
    assertThat(movie.vote_average).isGreaterThanOrEqualTo(0);
    assertThat(movie.vote_count).isGreaterThanOrEqualTo(0);

    try {
        Movie _movie = (Movie) movie;
        assertThat(_movie.genres.get(0).id).isNotNull();
        assertThat(_movie.genres.get(0).name).isNotNull();
    } catch (Exception exc) {
        assertThat(movie.genre_ids).isNotNull();
    }
} public static void assertBasePerson(BasePerson person) {
    assertBasePerson(person, true);
} public static void assertBaseTvSeason(BaseTvSeason tvSeason) {
    assertThat(tvSeason).isNotNull();
    if (tvSeason.air_date != null) {
        assertThat(tvSeason.air_date).isNotEqualTo(new Date());
    }
    assertThat(tvSeason.id).isNotNull();
    assertThat(tvSeason.season_number).isNotNull();
    assertThat(tvSeason.season_number).isGreaterThanOrEqualTo(0);
} public static void assertBaseTvShow(BaseTvShow tvShow) {
    assertThat(tvShow).isNotNull();
    assertThat(tvShow.id).isNotNull();
    assertThat(tvShow.name).isNotNull();
    assertThat(tvShow.origin_country).isNotNull();
    assertThat(tvShow.original_language).isNotNull();
    assertThat(tvShow.original_name).isNotNull();
    assertThat(tvShow.vote_count).isNotNull();
    assertThat(tvShow.vote_count).isGreaterThanOrEqualTo(0);
    assertThat(tvShow.vote_average).isNotNull();
    assertThat(tvShow.vote_average).isGreaterThanOrEqualTo(0);
    if (tvShow.popularity != null) {
        assertThat(tvShow.popularity).isGreaterThanOrEqualTo(0);
    }

    try {
        TvShow _tvShow = (TvShow) tvShow;
        for (Genre genre : _tvShow.genres) {
            assertGenre(genre);
        }
    } catch (Exception exc) {
        assertThat(tvShow.genre_ids).isNotNull();
    }
}
import com.uwetrottmann.tmdb2.BaseTestCase;
import com.uwetrottmann.tmdb2.entities.BaseMovie;
import com.uwetrottmann.tmdb2.entities.BasePerson;
import com.uwetrottmann.tmdb2.entities.BaseTvEpisode;
import com.uwetrottmann.tmdb2.entities.BaseTvSeason;
import com.uwetrottmann.tmdb2.entities.BaseTvShow;
import com.uwetrottmann.tmdb2.entities.FindResults;
import com.uwetrottmann.tmdb2.entities.TvEpisode;
import com.uwetrottmann.tmdb2.enumerations.ExternalSource;
import org.junit.Test;
import retrofit2.Call;
import java.io.IOException;
import static com.uwetrottmann.tmdb2.TestData.testMovie;
import static com.uwetrottmann.tmdb2.TestData.testPerson;
import static com.uwetrottmann.tmdb2.TestData.testTvEpisode;
import static com.uwetrottmann.tmdb2.TestData.testTvSeason;
import static com.uwetrottmann.tmdb2.TestData.testTvShow;
import static com.uwetrottmann.tmdb2.assertions.MovieAssertions.assertBaseMovie;
import static com.uwetrottmann.tmdb2.assertions.PersonAssertions.assertBasePerson;
import static com.uwetrottmann.tmdb2.assertions.TvAssertions.assertBaseTvSeason;
import static com.uwetrottmann.tmdb2.assertions.TvAssertions.assertBaseTvShow;
import static org.assertj.core.api.Assertions.assertThat;
package com.uwetrottmann.tmdb2.services;




public class FindServiceTest extends BaseTestCase {

    @Test
    public void test_find_movie() throws IOException {
        Call<FindResults> call = getUnauthenticatedInstance().findService().find(
                testMovie.imdb_id,
                ExternalSource.IMDB_ID,
                null
        );

        FindResults results = call.execute().body();

        assertThat(results).isNotNull();

        assertThat(results.movie_results).isNotNull();
        assertThat(results.movie_results).isNotEmpty();
        for (BaseMovie movie : results.movie_results) {
            assertBaseMovie(movie);
            assertThat(movie.title).isEqualTo(testMovie.title);
        }
    }

    @Test
    public void test_find_people() throws IOException {
        Call<FindResults> call = getUnauthenticatedInstance().findService().find(
                testPerson.imdb_id,
                ExternalSource.IMDB_ID,
                null
        );

        FindResults results = call.execute().body();

        assertThat(results).isNotNull();

        assertThat(results.person_results).isNotNull();
        assertThat(results.person_results).isNotEmpty();
        for (BasePerson person : results.person_results) {
            assertBasePerson(person);
            assertThat(person.name).isEqualTo(testPerson.name);
        }

    }

    @Test
    public void test_find_tv_show() throws IOException {
        Call<FindResults> call = getUnauthenticatedInstance().findService().find(
                testTvShow.external_ids.imdb_id,