Skip to content

Commit 8b60189

Browse files
authored
Merge a6b60a1 into ed10eb5
2 parents ed10eb5 + a6b60a1 commit 8b60189

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/CountTest.java

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ public void testCanRunCount() {
8888
"b", map("k", "b"),
8989
"c", map("k", "c")));
9090

91-
AggregateQuerySnapshot snapshot =
92-
waitFor(collection.count().get(AggregateSource.SERVER_DIRECT));
93-
assertEquals(Long.valueOf(3), snapshot.getCount());
91+
AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
92+
assertEquals(3, snapshot.getCount());
9493
}
9594

9695
@Test
@@ -103,8 +102,8 @@ public void testCanRunCountWithFilters() {
103102
"c", map("k", "c")));
104103

105104
AggregateQuerySnapshot snapshot =
106-
waitFor(collection.whereEqualTo("k", "b").count().get(AggregateSource.SERVER_DIRECT));
107-
assertEquals(Long.valueOf(1), snapshot.getCount());
105+
waitFor(collection.whereEqualTo("k", "b").count().get(AggregateSource.SERVER));
106+
assertEquals(1, snapshot.getCount());
108107
}
109108

110109
@Test
@@ -118,9 +117,9 @@ public void testCanRunCountWithOrderBy() {
118117
"d", map("absent", "d")));
119118

120119
AggregateQuerySnapshot snapshot =
121-
waitFor(collection.orderBy("k").count().get(AggregateSource.SERVER_DIRECT));
120+
waitFor(collection.orderBy("k").count().get(AggregateSource.SERVER));
122121
// "d" is filtered out because it is ordered by "k".
123-
assertEquals(Long.valueOf(3), snapshot.getCount());
122+
assertEquals(3, snapshot.getCount());
124123
}
125124

126125
@Test
@@ -132,7 +131,7 @@ public void testTerminateDoesNotCrashWithFlyingCountQuery() {
132131
"b", map("k", "b"),
133132
"c", map("k", "c")));
134133

135-
collection.orderBy("k").count().get(AggregateSource.SERVER_DIRECT);
134+
collection.orderBy("k").count().get(AggregateSource.SERVER);
136135
waitFor(collection.firestore.terminate());
137136
}
138137

@@ -146,15 +145,15 @@ public void testSnapshotEquals() {
146145
"c", map("k", "c")));
147146

148147
AggregateQuerySnapshot snapshot1 =
149-
waitFor(collection.whereEqualTo("k", "b").count().get(AggregateSource.SERVER_DIRECT));
148+
waitFor(collection.whereEqualTo("k", "b").count().get(AggregateSource.SERVER));
150149
AggregateQuerySnapshot snapshot1_same =
151-
waitFor(collection.whereEqualTo("k", "b").count().get(AggregateSource.SERVER_DIRECT));
150+
waitFor(collection.whereEqualTo("k", "b").count().get(AggregateSource.SERVER));
152151

153152
AggregateQuerySnapshot snapshot2 =
154-
waitFor(collection.whereEqualTo("k", "a").count().get(AggregateSource.SERVER_DIRECT));
153+
waitFor(collection.whereEqualTo("k", "a").count().get(AggregateSource.SERVER));
155154
waitFor(collection.document("d").set(map("k", "a")));
156155
AggregateQuerySnapshot snapshot2_different =
157-
waitFor(collection.whereEqualTo("k", "a").count().get(AggregateSource.SERVER_DIRECT));
156+
waitFor(collection.whereEqualTo("k", "a").count().get(AggregateSource.SERVER));
158157

159158
assertTrue(snapshot1.equals(snapshot1_same));
160159
assertEquals(snapshot1.hashCode(), snapshot1_same.hashCode());
@@ -196,9 +195,9 @@ public void testCanRunCollectionGroupQuery() {
196195
waitFor(batch.commit());
197196

198197
AggregateQuerySnapshot snapshot =
199-
waitFor(db.collectionGroup(collectionGroup).count().get(AggregateSource.SERVER_DIRECT));
198+
waitFor(db.collectionGroup(collectionGroup).count().get(AggregateSource.SERVER));
200199
assertEquals(
201-
Long.valueOf(5), // "cg-doc1", "cg-doc2", "cg-doc3", "cg-doc4", "cg-doc5",
200+
5, // "cg-doc1", "cg-doc2", "cg-doc3", "cg-doc4", "cg-doc5",
202201
snapshot.getCount());
203202
}
204203

