Skip to content

Commit 24813d0

Browse files
committed
Remove usage of Java 8 features (lambdas)
1 parent 11aa7ad commit 24813d0

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

Diff for: src/main/java/com/google/firebase/cloud/FirestoreClient.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Collections;
1515
import java.util.HashMap;
1616
import java.util.Map;
17+
import java.util.function.Function;
1718
import org.slf4j.Logger;
1819
import org.slf4j.LoggerFactory;
1920

@@ -139,16 +140,24 @@ private static class FirestoreInstances {
139140
private final FirebaseApp app;
140141

141142
private final Map<String, FirestoreClient> clients =
142-
Collections.synchronizedMap(new HashMap<>());
143+
Collections.synchronizedMap(new HashMap<String, FirestoreClient>());
143144

144145
private FirestoreInstances(FirebaseApp app) {
145146
this.app = app;
146147
}
147148

148149
FirestoreClient get(String databaseId) {
149-
return clients.computeIfAbsent(databaseId, id -> new FirestoreClient(app, id));
150+
return clients.computeIfAbsent(databaseId, newFirestoreInstance);
150151
}
151152

153+
private final Function<String, FirestoreClient> newFirestoreInstance =
154+
new Function<String, FirestoreClient>() {
155+
@Override
156+
public FirestoreClient apply(String id) {
157+
return new FirestoreClient(app, id);
158+
}
159+
};
160+
152161
void destroy() {
153162
synchronized (clients) {
154163
for (FirestoreClient client : clients.values()) {

Diff for: src/test/java/com/google/firebase/cloud/FirestoreClientTest.java

+28-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import org.junit.After;
2121
import org.junit.Test;
22+
import org.junit.function.ThrowingRunnable;
2223

2324
public class FirestoreClientTest {
2425

@@ -135,7 +136,7 @@ public void testFirestoreOptionsOverride() throws IOException {
135136
@Test
136137
public void testAppDelete() throws IOException {
137138
final String databaseId = "databaseIdInTestAppDelete";
138-
FirebaseApp app = FirebaseApp.initializeApp(FirebaseOptions.builder()
139+
final FirebaseApp app = FirebaseApp.initializeApp(FirebaseOptions.builder()
139140
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
140141
.setProjectId("mock-project-id")
141142
.setFirestoreOptions(FIRESTORE_OPTIONS)
@@ -151,13 +152,33 @@ public void testAppDelete() throws IOException {
151152

152153
assertNotSame(firestore1, firestore2);
153154

154-
DocumentReference document = firestore1.collection("collection").document("doc");
155+
final DocumentReference document = firestore1.collection("collection").document("doc");
155156
app.delete();
156157

157-
assertThrows(IllegalStateException.class, () -> FirestoreClient.getFirestore(app));
158-
assertThrows(IllegalStateException.class, () -> document.get());
159-
assertThrows(IllegalStateException.class, () -> FirestoreClient.getFirestore());
160-
assertThrows(IllegalStateException.class, () -> FirestoreClient.getFirestore(app, databaseId));
161-
assertThrows(IllegalStateException.class, () -> FirestoreClient.getFirestore(databaseId));
158+
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
159+
public void run() {
160+
FirestoreClient.getFirestore(app);
161+
}
162+
});
163+
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
164+
public void run() throws Throwable {
165+
document.get();
166+
}
167+
});
168+
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
169+
public void run() throws Throwable {
170+
FirestoreClient.getFirestore();
171+
}
172+
});
173+
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
174+
public void run() throws Throwable {
175+
FirestoreClient.getFirestore(app, databaseId);
176+
}
177+
});
178+
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
179+
public void run() throws Throwable {
180+
FirestoreClient.getFirestore(databaseId);
181+
}
182+
});
162183
}
163184
}

0 commit comments

Comments
 (0)