Skip to content

Commit 2266889

Browse files
committed
Addressing rayo's comments
1 parent bb37ff1 commit 2266889

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

firebase-installations/src/main/java/com/google/firebase/installations/Utils.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ private Utils(Clock clock) {
4141

4242
// Factory method that always returns the same Utils instance.
4343
public static Utils getInstance() {
44-
if (singleton == null) {
45-
singleton = new Utils(SystemClock.getInstance());
46-
}
47-
return singleton;
44+
return getInstance(SystemClock.getInstance());
4845
}
4946

50-
public static Utils getTestInstance(Clock clock) {
47+
/**
48+
* Returns an Utils instance. {@link Utils#getInstance()} defines the clock used. NOTE: If a Utils
49+
* instance has already been initialized, the parameter will be ignored and the existing instance
50+
* will be returned.
51+
*/
52+
public static Utils getInstance(Clock clock) {
5153
if (singleton == null) {
5254
singleton = new Utils(clock);
5355
}

firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.firebase.inject.Provider;
3434
import com.google.firebase.installations.FirebaseInstallationsException;
3535
import com.google.firebase.installations.FirebaseInstallationsException.Status;
36-
import com.google.firebase.installations.Utils;
3736
import com.google.firebase.installations.remote.InstallationResponse.ResponseCode;
3837
import com.google.firebase.platforminfo.UserAgentPublisher;
3938
import java.io.BufferedReader;
@@ -115,7 +114,7 @@ public FirebaseInstallationServiceClient(
115114
this.context = context;
116115
this.userAgentPublisher = publisher;
117116
this.heartbeatInfo = heartbeatInfo;
118-
this.requestLimiter = new RequestLimiter(Utils.getInstance());
117+
this.requestLimiter = new RequestLimiter();
119118
}
120119

121120
/**

firebase-installations/src/main/java/com/google/firebase/installations/remote/RequestLimiter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class RequestLimiter {
4242
this.utils = utils;
4343
}
4444

45+
RequestLimiter() {
46+
// Util class is injected to ease mocking & testing the system time.
47+
this.utils = Utils.getInstance();
48+
}
49+
4550
// Based on the response code, calculates the next request time to communicate with the FIS
4651
// servers.
4752
public synchronized void setNextRequestTime(int responseCode) {

firebase-installations/src/test/java/com/google/firebase/installations/FirebaseInstallationsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void setUp() {
152152
persistedInstallation.clearForTesting();
153153

154154
fakeClock = new FakeClock(5000000L);
155-
utils = Utils.getTestInstance(fakeClock);
155+
utils = Utils.getInstance(fakeClock);
156156
firebaseInstallations =
157157
new FirebaseInstallations(
158158
executor,

0 commit comments

Comments
 (0)