Skip to content

Commit fec7806

Browse files
committed
Fix all warnings
* Set compile options to -Werror * Fix all build breaks
1 parent c43ae16 commit fec7806

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+235
-226
lines changed

firebase-database/firebase-database.gradle

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ dependencies {
8484
androidTestImplementation "androidx.annotation:annotation:1.1.0"
8585
androidTestImplementation 'androidx.test:rules:1.2.0'
8686
androidTestImplementation 'androidx.test:runner:1.2.0'
87+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
8788
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
8889
androidTestImplementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'
8990
androidTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
9091
androidTestImplementation 'junit:junit:4.12'
92+
androidTestImplementation 'org.hamcrest:hamcrest:2.2'
93+
androidTestImplementation 'org.hamcrest:hamcrest-library:2.2'
9194
androidTestImplementation 'net.java:quickcheck:0.6'
92-
androidTestAnnotationProcessor 'net.java:quickcheck-src-generator:0.6'
93-
androidTestAnnotationProcessor 'net.java.quickcheck:quickcheck-src-generator:0.6'
94-
9595

9696
testImplementation 'junit:junit:4.12'
9797
testImplementation 'org.mockito:mockito-core:2.25.0'
@@ -101,8 +101,14 @@ dependencies {
101101
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
102102
testImplementation 'net.java.quickcheck:quickcheck:0.6'
103103
testImplementation "com.google.truth:truth:$googleTruthVersion"
104+
testImplementation 'androidx.test:core:1.2.0'
104105
testImplementation 'androidx.test:rules:1.2.0'
106+
}
105107

108+
gradle.projectsEvaluated {
109+
tasks.withType(JavaCompile) {
110+
options.compilerArgs << "-Xlint:deprecation" << "-Werror"
111+
}
106112
}
107113

108114
// ==========================================================================

firebase-database/src/androidTest/java/com/google/firebase/database/DataTest.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
package com.google.firebase.database;
1616

1717
import static java.util.concurrent.TimeUnit.MILLISECONDS;
18+
import static org.hamcrest.Matchers.lessThan;
1819
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertThat;
2224
import static org.junit.Assert.assertTrue;
2325
import static org.junit.Assert.fail;
2426

25-
import androidx.test.runner.AndroidJUnit4;
27+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2628
import com.google.firebase.database.core.DatabaseConfig;
2729
import com.google.firebase.database.core.Path;
2830
import com.google.firebase.database.core.RepoManager;
@@ -710,7 +712,7 @@ public boolean isComplete(List<EventRecord> events) {
710712
try {
711713
ref.child("two").removeValue();
712714
} catch (DatabaseException e) {
713-
fail("Should not fail");
715+
throw new AssertionError("Should not fail", e);
714716
}
715717
}
716718
return events.size() == 2;
@@ -2346,9 +2348,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
23462348
assertEquals(snap.getPriority().getClass(), Double.class);
23472349
assertEquals(snap.getPriority(), snap.child("b").getPriority());
23482350
assertEquals(snap.child("a").getValue(), snap.child("b").getValue());
2349-
assert (Math.abs(
2350-
System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()))
2351-
< 2000);
2351+
Long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString());
2352+
assertThat(Math.abs(drift), lessThan(2000l));
23522353
}
23532354

23542355
@Test
@@ -2412,7 +2413,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
24122413

24132414
IntegrationTestHelpers.waitFor(valSemaphore);
24142415

2415-
assert (Math.abs(System.currentTimeMillis() - priority.get()) < 2000);
2416+
long drift = System.currentTimeMillis() - priority.get();
2417+
assertThat(Math.abs(drift), lessThan(2000l));
24162418
}
24172419

24182420
@Test
@@ -2478,9 +2480,9 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
24782480
DataSnapshot snap = readerEventRecord.getSnapshot();
24792481
assertEquals(snap.child("a/b/c").getValue().getClass(), Long.class);
24802482
assertEquals(snap.child("a/b/d").getValue().getClass(), Long.class);
2481-
assert (Math.abs(
2482-
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString()))
2483-
< 2000);
2483+
long drift =
2484+
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString());
2485+
assertThat(Math.abs(drift), lessThan(2000l));
24842486
}
24852487

24862488
@Test
@@ -2534,9 +2536,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
25342536
assertEquals(snap.getPriority().getClass(), Double.class);
25352537
assertEquals(snap.getPriority(), snap.child("b").getPriority());
25362538
assertEquals(snap.child("a").getValue(), snap.child("b").getValue());
2537-
assert (Math.abs(
2538-
System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()))
2539-
< 2000);
2539+
long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString());
2540+
assertThat(Math.abs(drift), lessThan(2000l));
25402541
}
25412542

