Skip to content

Commit aa3c89f

Browse files
Fix remaining lint failures (mostly in tests) (#2025)
1 parent eb7cae1 commit aa3c89f

File tree

7 files changed

+83
-38
lines changed

7 files changed

+83
-38
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.database;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
1718
import static com.google.firebase.database.snapshot.NodeUtilities.NodeFromJSON;
1819
import static org.junit.Assert.assertTrue;
1920
import static org.junit.Assert.fail;
@@ -109,7 +110,7 @@ public static Node leafNodeOfSize(int size) {
109110
}
110111
int remainingLength = size - builder.length();
111112
builder.append(pattern.substring(0, remainingLength));
112-
assert builder.length() == size : "The string size did not match the expected size";
113+
hardAssert(builder.length() == size, "The string size did not match the expected size");
113114
return NodeFromJSON(builder.toString());
114115
}
115116

firebase-database/src/androidTest/java/com/google/firebase/database/snapshot/CompoundHashingIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.database.snapshot;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertFalse;
1920

@@ -81,7 +82,7 @@ private static void forEachLeaf(
8182
} else if (node.isEmpty()) {
8283
// ignore
8384
} else {
84-
assert node instanceof ChildrenNode;
85+
hardAssert(node instanceof ChildrenNode);
8586
((ChildrenNode) node)
8687
.forEachChild(
8788
new ChildrenNode.ChildVisitor() {

firebase-database/src/main/java/com/google/firebase/database/android/SqlPersistenceStorageEngine.java

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.HashMap;
5252
import java.util.HashSet;
5353
import java.util.List;
54+
import java.util.Locale;
5455
import java.util.Map;
5556
import java.util.Set;
5657

@@ -223,7 +224,7 @@ public void saveUserOverwrite(Path path, Node node, long writeId) {
223224
saveWrite(path, writeId, WRITE_TYPE_OVERWRITE, serializedNode);
224225
long duration = System.currentTimeMillis() - start;
225226
if (logger.logsDebug()) {
226-
logger.debug(String.format("Persisted user overwrite in %dms", duration));
227+
logger.debug(String.format(Locale.US, "Persisted user overwrite in %dms", duration));
227228
}
228229
}
229230

@@ -235,7 +236,7 @@ public void saveUserMerge(Path path, CompoundWrite children, long writeId) {
235236
saveWrite(path, writeId, WRITE_TYPE_MERGE, serializedNode);
236237
long duration = System.currentTimeMillis() - start;
237238
if (logger.logsDebug()) {
238-
logger.debug(String.format("Persisted user merge in %dms", duration));
239+
logger.debug(String.format(Locale.US, "Persisted user merge in %dms", duration));
239240
}
240241
}
241242

@@ -247,7 +248,8 @@ public void removeUserWrite(long writeId) {
247248
long duration = System.currentTimeMillis() - start;
248249
if (logger.logsDebug()) {
249250
logger.debug(
250-
String.format("Deleted %d write(s) with writeId %d in %dms", count, writeId, duration));
251+
String.format(
252+
Locale.US, "Deleted %d write(s) with writeId %d in %dms", count, writeId, duration));
251253
}
252254
}
253255

@@ -309,7 +311,7 @@ record = new UserWriteRecord(writeId, path, merge);
309311
}
310312
long duration = System.currentTimeMillis() - start;
311313
if (logger.logsDebug()) {
312-
logger.debug(String.format("Loaded %d writes in %dms", writes.size(), duration));
314+
logger.debug(String.format(Locale.US, "Loaded %d writes in %dms", writes.size(), duration));
313315
}
314316
return writes;
315317
} catch (IOException e) {
@@ -381,8 +383,12 @@ private void updateServerCache(Path path, Node node, boolean merge) {
381383
if (logger.logsDebug()) {
382384
logger.debug(
383385
String.format(
386+
Locale.US,
384387
"Persisted a total of %d rows and deleted %d rows for a set at %s in %dms",
385-
savedRows, removedRows, path.toString(), duration));
388+
savedRows,
389+
removedRows,
390+
path.toString(),
391+
duration));
386392
}
387393
}
388394

@@ -400,8 +406,12 @@ public void mergeIntoServerCache(Path path, CompoundWrite children) {
400406
if (logger.logsDebug()) {
401407
logger.debug(
402408
String.format(
409+
Locale.US,
403410
"Persisted a total of %d rows and deleted %d rows for a merge at %s in %dms",
404-
savedRows, removedRows, path.toString(), duration));
411+
savedRows,
412+
removedRows,
413+
path.toString(),
414+
duration));
405415
}
406416
}
407417

@@ -438,7 +448,7 @@ public void saveTrackedQuery(TrackedQuery trackedQuery) {
438448
TRACKED_QUERY_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
439449
long duration = System.currentTimeMillis() - start;
440450
if (logger.logsDebug()) {
441-
logger.debug(String.format("Saved new tracked query in %dms", duration));
451+
logger.debug(String.format(Locale.US, "Saved new tracked query in %dms", duration));
442452
}
443453
}
444454