@@ -213,40 +212,33 @@ public void testCanRunCountWithFiltersAndLimits() {
213212
"d", map("k", "d")));
214213

215214
AggregateQuerySnapshot snapshot =
216-
waitFor(
217-
collection.whereEqualTo("k", "a").limit(2).count().get(AggregateSource.SERVER_DIRECT));
218-
assertEquals(Long.valueOf(2), snapshot.getCount());
215+
waitFor(collection.whereEqualTo("k", "a").limit(2).count().get(AggregateSource.SERVER));
216+
assertEquals(2, snapshot.getCount());
219217

220218
snapshot =
221219
waitFor(
222-
collection
223-
.whereEqualTo("k", "a")
224-
.limitToLast(2)
225-
.count()
226-
.get(AggregateSource.SERVER_DIRECT));
227-
assertEquals(Long.valueOf(2), snapshot.getCount());
220+
collection.whereEqualTo("k", "a").limitToLast(2).count().get(AggregateSource.SERVER));
221+
assertEquals(2, snapshot.getCount());
228222

229223
snapshot =
230224
waitFor(
231225
collection
232226
.whereEqualTo("k", "d")
233227
.limitToLast(1000)
234228
.count()
235-
.get(AggregateSource.SERVER_DIRECT));
236-
assertEquals(Long.valueOf(1), snapshot.getCount());
229+
.get(AggregateSource.SERVER));
230+
assertEquals(1, snapshot.getCount());
237231
}
238232

239233
@Test
240234
public void testCanRunCountOnNonExistentCollection() {
241235
CollectionReference collection = testFirestore().collection("random-coll");
242236

243-
AggregateQuerySnapshot snapshot =
244-
waitFor(collection.count().get(AggregateSource.SERVER_DIRECT));
245-
assertEquals(Long.valueOf(0), snapshot.getCount());
237+
AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
238+
assertEquals(0, snapshot.getCount());
246239

247-
snapshot =
248-
waitFor(collection.whereEqualTo("k", 100).count().get(AggregateSource.SERVER_DIRECT));
249-
assertEquals(Long.valueOf(0), snapshot.getCount());
240+
snapshot = waitFor(collection.whereEqualTo("k", 100).count().get(AggregateSource.SERVER));
241+
assertEquals(0, snapshot.getCount());
250242
}
251243

252244
@Test
@@ -259,14 +251,13 @@ public void testFailWithoutNetwork() {
259251
"c", map("k", "c")));
260252
waitFor(collection.getFirestore().disableNetwork());
261253

262-
Exception e = waitForException(collection.count().get(AggregateSource.SERVER_DIRECT));
254+
Exception e = waitForException(collection.count().get(AggregateSource.SERVER));
263255
assertThat(e, instanceOf(FirebaseFirestoreException.class));
264256
assertEquals(
265257
FirebaseFirestoreException.Code.UNAVAILABLE, ((FirebaseFirestoreException) e).getCode());
266258

267259
waitFor(collection.getFirestore().enableNetwork());
268-
AggregateQuerySnapshot snapshot =
269-
waitFor(collection.count().get(AggregateSource.SERVER_DIRECT));
270-
assertEquals(Long.valueOf(3), snapshot.getCount());
260+
AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
261+
assertEquals(3, snapshot.getCount());
271262
}
272263
}

firebase-firestore/src/main/java/com/google/firebase/firestore/AggregateQuerySnapshot.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static com.google.firebase.firestore.util.Preconditions.checkNotNull;
1818

1919
import androidx.annotation.NonNull;
20-
import androidx.annotation.Nullable;
2120
import java.util.Objects;
2221

2322
/**
@@ -44,12 +43,8 @@ public AggregateQuery getQuery() {
4443
return query;
4544
}
4645

47-
/**
48-
* @return The result of a document count aggregation. Returns null if no count aggregation is
49-
* available in the result.
50-
*/
51-
@Nullable
52-
public Long getCount() {
46+
/** @return The result of a document count aggregation. */
47+
public long getCount() {
5348
return count;
5449
}
5550

firebase-firestore/src/main/java/com/google/firebase/firestore/AggregateSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ enum AggregateSource {
2222
*
2323
* <p>Requires client to be online.
2424
*/
25-
SERVER_DIRECT,
25+
SERVER,
2626
}

0 commit comments

Comments
 (0)