25422543
@Test
@@ -2599,7 +2600,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
25992600

26002601
IntegrationTestHelpers.waitFor(valSemaphore);
26012602

2602-
assert (Math.abs(System.currentTimeMillis() - priority.get()) < 2000);
2603+
long drift = System.currentTimeMillis() - priority.get();
2604+
assertThat(Math.abs(drift), lessThan(2000l));
26032605
}
26042606

26052607
@Test
@@ -2663,9 +2665,9 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
26632665
DataSnapshot snap = readerEventRecord.getSnapshot();
26642666
assertEquals(snap.child("a/b/c").getValue().getClass(), Long.class);
26652667
assertEquals(snap.child("a/b/d").getValue().getClass(), Long.class);
2666-
assert (Math.abs(
2667-
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString()))
2668-
< 2000);
2668+
long drift =
2669+
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString());
2670+
assertThat(Math.abs(drift), lessThan(2000l));
26692671
}
26702672

26712673
@Test
@@ -2710,7 +2712,7 @@ public Transaction.Result doTransaction(MutableData currentData) {
27102712
try {
27112713
currentData.setValue(ServerValue.TIMESTAMP);
27122714
} catch (DatabaseException e) {
2713-
fail("Should not fail");
2715+
throw new AssertionError("Should not fail", e);
27142716
}
27152717
return Transaction.success(currentData);
27162718
}
@@ -2730,14 +2732,14 @@ public void onComplete(DatabaseError error, boolean committed, DataSnapshot curr
27302732
EventRecord writerEventRecord = writerFuture.timedGet().get(1);
27312733
DataSnapshot snap1 = writerEventRecord.getSnapshot();
27322734
assertEquals(snap1.getValue().getClass(), Long.class);
2733-
assert (Math.abs(System.currentTimeMillis() - Long.parseLong(snap1.getValue().toString()))
2734-
< 2000);
2735+
long drift = System.currentTimeMillis() - Long.parseLong(snap1.getValue().toString());
2736+
assertThat(Math.abs(drift), lessThan(2000l));
27352737

27362738
EventRecord readerEventRecord = readerFuture.timedGet().get(1);
27372739
DataSnapshot snap2 = readerEventRecord.getSnapshot();
27382740
assertEquals(snap2.getValue().getClass(), Long.class);
2739-
assert (Math.abs(System.currentTimeMillis() - Long.parseLong(snap2.getValue().toString()))
2740-
< 2000);
2741+
drift = System.currentTimeMillis() - Long.parseLong(snap2.getValue().toString());
2742+
assertThat(Math.abs(drift), lessThan(2000l));
27412743
}
27422744

27432745
@Test

firebase-database/src/androidTest/java/com/google/firebase/database/EventTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
package com.google.firebase.database;
1616

17+
import static java.util.logging.Level.WARNING;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertNull;
1920
import static org.junit.Assert.assertTrue;
2021
import static org.junit.Assert.fail;
2122

22-
import androidx.test.runner.AndroidJUnit4;
23+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2324
import com.google.firebase.database.core.ZombieVerifier;
2425
import com.google.firebase.database.core.view.Event;
2526
import com.google.firebase.database.future.ReadFuture;
@@ -33,12 +34,14 @@
3334
import java.util.concurrent.TimeoutException;
3435
import java.util.concurrent.atomic.AtomicBoolean;
3536
import java.util.concurrent.atomic.AtomicInteger;
37+
import java.util.logging.Logger;
3638
import org.junit.After;
3739
import org.junit.Rule;
3840
import org.junit.Test;
3941