@@ -496,7 +506,9 @@ public List<TrackedQuery> loadTrackedQueries() {
496506
}
497507
long duration = System.currentTimeMillis() - start;
498508
if (logger.logsDebug()) {
499-
logger.debug(String.format("Loaded %d tracked queries in %dms", queries.size(), duration));
509+
logger.debug(
510+
String.format(
511+
Locale.US, "Loaded %d tracked queries in %dms", queries.size(), duration));
500512
}
501513
return queries;
502514
} finally {
@@ -519,7 +531,7 @@ public void resetPreviouslyActiveTrackedQueries(long lastUse) {
519531
TRACKED_QUERY_TABLE, values, whereClause, new String[] {}, SQLiteDatabase.CONFLICT_REPLACE);
520532
long duration = System.currentTimeMillis() - start;
521533
if (logger.logsDebug()) {
522-
logger.debug(String.format("Reset active tracked queries in %dms", duration));
534+
logger.debug(String.format(Locale.US, "Reset active tracked queries in %dms", duration));
523535
}
524536
}
525537

@@ -544,8 +556,11 @@ public void saveTrackedQueryKeys(long trackedQueryId, Set<ChildKey> keys) {
544556
if (logger.logsDebug()) {
545557
logger.debug(
546558
String.format(
559+
Locale.US,
547560
"Set %d tracked query keys for tracked query %d in %dms",
548-
keys.size(), trackedQueryId, duration));
561+
keys.size(),
562+
trackedQueryId,
563+
duration));
549564
}
550565
}
551566

@@ -572,8 +587,12 @@ public void updateTrackedQueryKeys(
572587
if (logger.logsDebug()) {
573588
logger.debug(
574589
String.format(
590+
Locale.US,
575591
"Updated tracked query keys (%d added, %d removed) for tracked query id %d in %dms",
576-
added.size(), removed.size(), trackedQueryId, duration));
592+
added.size(),
593+
removed.size(),
594+
trackedQueryId,
595+
duration));
577596
}
578597
}
579598

@@ -610,8 +629,11 @@ public Set<ChildKey> loadTrackedQueryKeys(Set<Long> trackedQueryIds) {
610629
if (logger.logsDebug()) {
611630
logger.debug(
612631
String.format(
632+
Locale.US,
613633
"Loaded %d tracked queries keys for tracked queries %s in %dms",
614-
keys.size(), trackedQueryIds.toString(), duration));
634+
keys.size(),
635+
trackedQueryIds.toString(),
636+
duration));
615637
}
616638
return keys;
617639
} finally {
@@ -681,7 +703,11 @@ public void pruneCache(Path root, PruneForest pruneForest) {
681703
if (logger.logsDebug()) {
682704
logger.debug(
683705
String.format(
684-
"Pruned %d rows with %d nodes resaved in %dms", prunedCount, resavedCount, duration));
706+
Locale.US,
707+
"Pruned %d rows with %d nodes resaved in %dms",
708+
prunedCount,
709+
resavedCount,
710+
duration));
685711
}
686712
}
687713

@@ -709,7 +735,11 @@ public Integer onNodeValue(Path keepPath, Void ignore, Integer nodesToResave) {
709735
Path absolutePath = pruneRoot.child(relativePath);
710736
if (logger.logsDebug()) {
711737
logger.debug(
712-
String.format("Need to rewrite %d nodes below path %s", nodesToResave, absolutePath));
738+
String.format(
739+
Locale.US,
740+
"Need to rewrite %d nodes below path %s",
741+
nodesToResave,
742+
absolutePath));
713743
}
714744
final Node currentNode = loadNested(absolutePath);
715745
pruneForest.foldKeptNodes(
@@ -750,7 +780,7 @@ public void removeAllUserWrites() {
750780
int count = database.delete(WRITES_TABLE, null, null);
751781
long duration = System.currentTimeMillis() - start;
752782
if (logger.logsDebug()) {
753-
logger.debug(String.format("Deleted %d (all) write(s) in %dms", count, duration));
783+
logger.debug(String.format(Locale.US, "Deleted %d (all) write(s) in %dms", count, duration));
754784
}
755785
}
756786

@@ -781,7 +811,7 @@ public void endTransaction() {
781811
insideTransaction = false;
782812
long elapsed = System.currentTimeMillis() - transactionStart;
783813
if (logger.logsDebug()) {
784-
logger.debug(String.format("Transaction completed. Elapsed: %dms", elapsed));
814+
logger.debug(String.format(Locale.US, "Transaction completed. Elapsed: %dms", elapsed));
785815
}
786816
}
787817

@@ -854,9 +884,12 @@ private int saveNested(Path path, Node node) {
854884
if (logger.logsDebug()) {
855885
logger.debug(
856886
String.format(
887+
Locale.US,
857888
"Node estimated serialized size at path %s of %d bytes exceeds limit of %d bytes. "
858889
+ "Splitting up.",
859-
path, estimatedSize, CHILDREN_NODE_SPLIT_SIZE_THRESHOLD));
890+
path,
891+
estimatedSize,
892+
CHILDREN_NODE_SPLIT_SIZE_THRESHOLD));
860893
}
861894
// split up the children node into multiple nodes
862895
int sum = 0;
@@ -881,7 +914,7 @@ private int saveNested(Path path, Node node) {
881914
}
882915

