Skip to content

Commit 3c8687a

Browse files
committed
remove FirestorePagingSource and consequently Java 8
1 parent 91f6269 commit 3c8687a

File tree

7 files changed

+312
-181
lines changed

7 files changed

+312
-181
lines changed

buildSrc/src/main/kotlin/Config.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ object Config {
3636
const val legacySupportv4 = "androidx.legacy:legacy-support-v4:1.0.0"
3737
const val multidex = "androidx.multidex:multidex:2.0.1"
3838
const val paging = "androidx.paging:paging-runtime:3.0.0-beta01"
39-
const val pagingRxJava3 = "androidx.paging:paging-rxjava3:3.0.0-beta01"
4039
const val recyclerView = "androidx.recyclerview:recyclerview:1.1.0"
4140

4241
const val design = "com.google.android.material:material:1.2.1"

firestore/build.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ android {
1212
consumerProguardFiles("proguard-rules.pro")
1313
}
1414
}
15-
16-
compileOptions {
17-
sourceCompatibility = JavaVersion.VERSION_1_8
18-
targetCompatibility = JavaVersion.VERSION_1_8
19-
}
2015
}
2116

2217
dependencies {
@@ -28,7 +23,6 @@ dependencies {
2823
api(Config.Libs.Androidx.recyclerView)
2924

3025
compileOnly(Config.Libs.Androidx.paging)
31-
api(Config.Libs.Androidx.pagingRxJava3)
3226
annotationProcessor(Config.Libs.Androidx.lifecycleCompiler)
3327

3428
lintChecks(project(":lint"))

firestore/src/androidTest/java/com/firebase/ui/firestore/FirestorePagingSourceTest.java renamed to firestore/src/androidTest/java/com/firebase/ui/firestore/FirestoreDataSourceTest.java

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.firebase.ui.firestore;
22

3-
import android.util.Log;
4-
5-
import com.firebase.ui.firestore.paging.FirestorePagingSource;
3+
import com.firebase.ui.firestore.paging.FirestoreDataSource;
64
import com.firebase.ui.firestore.paging.LoadingState;
75
import com.firebase.ui.firestore.paging.PageKey;
86
import com.google.android.gms.tasks.Tasks;
@@ -26,7 +24,7 @@
2624
import androidx.annotation.Nullable;
2725
import androidx.arch.core.executor.testing.InstantTaskExecutorRule;
2826
import androidx.lifecycle.Observer;
29-
import androidx.paging.PagingSource;
27+
import androidx.paging.PageKeyedDataSource;
3028
import androidx.test.ext.junit.runners.AndroidJUnit4;
3129

3230
import static org.junit.Assert.assertEquals;
@@ -36,9 +34,9 @@
3634
import static org.mockito.Mockito.when;
3735

3836
@RunWith(AndroidJUnit4.class)
39-
public class FirestorePagingSourceTest {
37+
public class FirestoreDataSourceTest {
4038

41-
private FirestorePagingSource mPagingSource;
39+
private FirestoreDataSource mDataSource;
4240

4341
/**
4442
* Needed to run tasks on the main thread so observeForever() doesn't throw.
@@ -47,43 +45,46 @@ public class FirestorePagingSourceTest {
4745
public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule();
4846

4947
@Mock Query mMockQuery;
48+
@Mock PageKeyedDataSource.LoadInitialCallback<PageKey, DocumentSnapshot> mInitialCallback;
49+
@Mock PageKeyedDataSource.LoadCallback<PageKey, DocumentSnapshot> mAfterCallback;
5050

5151
@Before
5252
public void setUp() {
5353
MockitoAnnotations.initMocks(this);
5454
initMockQuery();
5555

56-
// Create a testing paging source
57-
mPagingSource = new FirestorePagingSource(mMockQuery, Source.DEFAULT);
56+
// Create a testing data source
57+
mDataSource = new FirestoreDataSource(mMockQuery, Source.DEFAULT);
5858
}
5959

6060
@Test
6161
public void testLoadInitial_success() throws Exception {
6262
mockQuerySuccess(new ArrayList<DocumentSnapshot>());
6363

6464
TestObserver<LoadingState> observer = new TestObserver<>(2);
65-
mPagingSource.getLoadingState().observeForever(observer);
65+
mDataSource.getLoadingState().observeForever(observer);
6666

6767
// Kick off an initial load of 20 items
68-
PagingSource.LoadParams.Refresh<PageKey> params = new PagingSource.LoadParams.Refresh<>(null, 20, false);
69-
mPagingSource.loadSingle(params).blockingSubscribe();
68+
PageKeyedDataSource.LoadInitialParams<PageKey> params =
69+
new PageKeyedDataSource.LoadInitialParams<>(20, false);
70+
mDataSource.loadInitial(params, mInitialCallback);
7071

71-
// Should go from LOADING_INITIAL --> LOADED --> LOADING_FINISHED
72+
// Should go from LOADING_INITIAL --> LOADED
7273
observer.await();
73-
observer.assertResults(Arrays.asList(LoadingState.LOADING_INITIAL, LoadingState.LOADED,
74-
LoadingState.FINISHED));
74+
observer.assertResults(Arrays.asList(LoadingState.LOADING_INITIAL, LoadingState.LOADED));
7575
}
7676

7777
@Test
7878
public void testLoadInitial_failure() throws Exception {
7979
mockQueryFailure("Could not get initial documents.");
8080

8181
TestObserver<LoadingState> observer = new TestObserver<>(2);
82-
mPagingSource.getLoadingState().observeForever(observer);
82+
mDataSource.getLoadingState().observeForever(observer);
8383

8484
// Kick off an initial load of 20 items
85-
PagingSource.LoadParams.Refresh<PageKey> params = new PagingSource.LoadParams.Refresh<>(null, 20, false);
86-
mPagingSource.loadSingle(params).blockingSubscribe();
85+
PageKeyedDataSource.LoadInitialParams<PageKey> params =
86+
new PageKeyedDataSource.LoadInitialParams<>(20, false);
87+
mDataSource.loadInitial(params, mInitialCallback);
8788

8889
// Should go from LOADING_INITIAL --> ERROR
8990
observer.await();
@@ -95,39 +96,71 @@ public void testLoadAfter_success() throws Exception {
9596
mockQuerySuccess(new ArrayList<DocumentSnapshot>());
9697

9798
TestObserver<LoadingState> observer = new TestObserver<>(2);
98-
mPagingSource.getLoadingState().observeForever(observer);
99+
mDataSource.getLoadingState().observeForever(observer);
99100

100101
// Kick off an initial load of 20 items
101102
PageKey pageKey = new PageKey(null, null);
102-
PagingSource.LoadParams.Append<PageKey> params = new PagingSource.LoadParams.Append<>(pageKey, 20, false);
103-
mPagingSource.loadSingle(params).blockingSubscribe();
103+
PageKeyedDataSource.LoadParams<PageKey> params =
104+
new PageKeyedDataSource.LoadParams<>(pageKey, 20);
105+
mDataSource.loadAfter(params, mAfterCallback);
104106

105-
// Should go from LOADING_MORE --> LOADED --> LOADING_FINISHED
107+
// Should go from LOADING_MORE --> LOADED
106108
observer.await();
107-
observer.assertResults(Arrays.asList(LoadingState.LOADING_MORE, LoadingState.LOADED,
108-
LoadingState.FINISHED));
109+
observer.assertResults(Arrays.asList(LoadingState.LOADING_MORE, LoadingState.LOADED));
109110
}
110111

111112
@Test
112113
public void testLoadAfter_failure() throws Exception {
113114
mockQueryFailure("Could not load more documents.");
114115

115116
TestObserver<LoadingState> observer = new TestObserver<>(2);
116-
mPagingSource.getLoadingState().observeForever(observer);
117+
mDataSource.getLoadingState().observeForever(observer);
117118

118119
// Kick off an initial load of 20 items
119120
PageKey pageKey = new PageKey(null, null);
120-
PagingSource.LoadParams.Append<PageKey> params = new PagingSource.LoadParams.Append<>(pageKey, 20, false);
121-
mPagingSource.loadSingle(params).blockingSubscribe();
121+
PageKeyedDataSource.LoadParams<PageKey> params =
122+
new PageKeyedDataSource.LoadParams<>(pageKey, 20);
123+
mDataSource.loadAfter(params, mAfterCallback);
122124

123125
// Should go from LOADING_MORE --> ERROR
124126
observer.await();
125127
observer.assertResults(Arrays.asList(LoadingState.LOADING_MORE, LoadingState.ERROR));
126128
}
127129

130+
@Test
131+
public void testLoadAfter_retry() throws Exception {
132+
mockQueryFailure("Could not load more documents.");
133+
134+
TestObserver<LoadingState> observer1 = new TestObserver<>(2);
135+
mDataSource.getLoadingState().observeForever(observer1);
136+
137+
// Kick off an initial load of 20 items
138+
PageKey pageKey = new PageKey(null, null);
139+
PageKeyedDataSource.LoadParams<PageKey> params =
140+
new PageKeyedDataSource.LoadParams<>(pageKey, 20);
141+
mDataSource.loadAfter(params, mAfterCallback);
142+
143+
// Should go from LOADING_MORE --> ERROR
144+
observer1.await();
145+
observer1.assertResults(Arrays.asList(LoadingState.LOADING_MORE, LoadingState.ERROR));
146+
147+
// Create a new observer
148+
TestObserver<LoadingState> observer2 = new TestObserver<>(3);
149+
mDataSource.getLoadingState().observeForever(observer2);
150+
151+
// Retry the load
152+
mockQuerySuccess(new ArrayList<DocumentSnapshot>());
153+
mDataSource.retry();
154+
155+
// Should go from ERROR --> LOADING_MORE --> SUCCESS
156+
observer2.await();
157+
observer2.assertResults(
158+
Arrays.asList(LoadingState.ERROR, LoadingState.LOADING_MORE, LoadingState.LOADED));
159+
}
160+
128161
private void initMockQuery() {
129-
when(mMockQuery.startAfter(any(DocumentSnapshot.class))).thenReturn(mMockQuery);
130-
when(mMockQuery.endBefore(any(DocumentSnapshot.class))).thenReturn(mMockQuery);
162+
when(mMockQuery.startAfter(any())).thenReturn(mMockQuery);
163+
when(mMockQuery.endBefore(any())).thenReturn(mMockQuery);
131164
when(mMockQuery.limit(anyLong())).thenReturn(mMockQuery);
132165
}
133166

0 commit comments

Comments
 (0)