Skip to content

Commit 00956bc

Browse files
authored
Set firebase-database to -Werror (#1030)
* Set compile options to -Werror * Fix all build breaks
1 parent 7a61f82 commit 00956bc

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

+241
-232
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;
@@ -712,7 +714,7 @@ public boolean isComplete(List<EventRecord> events) {
712714
try {
713715
ref.child("two").removeValue();
714716
} catch (DatabaseException e) {
715-
fail("Should not fail");
717+
throw new AssertionError("Should not fail", e);
716718
}
717719
}
718720
return events.size() == 2;
@@ -2350,9 +2352,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
23502352
assertEquals(snap.getPriority().getClass(), Double.class);
23512353
assertEquals(snap.getPriority(), snap.child("b").getPriority());
23522354
assertEquals(snap.child("a").getValue(), snap.child("b").getValue());
2353-
assert (Math.abs(
2354-
System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()))
2355-
< 2000);
2355+
long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString());
2356+
assertThat(Math.abs(drift), lessThan(2000l));
23562357
}
23572358

23582359
@Test
@@ -2416,7 +2417,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
24162417

24172418
IntegrationTestHelpers.waitFor(valSemaphore);
24182419

2419-
assert (Math.abs(System.currentTimeMillis() - priority.get()) < 2000);
2420+
long drift = System.currentTimeMillis() - priority.get();
2421+
assertThat(Math.abs(drift), lessThan(2000l));
24202422
}
24212423

24222424
@Test
@@ -2482,9 +2484,9 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
24822484
DataSnapshot snap = readerEventRecord.getSnapshot();
24832485
assertEquals(snap.child("a/b/c").getValue().getClass(), Long.class);
24842486
assertEquals(snap.child("a/b/d").getValue().getClass(), Long.class);
2485-
assert (Math.abs(
2486-
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString()))
2487-
< 2000);
2487+
long drift =
2488+
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString());
2489+
assertThat(Math.abs(drift), lessThan(2000l));
24882490
}
24892491

24902492
@Test
@@ -2538,9 +2540,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
25382540
assertEquals(snap.getPriority().getClass(), Double.class);
25392541
assertEquals(snap.getPriority(), snap.child("b").getPriority());
25402542
assertEquals(snap.child("a").getValue(), snap.child("b").getValue());
2541-
assert (Math.abs(
2542-
System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString()))
2543-
< 2000);
2543+
long drift = System.currentTimeMillis() - Long.parseLong(snap.child("a").getValue().toString());
2544+
assertThat(Math.abs(drift), lessThan(2000l));
25442545
}
25452546

25462547
@Test
@@ -2603,7 +2604,8 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
26032604

26042605
IntegrationTestHelpers.waitFor(valSemaphore);
26052606

2606-
assert (Math.abs(System.currentTimeMillis() - priority.get()) < 2000);
2607+
long drift = System.currentTimeMillis() - priority.get();
2608+
assertThat(Math.abs(drift), lessThan(2000l));
26072609
}
26082610

26092611
@Test
@@ -2667,9 +2669,9 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
26672669
DataSnapshot snap = readerEventRecord.getSnapshot();
26682670
assertEquals(snap.child("a/b/c").getValue().getClass(), Long.class);
26692671
assertEquals(snap.child("a/b/d").getValue().getClass(), Long.class);
2670-
assert (Math.abs(
2671-
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString()))
2672-
< 2000);
2672+
long drift =
2673+
System.currentTimeMillis() - Long.parseLong(snap.child("a/b/c").getValue().toString());
2674+
assertThat(Math.abs(drift), lessThan(2000l));
26732675
}
26742676

26752677
@Test
@@ -2714,7 +2716,7 @@ public Transaction.Result doTransaction(MutableData currentData) {
27142716
try {
27152717
currentData.setValue(ServerValue.TIMESTAMP);
27162718
} catch (DatabaseException e) {
2717-
fail("Should not fail");
2719+
throw new AssertionError("Should not fail", e);
27182720
}
27192721
return Transaction.success(currentData);
27202722
}
@@ -2734,14 +2736,14 @@ public void onComplete(DatabaseError error, boolean committed, DataSnapshot curr
27342736
EventRecord writerEventRecord = writerFuture.timedGet().get(1);
27352737
DataSnapshot snap1 = writerEventRecord.getSnapshot();
27362738
assertEquals(snap1.getValue().getClass(), Long.class);
2737-
assert (Math.abs(System.currentTimeMillis() - Long.parseLong(snap1.getValue().toString()))
2738-
< 2000);
2739+
long drift = System.currentTimeMillis() - Long.parseLong(snap1.getValue().toString());
2740+
assertThat(Math.abs(drift), lessThan(2000l));
27392741

27402742
EventRecord readerEventRecord = readerFuture.timedGet().get(1);
27412743
DataSnapshot snap2 = readerEventRecord.getSnapshot();
27422744
assertEquals(snap2.getValue().getClass(), Long.class);
2743-
assert (Math.abs(System.currentTimeMillis() - Long.parseLong(snap2.getValue().toString()))
2744-
< 2000);
2745+
drift = System.currentTimeMillis() - Long.parseLong(snap2.getValue().toString());
2746+
assertThat(Math.abs(drift), lessThan(2000l));
27452747
}
27462748

27472749
@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)