diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/ApolloWatcherTest.java b/apollo-integration/src/test/java/com/apollographql/apollo/ApolloWatcherTest.java index c5937ce38ac..1bbfa10fc1b 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/ApolloWatcherTest.java +++ b/apollo-integration/src/test/java/com/apollographql/apollo/ApolloWatcherTest.java @@ -127,7 +127,7 @@ public void testQueryWatcherUpdated_Store_write() throws IOException, Interrupte assertThat(heroNameList.get(0)).isEqualTo("R2-D2"); // Someone writes to the store directly - Set changedKeys = apolloClient.apolloStore().writeTransaction(new Transaction>() { + Set changedKeys = apolloClient.getApolloStore().writeTransaction(new Transaction>() { @Nullable @Override public Set execute(WriteableStore cache) { Record record = Record.builder("2001") .addField("name", "Artoo") @@ -135,7 +135,7 @@ public void testQueryWatcherUpdated_Store_write() throws IOException, Interrupte return cache.merge(Collections.singletonList(record), CacheHeaders.NONE); } }); - apolloClient.apolloStore().publish(changedKeys); + apolloClient.getApolloStore().publish(changedKeys); assertThat(heroNameList.get(1)).isEqualTo("Artoo"); diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/IdFieldCacheKeyResolver.java b/apollo-integration/src/test/java/com/apollographql/apollo/IdFieldCacheKeyResolver.java index 08c626ad9a4..939a11ae698 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/IdFieldCacheKeyResolver.java +++ b/apollo-integration/src/test/java/com/apollographql/apollo/IdFieldCacheKeyResolver.java @@ -4,12 +4,12 @@ import com.apollographql.apollo.api.ResponseField; import com.apollographql.apollo.cache.normalized.CacheKey; import com.apollographql.apollo.cache.normalized.CacheKeyResolver; +import org.jetbrains.annotations.NotNull; import java.util.Map; -import org.jetbrains.annotations.NotNull; - public class IdFieldCacheKeyResolver extends CacheKeyResolver { + @NotNull @Override public CacheKey fromFieldRecordSet(@NotNull ResponseField field, @NotNull Map recordSet) { Object id = recordSet.get("id"); @@ -34,7 +34,7 @@ private CacheKey formatCacheKey(String id) { if (id == null || id.isEmpty()) { return CacheKey.NO_KEY; } else { - return CacheKey.from(id); + return new CacheKey(id); } } } diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/NormalizedCacheTestCase.java b/apollo-integration/src/test/java/com/apollographql/apollo/NormalizedCacheTestCase.java index f04cb463f7d..040275e7606 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/NormalizedCacheTestCase.java +++ b/apollo-integration/src/test/java/com/apollographql/apollo/NormalizedCacheTestCase.java @@ -404,7 +404,7 @@ public boolean test(Response response) } ); - HeroWithFriendsFragment heroWithFriendsFragment = apolloClient.apolloStore().read( + HeroWithFriendsFragment heroWithFriendsFragment = apolloClient.getApolloStore().read( new HeroWithFriendsFragment.Mapper(), CacheKey.from("2001"), Operation.EMPTY_VARIABLES).execute(); assertThat(heroWithFriendsFragment.id()).isEqualTo("2001"); @@ -417,17 +417,17 @@ public boolean test(Response response) assertThat(heroWithFriendsFragment.friends().get(2).fragments().humanWithIdFragment().id()).isEqualTo("1003"); assertThat(heroWithFriendsFragment.friends().get(2).fragments().humanWithIdFragment().name()).isEqualTo("Leia Organa"); - HumanWithIdFragment fragment = apolloClient.apolloStore().read(new HumanWithIdFragment.Mapper(), + HumanWithIdFragment fragment = apolloClient.getApolloStore().read(new HumanWithIdFragment.Mapper(), CacheKey.from("1000"), Operation.EMPTY_VARIABLES).execute(); assertThat(fragment.id()).isEqualTo("1000"); assertThat(fragment.name()).isEqualTo("Luke Skywalker"); - fragment = apolloClient.apolloStore().read(new HumanWithIdFragment.Mapper(), CacheKey.from("1002"), + fragment = apolloClient.getApolloStore().read(new HumanWithIdFragment.Mapper(), CacheKey.from("1002"), Operation.EMPTY_VARIABLES).execute(); assertThat(fragment.id()).isEqualTo("1002"); assertThat(fragment.name()).isEqualTo("Han Solo"); - fragment = apolloClient.apolloStore().read(new HumanWithIdFragment.Mapper(), CacheKey.from("1003"), + fragment = apolloClient.getApolloStore().read(new HumanWithIdFragment.Mapper(), CacheKey.from("1003"), Operation.EMPTY_VARIABLES).execute(); assertThat(fragment.id()).isEqualTo("1003"); assertThat(fragment.name()).isEqualTo("Leia Organa"); @@ -510,7 +510,7 @@ public boolean test(Response response) ); // test remove root query object - assertThat(apolloClient.apolloStore().remove(CacheKey.from("2001")).execute()).isTrue(); + assertThat(apolloClient.getApolloStore().remove(CacheKey.from("2001")).execute()).isTrue(); Utils.INSTANCE.assertResponse( apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))) @@ -546,7 +546,7 @@ public boolean test(Response response) ); // test remove object from the list - assertThat(apolloClient.apolloStore().remove(CacheKey.from("1002")).execute()).isTrue(); + assertThat(apolloClient.getApolloStore().remove(CacheKey.from("1002")).execute()).isTrue(); Utils.INSTANCE.assertResponse( apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))) @@ -630,7 +630,7 @@ public boolean test(Response response) } ); - assertThat(apolloClient.apolloStore().remove(asList(CacheKey.from("1002"), CacheKey.from("1000"))) + assertThat(apolloClient.getApolloStore().remove(asList(CacheKey.from("1002"), CacheKey.from("1000"))) .execute()).isEqualTo(2); Utils.INSTANCE.assertResponse( @@ -797,7 +797,7 @@ public boolean test(Response response) } ); - Map> dump = apolloClient.apolloStore().normalizedCache().dump(); + Map> dump = apolloClient.getApolloStore().normalizedCache().dump(); assertThat(NormalizedCache.prettifyDump(dump)).isEqualTo("OptimisticNormalizedCache {}\n" + "LruNormalizedCache {\n" + " \"1002\" : {\n" + @@ -883,7 +883,7 @@ public boolean test(Response response) ); // test remove root query object - assertThat(apolloClient.apolloStore().remove(CacheKey.from("2001"), true).execute()).isTrue(); + assertThat(apolloClient.getApolloStore().remove(CacheKey.from("2001"), true).execute()).isTrue(); Utils.INSTANCE.assertResponse( apolloClient.query(new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(Episode.NEWHOPE))) @@ -929,7 +929,7 @@ public boolean test(Response response) } ); - assertThat(NormalizedCache.prettifyDump(apolloClient.apolloStore().normalizedCache().dump())).isEqualTo("" + + assertThat(NormalizedCache.prettifyDump(apolloClient.getApolloStore().normalizedCache().dump())).isEqualTo("" + "OptimisticNormalizedCache {}\n" + "LruNormalizedCache {\n" + " \"QUERY_ROOT\" : {\n" + diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/OptimisticCacheTestCase.java b/apollo-integration/src/test/java/com/apollographql/apollo/OptimisticCacheTestCase.java index 861384a8133..a2a92539a37 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/OptimisticCacheTestCase.java +++ b/apollo-integration/src/test/java/com/apollographql/apollo/OptimisticCacheTestCase.java @@ -16,7 +16,12 @@ import com.apollographql.apollo.integration.normalizer.type.ColorInput; import com.apollographql.apollo.integration.normalizer.type.Episode; import com.apollographql.apollo.integration.normalizer.type.ReviewInput; - +import io.reactivex.functions.Predicate; +import okhttp3.Dispatcher; +import okhttp3.OkHttpClient; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -27,14 +32,6 @@ import java.util.List; import java.util.UUID; -import org.jetbrains.annotations.NotNull; - -import io.reactivex.functions.Predicate; -import okhttp3.Dispatcher; -import okhttp3.OkHttpClient; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; - import static com.apollographql.apollo.fetcher.ApolloResponseFetchers.CACHE_ONLY; import static com.google.common.truth.Truth.assertThat; @@ -88,7 +85,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ) ) )); - apolloClient.apolloStore().writeOptimisticUpdatesAndPublish(query, data, mutationId).execute(); + apolloClient.getApolloStore().writeOptimisticUpdatesAndPublish(query, data, mutationId).execute(); Utils.INSTANCE.assertResponse( apolloClient.query(query).responseFetcher(CACHE_ONLY), @@ -103,7 +100,7 @@ private MockResponse mockResponse(String fileName) throws IOException { } ); - apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId).execute(); + apolloClient.getApolloStore().rollbackOptimisticUpdates(mutationId).execute(); Utils.INSTANCE.assertResponse( apolloClient.query(query).responseFetcher(CACHE_ONLY), @@ -157,7 +154,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ) ) ); - apolloClient.apolloStore().writeOptimisticUpdatesAndPublish(query1, data1, mutationId1).execute(); + apolloClient.getApolloStore().writeOptimisticUpdatesAndPublish(query1, data1, mutationId1).execute(); // check if query1 see optimistic updates Utils.INSTANCE.assertResponse( @@ -192,7 +189,7 @@ private MockResponse mockResponse(String fileName) throws IOException { "1000", "Beast" )); - apolloClient.apolloStore().writeOptimisticUpdatesAndPublish(query2, data2, mutationId2).execute(); + apolloClient.getApolloStore().writeOptimisticUpdatesAndPublish(query2, data2, mutationId2).execute(); // check if query1 see the latest optimistic updates Utils.INSTANCE.assertResponse( @@ -224,7 +221,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ); // rollback query1 optimistic updates - apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId1).execute(); + apolloClient.getApolloStore().rollbackOptimisticUpdates(mutationId1).execute(); // check if query1 see the latest optimistic updates Utils.INSTANCE.assertResponse( @@ -258,7 +255,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ); // rollback query2 optimistic updates - apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId2).execute(); + apolloClient.getApolloStore().rollbackOptimisticUpdates(mutationId2).execute(); // check if query2 see the latest optimistic updates Utils.INSTANCE.assertResponse( @@ -286,7 +283,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ); UUID mutationId = UUID.randomUUID(); - apolloClient.apolloStore().writeOptimisticUpdates( + apolloClient.getApolloStore().writeOptimisticUpdates( new HeroNameQuery(), new HeroNameQuery.Data(new HeroNameQuery.Hero("Droid", "R22-D22")), mutationId @@ -304,7 +301,7 @@ private MockResponse mockResponse(String fileName) throws IOException { } ); - apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId).execute(); + apolloClient.getApolloStore().rollbackOptimisticUpdates(mutationId).execute(); Utils.INSTANCE.assertResponse( apolloClient.query(new HeroNameWithEnumsQuery()).responseFetcher(CACHE_ONLY), @@ -441,14 +438,14 @@ private MockResponse mockResponse(String fileName) throws IOException { ) ) ); - apolloClient.apolloStore().writeOptimisticUpdatesAndPublish(query1, data1, mutationId1).execute(); + apolloClient.getApolloStore().writeOptimisticUpdatesAndPublish(query1, data1, mutationId1).execute(); HeroNameWithIdQuery.Data data2 = new HeroNameWithIdQuery.Data(new HeroNameWithIdQuery.Hero( "Human", "1000", "Spiderman" )); - apolloClient.apolloStore().writeOptimisticUpdatesAndPublish(query2, data2, mutationId2).execute(); + apolloClient.getApolloStore().writeOptimisticUpdatesAndPublish(query2, data2, mutationId2).execute(); // check if query1 see optimistic updates Utils.INSTANCE.assertResponse( @@ -480,7 +477,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ); // rollback query2 optimistic updates - apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId2).execute(); + apolloClient.getApolloStore().rollbackOptimisticUpdates(mutationId2).execute(); // check if query1 see the latest optimistic updates Utils.INSTANCE.assertResponse( @@ -512,7 +509,7 @@ private MockResponse mockResponse(String fileName) throws IOException { ); // rollback query1 optimistic updates - apolloClient.apolloStore().rollbackOptimisticUpdates(mutationId1).execute(); + apolloClient.getApolloStore().rollbackOptimisticUpdates(mutationId1).execute(); // check if query1 see the latest non-optimistic updates Utils.INSTANCE.assertResponse( diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/ResponseNormalizationTest.java b/apollo-integration/src/test/java/com/apollographql/apollo/ResponseNormalizationTest.java index f13fdb463e3..6e296f81d30 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/ResponseNormalizationTest.java +++ b/apollo-integration/src/test/java/com/apollographql/apollo/ResponseNormalizationTest.java @@ -20,7 +20,10 @@ import com.apollographql.apollo.integration.normalizer.HeroParentTypeDependentFieldQuery; import com.apollographql.apollo.integration.normalizer.HeroTypeDependentAliasedFieldQuery; import com.apollographql.apollo.integration.normalizer.SameHeroTwiceQuery; - +import io.reactivex.functions.Predicate; +import okhttp3.Dispatcher; +import okhttp3.OkHttpClient; +import okhttp3.mockwebserver.MockWebServer; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -30,11 +33,6 @@ import java.util.Collections; import java.util.List; -import io.reactivex.functions.Predicate; -import okhttp3.Dispatcher; -import okhttp3.OkHttpClient; -import okhttp3.mockwebserver.MockWebServer; - import static com.apollographql.apollo.integration.normalizer.type.Episode.EMPIRE; import static com.apollographql.apollo.integration.normalizer.type.Episode.JEDI; import static com.google.common.truth.Truth.assertThat; @@ -59,7 +57,7 @@ public class ResponseNormalizationTest { .normalizedCache(new LruNormalizedCacheFactory(EvictionPolicy.NO_EVICTION), new IdFieldCacheKeyResolver()) .dispatcher(Utils.INSTANCE.immediateExecutor()) .build(); - normalizedCache = apolloClient.apolloStore().normalizedCache(); + normalizedCache = apolloClient.getApolloStore().normalizedCache(); } @Test public void testHeroName() throws Exception { diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/ResponseWriteTestCase.java b/apollo-integration/src/test/java/com/apollographql/apollo/ResponseWriteTestCase.java index bfa24036daa..827b8244ec3 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/ResponseWriteTestCase.java +++ b/apollo-integration/src/test/java/com/apollographql/apollo/ResponseWriteTestCase.java @@ -98,7 +98,7 @@ public void customType() throws Exception { DATE_TIME_FORMAT.parse("1985-04-16"), Collections.emptyList() ); - apolloClient.apolloStore().write(query, new EpisodeHeroWithDatesQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new EpisodeHeroWithDatesQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -122,7 +122,7 @@ public void customType() throws Exception { DATE_TIME_FORMAT.parse("2017-05-16") ) ); - apolloClient.apolloStore().write(query, new EpisodeHeroWithDatesQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new EpisodeHeroWithDatesQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -168,7 +168,7 @@ public void enums() throws Exception { Episode.JEDI, Collections.emptyList() ); - apolloClient.apolloStore().write(query, new HeroNameWithEnumsQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new HeroNameWithEnumsQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -189,7 +189,7 @@ public void enums() throws Exception { Episode.JEDI, asList(Episode.EMPIRE) ); - apolloClient.apolloStore().write(query, new HeroNameWithEnumsQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new HeroNameWithEnumsQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -240,7 +240,7 @@ public void objects() throws Exception { "R222-D222", null ); - apolloClient.apolloStore().write(query, new HeroAndFriendsNamesWithIDsQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new HeroAndFriendsNamesWithIDsQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -266,7 +266,7 @@ public void objects() throws Exception { "R222-D222", singletonList(friend) ); - apolloClient.apolloStore().write(query, new HeroAndFriendsNamesWithIDsQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new HeroAndFriendsNamesWithIDsQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -346,7 +346,7 @@ public void operation_with_fragments() throws Exception { ) ) ); - apolloClient.apolloStore().write(query, new HeroAndFriendsWithFragmentsQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new HeroAndFriendsWithFragmentsQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -422,7 +422,7 @@ public boolean test(Response response) ) ) ); - apolloClient.apolloStore().write(query, new EpisodeHeroWithInlineFragmentQuery.Data(hero)).execute(); + apolloClient.getApolloStore().write(query, new EpisodeHeroWithInlineFragmentQuery.Data(hero)).execute(); assertCachedQueryResponse( query, @@ -477,7 +477,7 @@ public void fragments() throws Exception { } ); - apolloClient.apolloStore().write( + apolloClient.getApolloStore().write( new HeroWithFriendsFragment( "Droid", "2001", @@ -507,7 +507,7 @@ public void fragments() throws Exception { ), CacheKey.from("2001"), query.variables() ).execute(); - apolloClient.apolloStore().write( + apolloClient.getApolloStore().write( new HumanWithIdFragment( "Human", "1002", @@ -561,7 +561,7 @@ public void fragments() throws Exception { "SuperRocket", asList(asList(900d, 800d), asList(700d, 600d)) ); - apolloClient.apolloStore().write(query, new StarshipByIdQuery.Data(starship)).execute(); + apolloClient.getApolloStore().write(query, new StarshipByIdQuery.Data(starship)).execute(); assertCachedQueryResponse( query, diff --git a/apollo-integration/src/test/java/com/apollographql/apollo/internal/subscription/SubscriptionNormalizedCacheTest.kt b/apollo-integration/src/test/java/com/apollographql/apollo/internal/subscription/SubscriptionNormalizedCacheTest.kt index 1c1c0e88a7e..e7ff6694fdb 100644 --- a/apollo-integration/src/test/java/com/apollographql/apollo/internal/subscription/SubscriptionNormalizedCacheTest.kt +++ b/apollo-integration/src/test/java/com/apollographql/apollo/internal/subscription/SubscriptionNormalizedCacheTest.kt @@ -70,7 +70,7 @@ class SubscriptionNormalizedCacheTest { expectedContent = "Network comment content" ) - val cacheDump = apolloClient.apolloStore().normalizedCache().dump() + val cacheDump = apolloClient.apolloStore.normalizedCache().dump() assertThat(NormalizedCache.prettifyDump(cacheDump)).isEqualTo(""" OptimisticNormalizedCache {} LruNormalizedCache {} @@ -86,7 +86,7 @@ class SubscriptionNormalizedCacheTest { "Comment", 100, "Cached comment content", NewRepoCommentSubscription.PostedBy("User", "user@user.com") ) ) - apolloClient.apolloStore().write(operation, data).execute() + apolloClient.apolloStore.write(operation, data).execute() val callback = SubscriptionManagerCallbackAdapter() subscriptionCall.cachePolicy(ApolloSubscriptionCall.CachePolicy.NETWORK_ONLY).execute(callback) @@ -106,7 +106,7 @@ class SubscriptionNormalizedCacheTest { expectedContent = "Network comment content" ) - val cacheDump = apolloClient.apolloStore().normalizedCache().dump() + val cacheDump = apolloClient.apolloStore.normalizedCache().dump() assertThat(NormalizedCache.prettifyDump(cacheDump)).isEqualTo(""" OptimisticNormalizedCache {} LruNormalizedCache { @@ -138,7 +138,7 @@ class SubscriptionNormalizedCacheTest { "Comment", 100, "Cached comment content", NewRepoCommentSubscription.PostedBy("User", "user@user.com") ) ) - apolloClient.apolloStore().write(operation, data).execute() + apolloClient.apolloStore.write(operation, data).execute() val callback = SubscriptionManagerCallbackAdapter() subscriptionCall.cachePolicy(ApolloSubscriptionCall.CachePolicy.CACHE_AND_NETWORK).execute(callback) @@ -161,7 +161,7 @@ class SubscriptionNormalizedCacheTest { expectedContent = "Network comment content" ) - val cacheDump = apolloClient.apolloStore().normalizedCache().dump() + val cacheDump = apolloClient.apolloStore.normalizedCache().dump() assertThat(NormalizedCache.prettifyDump(cacheDump)).isEqualTo(""" OptimisticNormalizedCache {} LruNormalizedCache { diff --git a/apollo-normalized-cache/src/main/java/com/apollographql/apollo/cache/normalized/CacheKeyResolver.kt b/apollo-normalized-cache/src/main/java/com/apollographql/apollo/cache/normalized/CacheKeyResolver.kt index 8719f4d0549..01e1c32f59c 100644 --- a/apollo-normalized-cache/src/main/java/com/apollographql/apollo/cache/normalized/CacheKeyResolver.kt +++ b/apollo-normalized-cache/src/main/java/com/apollographql/apollo/cache/normalized/CacheKeyResolver.kt @@ -9,7 +9,7 @@ import com.apollographql.apollo.api.ResponseField abstract class CacheKeyResolver { abstract fun fromFieldRecordSet( field: ResponseField, - recordSet: Map + recordSet: @JvmSuppressWildcards Map ): CacheKey abstract fun fromFieldArguments(