File tree Expand file tree Collapse file tree 4 files changed +14
-8
lines changed
firebase-installations/src
main/java/com/google/firebase/installations
test/java/com/google/firebase/installations Expand file tree Collapse file tree 4 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,15 @@ private Utils(Clock clock) {
41
41
42
42
// Factory method that always returns the same Utils instance.
43
43
public static Utils getInstance () {
44
- if (singleton == null ) {
45
- singleton = new Utils (SystemClock .getInstance ());
46
- }
47
- return singleton ;
44
+ return getInstance (SystemClock .getInstance ());
48
45
}
49
46
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 ) {
51
53
if (singleton == null ) {
52
54
singleton = new Utils (clock );
53
55
}
Original file line number Diff line number Diff line change 33
33
import com .google .firebase .inject .Provider ;
34
34
import com .google .firebase .installations .FirebaseInstallationsException ;
35
35
import com .google .firebase .installations .FirebaseInstallationsException .Status ;
36
- import com .google .firebase .installations .Utils ;
37
36
import com .google .firebase .installations .remote .InstallationResponse .ResponseCode ;
38
37
import com .google .firebase .platforminfo .UserAgentPublisher ;
39
38
import java .io .BufferedReader ;
@@ -115,7 +114,7 @@ public FirebaseInstallationServiceClient(
115
114
this .context = context ;
116
115
this .userAgentPublisher = publisher ;
117
116
this .heartbeatInfo = heartbeatInfo ;
118
- this .requestLimiter = new RequestLimiter (Utils . getInstance () );
117
+ this .requestLimiter = new RequestLimiter ();
119
118
}
120
119
121
120
/**
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ class RequestLimiter {
42
42
this .utils = utils ;
43
43
}
44
44
45
+ RequestLimiter () {
46
+ // Util class is injected to ease mocking & testing the system time.
47
+ this .utils = Utils .getInstance ();
48
+ }
49
+
45
50
// Based on the response code, calculates the next request time to communicate with the FIS
46
51
// servers.
47
52
public synchronized void setNextRequestTime (int responseCode ) {
Original file line number Diff line number Diff line change @@ -152,7 +152,7 @@ public void setUp() {
152
152
persistedInstallation .clearForTesting ();
153
153
154
154
fakeClock = new FakeClock (5000000L );
155
- utils = Utils .getTestInstance (fakeClock );
155
+ utils = Utils .getInstance (fakeClock );
156
156
firebaseInstallations =
157
157
new FirebaseInstallations (
158
158
executor ,
You can’t perform that action at this time.
0 commit comments