Skip to content

Commit 7e59264

Browse files
authored
changed the instrumentation tests into unit tests (#1053)
* changed the instrumentation tests into unit tests unit tests are easier and faster to run and debug the unit tests are also included in the code coverage tests * remove the FirebaseInstallations instrumentation tests These have been moved into unit tests and so are no longer needed. Also removed constants that are no longer referenced. * fix a format error
1 parent 2840a51 commit 7e59264

File tree

8 files changed

+1039
-899
lines changed

8 files changed

+1039
-899
lines changed

firebase-installations/firebase-installations.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ dependencies {
5353
testImplementation 'junit:junit:4.12'
5454
testImplementation "org.robolectric:robolectric:$robolectricVersion"
5555
testImplementation "com.google.truth:truth:$googleTruthVersion"
56-
56+
testImplementation 'org.mockito:mockito-core:2.25.0'
57+
testImplementation 'org.mockito:mockito-inline:2.25.0'
5758

5859
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
5960
androidTestImplementation 'androidx.test:runner:1.2.0'
6061
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
6162
androidTestImplementation 'junit:junit:4.12'
6263
androidTestImplementation "androidx.annotation:annotation:1.0.0"
6364
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
64-
androidTestImplementation 'org.mockito:mockito-android:2.25.0'
65+
androidTestImplementation 'org.mockito:mockito-inline:2.25.0'
6566
}

firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java

Lines changed: 0 additions & 849 deletions
This file was deleted.

firebase-installations/src/androidTest/java/com/google/firebase/installations/FisAndroidTestConstants.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,11 @@
1515
package com.google.firebase.installations;
1616

1717
import com.google.firebase.installations.local.PersistedInstallationEntry;
18-
import com.google.firebase.installations.remote.InstallationResponse;
19-
import com.google.firebase.installations.remote.InstallationResponse.ResponseCode;
20-
import com.google.firebase.installations.remote.TokenResult;
2118

2219
public final class FisAndroidTestConstants {
2320
public static final String TEST_FID_1 = "cccccccccccccccccccccc";
2421

25-
public static final String TEST_PROJECT_ID = "777777777777";
26-
2722
public static final String TEST_AUTH_TOKEN = "fis.auth.token";
28-
public static final String TEST_AUTH_TOKEN_2 = "fis.auth.token2";
29-
public static final String TEST_AUTH_TOKEN_3 = "fis.auth.token3";
30-
public static final String TEST_AUTH_TOKEN_4 = "fis.auth.token4";
31-
32-
public static final String TEST_API_KEY = "apiKey";
3323

3424
public static final String TEST_REFRESH_TOKEN = "1:test-refresh-token";
3525

@@ -41,40 +31,6 @@ public final class FisAndroidTestConstants {
4131
public static final long TEST_CREATION_TIMESTAMP_1 = 2000L;
4232
public static final long TEST_CREATION_TIMESTAMP_2 = 2L;
4333

44-
public static final String TEST_INSTANCE_ID_1 = "ccccccccccc";
45-
4634
public static final PersistedInstallationEntry DEFAULT_PERSISTED_INSTALLATION_ENTRY =
4735
PersistedInstallationEntry.builder().build();
48-
public static final InstallationResponse TEST_INSTALLATION_RESPONSE =
49-
InstallationResponse.builder()
50-
.setUri("/projects/" + TEST_PROJECT_ID + "/installations/" + TEST_FID_1)
51-
.setFid(TEST_FID_1)
52-
.setRefreshToken(TEST_REFRESH_TOKEN)
53-
.setAuthToken(
54-
TokenResult.builder()
55-
.setToken(TEST_AUTH_TOKEN)
56-
.setTokenExpirationTimestamp(TEST_TOKEN_EXPIRATION_TIMESTAMP)
57-
.build())
58-
.setResponseCode(ResponseCode.OK)
59-
.build();
60-
61-
public static final InstallationResponse TEST_INSTALLATION_RESPONSE_WITH_IID =
62-
InstallationResponse.builder()
63-
.setUri("/projects/" + TEST_PROJECT_ID + "/installations/" + TEST_INSTANCE_ID_1)
64-
.setFid(TEST_INSTANCE_ID_1)
65-
.setRefreshToken(TEST_REFRESH_TOKEN)
66-
.setAuthToken(
67-
TokenResult.builder()
68-
.setToken(TEST_AUTH_TOKEN)
69-
.setTokenExpirationTimestamp(TEST_TOKEN_EXPIRATION_TIMESTAMP)
70-
.build())
71-
.setResponseCode(ResponseCode.OK)
72-
.build();
73-
74-
public static final TokenResult TEST_TOKEN_RESULT =
75-
TokenResult.builder()
76-
.setToken(TEST_AUTH_TOKEN_2)
77-
.setTokenExpirationTimestamp(TEST_TOKEN_EXPIRATION_TIMESTAMP)
78-
.setResponseCode(TokenResult.ResponseCode.OK)
79-
.build();
8036
}

firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static PersistedInstallationEntrySubject assertThat(
4545

4646
/**
4747
* Constructor for use by subclasses. If you want to create an instance of this class itself, call
48-
* {@link Subject#check(String, PersistedInstallationEntry ..) check(...)}{@code .that(actual)}.
48+
* {@link Subject#check(String, Object ...) check(...)}{@code .that(actual)}.
4949
*
5050
* @param metadata
5151
* @param actual

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private PersistedInstallationEntry getPrefsWithGeneratedIdMultiProcessSafe() {
337337
}
338338

339339
/** Use file locking to acquire a lock that will also block other processes. */
340-
private FileLock getCrossProcessLock() {
340+
FileLock getCrossProcessLock() {
341341
try {
342342
File file =
343343
new File(firebaseApp.getApplicationContext().getFilesDir(), LOCKFILE_NAME_GENERATE_FID);
@@ -351,7 +351,7 @@ private FileLock getCrossProcessLock() {
351351
}
352352

353353
/** Release a previously acquired lock. */
354-
private void releaseCrossProcessLock(FileLock fileLock) {
354+
void releaseCrossProcessLock(FileLock fileLock) {
355355
try {
356356
fileLock.release();
357357
} catch (IOException e) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ public FakeCalendar(long initialTimeInMillis) {
2323
timeInMillis = initialTimeInMillis;
2424
}
2525

26+
@Override
2627
public long getTimeInMillis() {
2728
return timeInMillis;
2829
}
2930

31+
@Override
3032
public void setTimeInMillis(long timeInMillis) {
3133
this.timeInMillis = timeInMillis;
3234
}

0 commit comments

Comments
 (0)