use of com.apollographql.apollo.integration.normalizer.EpisodeHeroWithDatesQuery in project apollo-android by apollographql.
the class ResponseWriteTestCase method customType.
@Test
public void customType() throws Exception {
EpisodeHeroWithDatesQuery query = new EpisodeHeroWithDatesQuery(Input.fromNullable(JEDI));
enqueueAndAssertResponse(server, "EpisodeHeroWithDatesResponse.json", apolloClient.query(query), new Predicate<Response<EpisodeHeroWithDatesQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroWithDatesQuery.Data> response) throws Exception {
assertThat(response.data().hero().__typename()).isEqualTo("Droid");
assertThat(response.data().hero().heroName()).isEqualTo("R2-D2");
assertThat(DATE_TIME_FORMAT.format(response.data().hero().birthDate())).isEqualTo("1984-04-16");
assertThat(response.data().hero().showUpDates()).hasSize(3);
assertThat(DATE_TIME_FORMAT.format(response.data().hero().showUpDates().get(0))).isEqualTo("2017-01-16");
assertThat(DATE_TIME_FORMAT.format(response.data().hero().showUpDates().get(1))).isEqualTo("2017-02-16");
assertThat(DATE_TIME_FORMAT.format(response.data().hero().showUpDates().get(2))).isEqualTo("2017-03-16");
return true;
}
});
EpisodeHeroWithDatesQuery.Hero hero = new EpisodeHeroWithDatesQuery.Hero("Droid", "R222-D222", DATE_TIME_FORMAT.parse("1985-04-16"), Collections.<Date>emptyList());
apolloClient.apolloStore().write(query, new EpisodeHeroWithDatesQuery.Data(hero)).execute();
assertCachedQueryResponse(query, new Predicate<Response<EpisodeHeroWithDatesQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroWithDatesQuery.Data> response) throws Exception {
assertThat(response.data().hero().__typename()).isEqualTo("Droid");
assertThat(response.data().hero().heroName()).isEqualTo("R222-D222");
assertThat(DATE_TIME_FORMAT.format(response.data().hero().birthDate())).isEqualTo("1985-04-16");
assertThat(response.data().hero().showUpDates()).hasSize(0);
return true;
}
});
hero = new EpisodeHeroWithDatesQuery.Hero(hero.__typename(), "R22-D22", DATE_TIME_FORMAT.parse("1986-04-16"), asList(DATE_TIME_FORMAT.parse("2017-04-16"), DATE_TIME_FORMAT.parse("2017-05-16")));
apolloClient.apolloStore().write(query, new EpisodeHeroWithDatesQuery.Data(hero)).execute();
assertCachedQueryResponse(query, new Predicate<Response<EpisodeHeroWithDatesQuery.Data>>() {
@Override
public boolean test(Response<EpisodeHeroWithDatesQuery.Data> response) throws Exception {
assertThat(response.data().hero().__typename()).isEqualTo("Droid");
assertThat(response.data().hero().heroName()).isEqualTo("R22-D22");
assertThat(DATE_TIME_FORMAT.format(response.data().hero().birthDate())).isEqualTo("1986-04-16");
assertThat(response.data().hero().showUpDates()).hasSize(2);
assertThat(DATE_TIME_FORMAT.format(response.data().hero().showUpDates().get(0))).isEqualTo("2017-04-16");
assertThat(DATE_TIME_FORMAT.format(response.data().hero().showUpDates().get(1))).isEqualTo("2017-05-16");
return true;
}
});
}
Aggregations