4042
@org.junit.runner.RunWith(AndroidJUnit4.class)
4143
public class EventTest {
44+
private static Logger LOGGER = Logger.getLogger(EventTest.class.getName());
4245
@Rule public RetryRule retryRule = new RetryRule(3);
4346

4447
@After
@@ -623,15 +626,15 @@ public void onDataChange(DataSnapshot snapshot) {
623626
try {
624627
IntegrationTestHelpers.waitFor(blockSem);
625628
} catch (InterruptedException e) {
626-
e.printStackTrace();
629+
LOGGER.log(WARNING, "unexpected error", e);
627630
}
628631
ref.removeEventListener(this);
629632
try {
630633
// this doesn't block immediately because we are already on the repo thread.
631634
// we kick off the verify and let the unit test block on the endingsemaphore
632635
ZombieVerifier.verifyRepoZombies(ref, endingSemaphore);
633636
} catch (InterruptedException e) {
634-
e.printStackTrace();
637+
LOGGER.log(WARNING, "unexpected error", e);
635638
}
636639
}
637640
}
@@ -671,15 +674,15 @@ public void onDataChange(DataSnapshot snapshot) {
671674
try {
672675
IntegrationTestHelpers.waitFor(blockSem);
673676
} catch (InterruptedException e) {
674-
e.printStackTrace();
677+
LOGGER.log(WARNING, "unexpected error", e);
675678
}
676679
ref.removeEventListener(this);
677680
try {
678681
// this doesn't block immediately because we are already on the repo thread.
679682
// we kick off the verify and let the unit test block on the endingsemaphore
680683
ZombieVerifier.verifyRepoZombies(ref, endingSemaphore);
681684
} catch (InterruptedException e) {
682-
e.printStackTrace();
685+
LOGGER.log(WARNING, "unexpected error", e);
683686
}
684687
}
685688
}
@@ -720,15 +723,15 @@ public void onDataChange(DataSnapshot snapshot) {
720723
try {
721724
IntegrationTestHelpers.waitFor(blockSem);
722725
} catch (InterruptedException e) {
723-
e.printStackTrace();
726+
LOGGER.log(WARNING, "unexpected error", e);
724727
}
725728
ref.removeEventListener(this);
726729
try {
727730
// this doesn't block immediately because we are already on the repo thread.
728731
// we kick off the verify and let the unit test block on the endingsemaphore
729732
ZombieVerifier.verifyRepoZombies(ref, endingSemaphore);
730733
} catch (InterruptedException e) {
731-
e.printStackTrace();
734+
LOGGER.log(WARNING, "unexpected error", e);
732735
}
733736
}
734737
}
@@ -769,15 +772,15 @@ public void onChildAdded(DataSnapshot snapshot, String previousChildName) {
769772
try {
770773
IntegrationTestHelpers.waitFor(blockSem);
771774
} catch (InterruptedException e) {
772-
e.printStackTrace();
775+
LOGGER.log(WARNING, "unexpected error", e);
773776
}
774777
ref.removeEventListener(this);
775778
try {
776779
// this doesn't block immediately because we are already on the repo thread.
777780
// we kick off the verify and let the unit test block on the endingsemaphore
778781
ZombieVerifier.verifyRepoZombies(ref, endingSemaphore);
779782
} catch (InterruptedException e) {
780-
e.printStackTrace();
783+
LOGGER.log(WARNING, "unexpected error", e);
781784
}
782785
}
783786
}

firebase-database/src/androidTest/java/com/google/firebase/database/FirebaseDatabaseTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import static org.junit.Assert.assertSame;
2121
import static org.junit.Assert.fail;
2222

