|
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;
|
|
25 | 26 | import static org.junit.Assert.assertEquals;
|
26 | 27 | import static org.junit.Assert.assertFalse;
|
27 | 28 | import static org.junit.Assert.assertNotEquals;
|
| 29 | +import static org.junit.Assert.assertThrows; |
28 | 30 | import static org.junit.Assert.assertTrue;
|
| 31 | +import static org.junit.Assume.assumeFalse; |
29 | 32 |
|
30 | 33 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
| 34 | +import com.google.android.gms.tasks.Task; |
31 | 35 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
| 36 | +import java.util.Collections; |
32 | 37 | import org.junit.After;
|
33 | 38 | import org.junit.Test;
|
34 | 39 | import org.junit.runner.RunWith;
|
@@ -253,4 +258,23 @@ public void testFailWithoutNetwork() {
|
253 | 258 | AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
|
254 | 259 | assertEquals(3L, snapshot.getCount());
|
255 | 260 | }
|
| 261 | + |
| 262 | + @Test |
| 263 | + public void testFailWithGoodMessageIfMissingIndex() { |
| 264 | + assumeFalse( |
| 265 | + "Skip this test when running against the Firestore emulator because the Firestore emulator " |
| 266 | + + "does not use indexes and never fails with a 'missing index' error", |
| 267 | + BuildConfig.USE_EMULATOR_FOR_TESTS); |
| 268 | + |
| 269 | + CollectionReference collection = testCollectionWithDocs(Collections.emptyMap()); |
| 270 | + Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99); |
| 271 | + AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count(); |
| 272 | + Task<AggregateQuerySnapshot> task = compositeIndexCountQuery.get(AggregateSource.SERVER); |
| 273 | + |
| 274 | + Throwable throwable = assertThrows(Throwable.class, () -> waitFor(task)); |
| 275 | + |
| 276 | + Throwable cause = throwable.getCause(); |
| 277 | + assertThat(cause).hasMessageThat().ignoringCase().contains("index"); |
| 278 | + assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com"); |
| 279 | + } |
256 | 280 | }
|
0 commit comments