Skip to content

Commit 08d28c7

Browse files
committed
Add documentation and fix test.
1 parent 372b10b commit 08d28c7

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.junit.Assert.assertSame;
3939
import static org.junit.Assert.assertTrue;
4040
import static org.junit.Assert.fail;
41+
import static org.junit.Assume.assumeTrue;
4142

4243
import androidx.test.ext.junit.runners.AndroidJUnit4;
4344
import com.google.android.gms.tasks.Task;
@@ -1169,13 +1170,11 @@ public void testDifferentDbNamesAreDifferent() {
11691170
}
11701171

11711172
@Test
1172-
public void testNamedDbHaveDifferentPersistence()
1173-
throws ExecutionException, InterruptedException, TimeoutException {
1173+
public void testNamedDbHaveDifferentPersistence() {
11741174
// TODO: Have backend with named databases created beforehand.
11751175
// Emulator doesn't care if database was created beforehand.
1176-
if (!isRunningAgainstEmulator()) {
1177-
return;
1178-
}
1176+
assumeTrue(isRunningAgainstEmulator());
1177+
11791178
// FirebaseFirestore db1 = FirebaseFirestore.getInstance();
11801179
String projectId = provider().projectId();
11811180
FirebaseFirestore db1 =

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,61 @@ private static FirebaseApp getDefaultFirebaseApp() {
112112
return app;
113113
}
114114

115+
/**
116+
* Returns the existing default {@link FirebaseFirestore} instance that is associated with the
117+
* default {@link FirebaseApp}. If no instance exists, initializes a new
118+
* instance with default settings.
119+
* @param app - The {@link FirebaseApp} instance that the returned {@link FirebaseFirestore}
120+
* instance is associated with.
121+
* @param database - The name of database.
122+
* @returns The {@link FirebaseFirestore} instance of the provided app.
123+
*/
115124
@NonNull
116125
public static FirebaseFirestore getInstance() {
117126
return getInstance(getDefaultFirebaseApp(), DatabaseId.DEFAULT_DATABASE_ID);
118127
}
119128

129+
/**
130+
* Returns the existing default {@link FirebaseFirestore} instance that is associated with the
131+
* provided {@link FirebaseApp}. If no instance exists, initializes a new
132+
* instance with default settings.
133+
* @param app - The {@link FirebaseApp} instance that the returned {@link FirebaseFirestore}
134+
* instance is associated with.
135+
* @param database - The name of database.
136+
* @returns The {@link FirebaseFirestore} instance of the provided app.
137+
*/
120138
@NonNull
121139
public static FirebaseFirestore getInstance(@NonNull FirebaseApp app) {
122140
return getInstance(app, DatabaseId.DEFAULT_DATABASE_ID);
123141
}
124142

143+
/**
144+
* Returns the existing {@link FirebaseFirestore} instance that is associated with the
145+
* default {@link FirebaseApp}. If no instance exists, initializes a new
146+
* instance with default settings.
147+
* @param app - The {@link FirebaseApp} instance that the returned {@link FirebaseFirestore}
148+
* instance is associated with.
149+
* @param database - The name of database.
150+
* @returns The {@link FirebaseFirestore} instance of the provided app.
151+
*/
125152
@NonNull
126153
public static FirebaseFirestore getInstance(@NonNull String database) {
127154
return getInstance(getDefaultFirebaseApp(), database);
128155
}
129156

157+
/**
158+
* Returns the existing {@link FirebaseFirestore} instance that is associated with the
159+
* provided {@link FirebaseApp}. If no instance exists, initializes a new
160+
* instance with default settings.
161+
* @param app - The {@link FirebaseApp} instance that the returned {@link FirebaseFirestore}
162+
* instance is associated with.
163+
* @param database - The name of database.
164+
* @returns The {@link FirebaseFirestore} instance of the provided app.
165+
*/
130166
@NonNull
131167
public static FirebaseFirestore getInstance(@NonNull FirebaseApp app, @NonNull String database) {
132168
checkNotNull(app, "Provided FirebaseApp must not be null.");
169+
checkNotNull(database, "Provided database name must not be null.");
133170
FirestoreMultiDbComponent component = app.get(FirestoreMultiDbComponent.class);
134171
checkNotNull(component, "Firestore component is not present.");
135172
return component.get(database);

0 commit comments

Comments
 (0)