Skip to content

Commit 30651de

Browse files
committed
Revert "Remove usage of Java 8 features (lambdas)"
This reverts commit 24813d0.
1 parent 24813d0 commit 30651de

File tree

2 files changed

+9
-39
lines changed

2 files changed

+9
-39
lines changed

src/main/java/com/google/firebase/cloud/FirestoreClient.java

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

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

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

145144
private FirestoreInstances(FirebaseApp app) {
146145
this.app = app;
147146
}
148147

149148
FirestoreClient get(String databaseId) {
150-
return clients.computeIfAbsent(databaseId, newFirestoreInstance);
149+
return clients.computeIfAbsent(databaseId, id -> new FirestoreClient(app, id));
151150
}
152151

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-
161152
void destroy() {
162153
synchronized (clients) {
163154
for (FirestoreClient client : clients.values()) {

src/test/java/com/google/firebase/cloud/FirestoreClientTest.java

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

2423
public class FirestoreClientTest {
2524

@@ -136,7 +135,7 @@ public void testFirestoreOptionsOverride() throws IOException {
136135
@Test
137136
public void testAppDelete() throws IOException {
138137
final String databaseId = "databaseIdInTestAppDelete";
139-
final FirebaseApp app = FirebaseApp.initializeApp(FirebaseOptions.builder()
138+
FirebaseApp app = FirebaseApp.initializeApp(FirebaseOptions.builder()
140139
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
141140
.setProjectId("mock-project-id")
142141
.setFirestoreOptions(FIRESTORE_OPTIONS)
@@ -152,33 +151,13 @@ public void testAppDelete() throws IOException {
152151

153152
assertNotSame(firestore1, firestore2);
154153

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

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-
});
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));
183162
}
184163
}

0 commit comments

Comments
 (0)