Skip to content

Commit 1f574a3

Browse files
authored
Fixing some compiler warnings (#245)
1 parent fd63d97 commit 1f574a3

File tree

5 files changed

+39
-127
lines changed

5 files changed

+39
-127
lines changed

src/test/java/com/google/firebase/database/OnDisconnectTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@
2424
import com.google.firebase.database.DatabaseReference.CompletionListener;
2525
import com.google.firebase.database.core.Path;
2626
import com.google.firebase.database.core.Repo;
27+
import com.google.firebase.database.snapshot.Node;
2728
import com.google.firebase.database.snapshot.NodeUtilities;
2829
import java.util.Map;
2930
import org.junit.Test;
31+
import org.mockito.ArgumentMatchers;
3032
import org.mockito.Mockito;
3133

3234
public class OnDisconnectTest {
3335

3436
private static final Path path = new Path("foo");
3537

3638
@Test
37-
public void testSetValue() throws Exception {
39+
public void testSetValue() {
3840
Repo repo = mockRepo();
3941
OnDisconnect reference = new OnDisconnect(repo, path);
4042
reference.setValueAsync("value");
41-
reference.setValue("value", (CompletionListener) null);
43+
reference.setValue("value", null);
4244
Mockito.verify(repo, times(2))
4345
.scheduleNow(Mockito.any(Runnable.class));
4446
Mockito.verify(repo, times(2))
@@ -49,7 +51,7 @@ public void testSetValue() throws Exception {
4951
}
5052

5153
@Test
52-
public void testSetValueWithPriority() throws Exception {
54+
public void testSetValueWithPriority() {
5355
Repo repo = mockRepo();
5456
OnDisconnect reference = new OnDisconnect(repo, path);
5557
reference.setValueAsync("value", 10);
@@ -89,7 +91,7 @@ public void testSetValueWithPriority() throws Exception {
8991
}
9092

9193
@Test
92-
public void testUpdateChildren() throws Exception {
94+
public void testUpdateChildren() {
9395
Repo repo = mockRepo();
9496
OnDisconnect reference = new OnDisconnect(repo, path);
9597
try {
@@ -107,13 +109,13 @@ public void testUpdateChildren() throws Exception {
107109
Mockito.verify(repo, times(2))
108110
.onDisconnectUpdate(
109111
Mockito.same(path),
110-
Mockito.any(Map.class),
112+
ArgumentMatchers.<Map<Path, Node>>any(),
111113
Mockito.any(CompletionListener.class),
112114
Mockito.same(update));
113115
}
114116

115117
@Test
116-
public void testRemoveValue() throws Exception {
118+
public void testRemoveValue() {
117119
Repo repo = mockRepo();
118120
OnDisconnect reference = new OnDisconnect(repo, path);
119121
reference.removeValueAsync();
@@ -129,7 +131,7 @@ public void testRemoveValue() throws Exception {
129131
}
130132

131133
@Test
132-
public void testCancel() throws Exception {
134+
public void testCancel() {
133135
Repo repo = mockRepo();
134136
OnDisconnect reference = new OnDisconnect(repo, path);
135137
reference.cancelAsync();

src/test/java/com/google/firebase/database/core/utilities/ChildKeyGenerator.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/test/java/com/google/firebase/database/integration/FirebaseDatabaseAuthTestIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.api.core.ApiFutures;
2424
import com.google.auth.oauth2.GoogleCredentials;
2525
import com.google.common.collect.ImmutableMap;
26+
import com.google.common.util.concurrent.MoreExecutors;
2627
import com.google.firebase.FirebaseApp;
2728
import com.google.firebase.FirebaseOptions;
2829
import com.google.firebase.database.DataSnapshot;
@@ -169,7 +170,7 @@ public void onSuccess(Void result) {
169170
success.compareAndSet(false, true);
170171
lock.countDown();
171172
}
172-
});
173+
}, MoreExecutors.directExecutor());
173174
boolean finished = lock.await(TestUtils.TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
174175
if (shouldTimeout) {
175176
assertTrue("Write finished (expected to timeout).", !finished);

src/test/java/com/google/firebase/database/integration/OrderByTestIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNull;
2121

22+
import com.google.api.client.json.GenericJson;
2223
import com.google.common.collect.ImmutableList;
2324
import com.google.firebase.FirebaseApp;
2425
import com.google.firebase.database.ChildEventListener;
@@ -82,7 +83,7 @@ private static String formatRules(DatabaseReference ref, String rules) {
8283
return String.format(
8384
"{\"rules\": {\".read\": true, \".write\": true, \"%s\": %s}}", ref.getKey(), rules);
8485
}
85-
86+
8687
private static void uploadRules(FirebaseApp app, String rules) throws IOException {
8788
IntegrationTestUtils.AppHttpClient client = new IntegrationTestUtils.AppHttpClient(app);
8889
IntegrationTestUtils.ResponseInfo response = client.put("/.settings/rules.json", rules);

src/test/java/com/google/firebase/testing/IntegrationTestUtils.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

2121
import com.google.api.client.googleapis.util.Utils;
22+
import com.google.api.client.http.ByteArrayContent;
23+
import com.google.api.client.http.GenericUrl;
24+
import com.google.api.client.http.HttpRequest;
25+
import com.google.api.client.http.HttpRequestFactory;
26+
import com.google.api.client.http.HttpResponse;
2227
import com.google.api.client.json.GenericJson;
2328
import com.google.cloud.firestore.FirestoreOptions;
2429
import com.google.common.collect.ImmutableList;
30+
import com.google.common.io.ByteStreams;
2531
import com.google.common.io.CharStreams;
2632
import com.google.firebase.FirebaseApp;
2733
import com.google.firebase.FirebaseOptions;
28-
import com.google.firebase.FirebaseOptions.Builder;
2934
import com.google.firebase.TestOnlyImplFirebaseTrampolines;
3035
import com.google.firebase.database.DatabaseReference;
3136
import com.google.firebase.database.FirebaseDatabase;
@@ -35,13 +40,6 @@
3540
import java.io.InputStream;
3641
import java.io.InputStreamReader;
3742
import java.util.List;
38-
import org.apache.http.HttpEntity;
39-
import org.apache.http.HttpResponse;
40-
import org.apache.http.client.HttpClient;
41-
import org.apache.http.client.methods.HttpPut;
42-
import org.apache.http.entity.StringEntity;
43-
import org.apache.http.impl.client.DefaultHttpClient;
44-
import org.apache.http.util.EntityUtils;
4543

4644
public class IntegrationTestUtils {
4745

@@ -151,26 +149,34 @@ public static List<DatabaseReference> getRandomNode(FirebaseApp app, int count)
151149
}
152150

153151
public static class AppHttpClient {
154-
152+
155153
private final FirebaseApp app;
154+
private final FirebaseOptions options;
155+
private final HttpRequestFactory requestFactory;
156156

157157
public AppHttpClient() {
158158
this(FirebaseApp.getInstance());
159159
}
160160

161161
public AppHttpClient(FirebaseApp app) {
162162
this.app = checkNotNull(app);
163+
this.options = app.getOptions();
164+
this.requestFactory = this.options.getHttpTransport().createRequestFactory();
163165
}
164166

165-
public ResponseInfo put(String path, String data) throws IOException {
166-
String url = app.getOptions().getDatabaseUrl() + path + "?access_token=" + getToken();
167-
HttpPut put = new HttpPut(url);
168-
HttpEntity entity = new StringEntity(data, "UTF-8");
169-
put.setEntity(entity);
170-
171-
HttpClient httpClient = new DefaultHttpClient();
172-
HttpResponse response = httpClient.execute(put);
173-
return new ResponseInfo(response);
167+
public ResponseInfo put(String path, String json) throws IOException {
168+
String url = options.getDatabaseUrl() + path + "?access_token=" + getToken();
169+
HttpRequest request = requestFactory.buildPutRequest(new GenericUrl(url),
170+
ByteArrayContent.fromString("application/json", json));
171+
HttpResponse response = null;
172+
try {
173+
response = request.execute();
174+
return new ResponseInfo(response);
175+
} finally {
176+
if (response != null) {
177+
response.disconnect();
178+
}
179+
}
174180
}
175181

176182
private String getToken() {
@@ -185,8 +191,8 @@ public static class ResponseInfo {
185191
private final byte[] payload;
186192

187193
private ResponseInfo(HttpResponse response) throws IOException {
188-
this.status = response.getStatusLine().getStatusCode();
189-
this.payload = EntityUtils.toByteArray(response.getEntity());
194+
this.status = response.getStatusCode();
195+
this.payload = ByteStreams.toByteArray(response.getContent());
190196
}
191197

192198
public int getStatus() {

0 commit comments

Comments
 (0)