diff --git a/firebase-firestore/src/androidTest/java/com/google/firebase/firestore/CountTest.java b/firebase-firestore/src/androidTest/java/com/google/firebase/firestore/CountTest.java index 5636cecffdd..396847e2174 100644 --- a/firebase-firestore/src/androidTest/java/com/google/firebase/firestore/CountTest.java +++ b/firebase-firestore/src/androidTest/java/com/google/firebase/firestore/CountTest.java @@ -14,6 +14,7 @@ package com.google.firebase.firestore; +import static com.google.common.truth.Truth.assertThat; import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection; import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs; import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore; @@ -25,10 +26,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.android.gms.tasks.Task; import com.google.firebase.firestore.testutil.IntegrationTestUtil; +import java.util.Collections; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -253,4 +258,23 @@ public void testFailWithoutNetwork() { AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER)); assertEquals(3L, snapshot.getCount()); } + + @Test + public void testFailWithGoodMessageIfMissingIndex() { + assumeFalse( + "Skip this test when running against the Firestore emulator because the Firestore emulator " + + "does not use indexes and never fails with a 'missing index' error", + BuildConfig.USE_EMULATOR_FOR_TESTS); + + CollectionReference collection = testCollectionWithDocs(Collections.emptyMap()); + Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99); + AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count(); + Task task = compositeIndexCountQuery.get(AggregateSource.SERVER); + + Throwable throwable = assertThrows(Throwable.class, () -> waitFor(task)); + + Throwable cause = throwable.getCause(); + assertThat(cause).hasMessageThat().ignoringCase().contains("index"); + assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com"); + } }