23-
import androidx.test.InstrumentationRegistry;
24-
import androidx.test.runner.AndroidJUnit4;
23+
import androidx.test.ext.junit.runners.AndroidJUnit4;
24+
import androidx.test.platform.app.InstrumentationRegistry;
2525
import com.google.firebase.FirebaseApp;
2626
import com.google.firebase.FirebaseOptions;
2727
import com.google.firebase.database.core.DatabaseConfig;
@@ -566,7 +566,7 @@ private static FirebaseApp emptyApp(String appId) {
566566

567567
private static FirebaseApp appForDatabaseUrl(String url, String name) {
568568
return FirebaseApp.initializeApp(
569-
InstrumentationRegistry.getTargetContext(),
569+
InstrumentationRegistry.getInstrumentation().getTargetContext(),
570570
new FirebaseOptions.Builder()
571571
.setApplicationId("appid")
572572
.setApiKey("apikey")

firebase-database/src/androidTest/java/com/google/firebase/database/InfoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.junit.Assert.assertTrue;
2020
import static org.junit.Assert.fail;
2121

22-
import androidx.test.runner.AndroidJUnit4;
22+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2323
import com.google.firebase.database.core.DatabaseConfig;
2424
import com.google.firebase.database.core.RepoManager;
2525
import com.google.firebase.database.future.ReadFuture;

firebase-database/src/androidTest/java/com/google/firebase/database/IntegrationTestHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public static String getTestSecret() {
300300
Map<String, Object> data = new ObjectMapper().readValue(response, t);
301301
testSecret = (String) ((List) data.get("secrets")).get(0);
302302
} catch (Throwable e) {
303-
fail("Could not get test secret.");
303+
throw new AssertionError("Could not get test secret. ", e);
304304
}
305305
}
306306
return testSecret;

firebase-database/src/androidTest/java/com/google/firebase/database/IntegrationTestValues.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package com.google.firebase.database;
1616

1717
import android.content.Context;
18-
import androidx.test.InstrumentationRegistry;
18+
import androidx.test.platform.app.InstrumentationRegistry;
1919

2020
public class IntegrationTestValues {
2121
private static final String TEST_ALT_NAMESPACE = "https://test.firebaseio.com";
@@ -25,7 +25,7 @@ public class IntegrationTestValues {
2525
private IntegrationTestValues() {}
2626

2727
public static String getNamespace() {
28-
Context c = InstrumentationRegistry.getContext();
28+
Context c = InstrumentationRegistry.getInstrumentation().getContext();
2929
return c.getResources().getString(R.string.firebase_database_url);
3030
}
3131

@@ -34,7 +34,7 @@ public static String getAltNamespace() {
3434
}
3535

3636
public static String getProjectId() {
37-
Context c = InstrumentationRegistry.getContext();
37+
Context c = InstrumentationRegistry.getInstrumentation().getContext();
3838
return c.getResources().getString(R.string.project_id);
3939
}
4040

firebase-database/src/androidTest/java/com/google/firebase/database/ObjectMapTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import static org.junit.Assert.assertTrue;
1919
import static org.junit.Assert.fail;
2020

21-
import androidx.test.runner.AndroidJUnit4;
21+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2222
import com.google.firebase.database.snapshot.EmptyNode;
2323
import java.io.IOException;
2424
import java.util.ArrayList;
@@ -61,6 +61,11 @@ public String toString() {
6161
public boolean equals(Object o) {
6262
return (o instanceof Author) && ((Author) o).name.equals(name) && ((Author) o).id == id;
6363
}
64+
65+
@Override
66+
public int hashCode() {
67+
return 31 * name.hashCode() + Integer.hashCode(id);
68+
}
6469
}
6570

6671
@ThrowOnExtraProperties
@@ -95,6 +100,11 @@ public boolean equals(Object o) {
95100
&& (((((Message) o).author == null) && (author == null))
96101
|| ((Message) o).author.equals(author));
97102
}
103+
104+
@Override
105+
public int hashCode() {
106+
return 31 * text.hashCode() + author.hashCode();
107+
}
98108
}
99109

100110
private MutableData emptyData() {

firebase-database/src/androidTest/java/com/google/firebase/database/OrderByTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import static org.junit.Assert.assertEquals;
1818

19-
import androidx.test.runner.AndroidJUnit4;
19+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2020
import com.google.firebase.database.future.ReadFuture;
2121
import com.google.firebase.database.future.WriteFuture;
2222
import java.util.ArrayList;
@@ -27,7 +27,7 @@
2727
import java.util.concurrent.ExecutionException;
2828
import java.util.concurrent.Semaphore;
2929
import java.util.concurrent.TimeoutException;
30-
import junit.framework.Assert;
30+
import org.junit.Assert;
3131
import org.junit.Rule;
3232
import org.junit.Test;
3333

firebase-database/src/androidTest/java/com/google/firebase/database/OrderTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.junit.Assert.assertTrue;
2020
import static org.junit.Assert.fail;
2121

22-
import androidx.test.runner.AndroidJUnit4;
22+
import androidx.test.ext.junit.runners.AndroidJUnit4;
2323
import com.google.firebase.database.core.view.Event;
2424
import com.google.firebase.database.future.ReadFuture;
2525
import com.google.firebase.database.future.WriteFuture;
@@ -170,10 +170,9 @@ public void pushDataWithExponentialPriorityAndCheckOrder()
170170
DatabaseReference reader = refs.get(1);
171171

172172
for (int i = 0; i < 9; ++i) {
173-
writer.push().setValue(i, 111111111111111111111111111111.0 / Math.pow(10, i));
173+
writer.push().setValue(i, Float.MAX_VALUE / Math.pow(10, i));
174174
}
175-
new WriteFuture(writer.push(), 9, 111111111111111111111111111111.0 / Math.pow(10, 9))
176-
.timedGet();
175+
new WriteFuture(writer.push(), 9, Float.MAX_VALUE / Math.pow(10, 9)).timedGet();
177176

178177
DataSnapshot snap = IntegrationTestHelpers.getSnap(writer);
179178
long i = 9;

0 commit comments

Comments
 (0)