|
14 | 14 |
|
15 | 15 | package com.google.firebase.firestore;
|
16 | 16 |
|
| 17 | +import static com.google.common.truth.Truth.assertThat; |
17 | 18 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
|
18 | 19 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
|
19 | 20 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
|
| 21 | +import static com.google.firebase.firestore.testutil.IntegrationTestUtil.toDataMap; |
20 | 22 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
|
21 | 23 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitForException;
|
22 | 24 | import static com.google.firebase.firestore.testutil.TestUtil.map;
|
|
25 | 27 | import static org.junit.Assert.assertEquals;
|
26 | 28 | import static org.junit.Assert.assertFalse;
|
27 | 29 | import static org.junit.Assert.assertNotEquals;
|
| 30 | +import static org.junit.Assert.assertThrows; |
28 | 31 | import static org.junit.Assert.assertTrue;
|
| 32 | +import static org.junit.Assume.assumeFalse; |
29 | 33 |
|
30 | 34 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
| 35 | + |
| 36 | +import com.google.android.gms.tasks.Task; |
| 37 | +import com.google.android.gms.tasks.Tasks; |
31 | 38 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
32 | 39 | import org.junit.After;
|
33 | 40 | import org.junit.Test;
|
34 | 41 | import org.junit.runner.RunWith;
|
35 | 42 |
|
| 43 | +import java.util.Collections; |
| 44 | + |
36 | 45 | @RunWith(AndroidJUnit4.class)
|
37 | 46 | public class CountTest {
|
38 | 47 |
|
@@ -253,4 +262,23 @@ public void testFailWithoutNetwork() {
|
253 | 262 | AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
|
254 | 263 | assertEquals(3L, snapshot.getCount());
|
255 | 264 | }
|
| 265 | + |
| 266 | + @Test |
| 267 | + public void testFailWithGoodMessageIfMissingIndex() { |
| 268 | + assumeFalse( |
| 269 | + "Skip this test when running against the Firestore emulator because the Firestore emulator " |
| 270 | + + "does not use indexes and never fails with a 'missing index' error", |
| 271 | + BuildConfig.USE_EMULATOR_FOR_TESTS); |
| 272 | + |
| 273 | + CollectionReference collection = testCollectionWithDocs(Collections.emptyMap()); |
| 274 | + Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99); |
| 275 | + AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count(); |
| 276 | + Task<AggregateQuerySnapshot> task = compositeIndexCountQuery.get(AggregateSource.SERVER); |
| 277 | + |
| 278 | + Throwable throwable = assertThrows(Throwable.class, () -> waitFor(task)); |
| 279 | + |
| 280 | + Throwable cause = throwable.getCause(); |
| 281 | + assertThat(cause).hasMessageThat().ignoringCase().contains("index"); |
| 282 | + assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com"); |
| 283 | + } |
256 | 284 | }
|
0 commit comments