883916
private String partKey(Path path, int i) {
884-
return pathToKey(path) + String.format(PART_KEY_FORMAT, i);
917+
return pathToKey(path) + String.format(Locale.US, PART_KEY_FORMAT, i);
885918
}
886919

887920
private void saveNode(Path path, Node node) {
@@ -984,6 +1017,7 @@ private Node loadNested(Path path) {
9841017
if (logger.logsDebug()) {
9851018
logger.debug(
9861019
String.format(
1020+
Locale.US,
9871021
"Loaded a total of %d rows for a total of %d nodes at %s in %dms "
9881022
+ "(Query: %dms, Loading: %dms, Serializing: %dms)",
9891023
payloads.size(),

firebase-database/src/test/java/com/google/firebase/database/core/SyncPointTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.fasterxml.jackson.databind.ObjectMapper;
1820
import com.google.firebase.database.DataSnapshot;
1921
import com.google.firebase.database.DatabaseError;
@@ -66,15 +68,15 @@ public void startListening(
6668
SyncTree.CompletionListener onListenComplete) {
6769
Path path = query.getPath();
6870
logger.debug("Listening at " + path + " for Tag " + tag + ")");
69-
assert !listens.contains(query) : "Duplicate listen";
71+
hardAssert(!listens.contains(query), "Duplicate listen");
7072
this.listens.add(query);
7173
}
7274

7375
@Override
7476
public void stopListening(QuerySpec query, Tag tag) {
7577
Path path = query.getPath();
7678
logger.debug("Stop listening at " + path + " for Tag " + tag + ")");
77-
assert this.listens.contains(query) : "Stopped listening for query already";
79+
hardAssert(this.listens.contains(query), "Stopped listening for query already");
7880
this.listens.remove(query);
7981
}
8082
};

firebase-database/src/test/java/com/google/firebase/database/core/persistence/RandomPersistenceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.database.core.persistence;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertTrue;
1920

@@ -116,7 +117,7 @@ private void applyOperation(SyncTree syncTree, Operation operation, Map<QuerySpe
116117
if (operation.getSource().isTagged()) {
117118
Tag tag =
118119
tagMap.get(new QuerySpec(operation.getPath(), operation.getSource().getQueryParams()));
119-
assert tag != null;
120+
hardAssert(tag != null);
120121
switch (operation.getType()) {
121122
case ListenComplete:
122123
{

firebase-database/src/testUtil/java/com/google/firebase/database/core/RandomOperationGenerator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.database.core;
1616

17+
import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
18+
1719
import com.google.firebase.database.core.operation.AckUserWrite;
1820
import com.google.firebase.database.core.operation.ListenComplete;
1921
import com.google.firebase.database.core.operation.Merge;
@@ -285,7 +287,7 @@ public CacheNode getExpectedClientState(QueryParams params) {
285287
private Operation getAck() {
286288
WriteOp op = this.writeOpForLastUpdate;
287289
WriteOp frontOp = outstandingWrites.remove();
288-
assert op == frontOp : "The write op should be the front of the queue";
290+
hardAssert(op == frontOp, "The write op should be the front of the queue");
289291
writeTree.removeWrite(op.writeId);
290292
this.writeOpForLastUpdate = null;
291293
return getAckForWrite(op.operation, /*revert=*/ false);
@@ -296,7 +298,7 @@ private Operation getAckForWrite(Operation writeOp, boolean revert) {
296298
Overwrite overwrite = (Overwrite) writeOp;
297299
return new AckUserWrite(overwrite.getPath(), new ImmutableTree<Boolean>(true), revert);
298300
} else {
299-
assert (writeOp.getType() == Operation.OperationType.Merge);
301+
hardAssert(writeOp.getType() == Operation.OperationType.Merge);
300302
Merge merge = (Merge) writeOp;
301303
ImmutableTree<Boolean> affectedTree = ImmutableTree.emptyInstance();
302304
for (Map.Entry<Path, Node> entry : merge.getChildren()) {
@@ -465,7 +467,8 @@ private Map<ChildKey, Node> getMergeMap(Merge merge) {
465467
merge.getChildren().childCompoundWrites().entrySet()) {
466468
ChildKey key = entry.getKey();
467469
CompoundWrite childWrite = entry.getValue();
468-
assert childWrite.rootWrite() != null : "This is a deep overwrite, which is not supported";
470+
hardAssert(
471+
childWrite.rootWrite() != null, "This is a deep overwrite, which is not supported");
469472
map.put(key, childWrite.rootWrite());
470473
}
471474
return map;
@@ -485,7 +488,7 @@ private Overwrite getRandomOverwrite(OperationSource source) {
485488
}
486489

487490
private static Operation userOperationToServerOperation(Operation operation) {
488-
assert operation.getSource().isFromUser();
491+
hardAssert(operation.getSource().isFromUser());
489492
switch (operation.getType()) {
490493
case Overwrite:
491494
{

0 commit comments

Comments
 (0)