-
Notifications
You must be signed in to change notification settings - Fork 625
Removing dependency for activities #3298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f26de2e
afa49e7
cf274df
535b182
dd9215f
8b433d1
010a7f9
00faad7
0e12c55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ class NewReleaseFetcher { | |
private final FirebaseApp firebaseApp; | ||
private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient; | ||
private final Provider<FirebaseInstallationsApi> firebaseInstallationsApiProvider; | ||
private final Context applicationContext; | ||
// Maintain an in-memory mapping from source file to APK hash to avoid re-calculating the hash | ||
private static final ConcurrentMap<String, String> cachedApkHashes = new ConcurrentHashMap<>(); | ||
|
||
|
@@ -60,10 +61,11 @@ class NewReleaseFetcher { | |
@NonNull FirebaseApp firebaseApp, | ||
@NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient, | ||
@NonNull Provider<FirebaseInstallationsApi> firebaseInstallationsApiProvider) { | ||
this.firebaseApp = firebaseApp; | ||
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient; | ||
this.firebaseInstallationsApiProvider = firebaseInstallationsApiProvider; | ||
this.taskExecutor = Executors.newSingleThreadExecutor(); | ||
this( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
firebaseApp, | ||
firebaseAppDistributionTesterApiClient, | ||
firebaseInstallationsApiProvider, | ||
Executors.newSingleThreadExecutor()); | ||
} | ||
|
||
NewReleaseFetcher( | ||
|
@@ -75,6 +77,7 @@ class NewReleaseFetcher { | |
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient; | ||
this.firebaseInstallationsApiProvider = firebaseInstallationsApiProvider; | ||
this.taskExecutor = executor; | ||
this.applicationContext = firebaseApp.getApplicationContext(); | ||
} | ||
|
||
@NonNull | ||
|
@@ -151,19 +154,17 @@ private long parseBuildVersion(String buildVersion) throws FirebaseAppDistributi | |
|
||
private boolean isOlderBuildVersion(long newReleaseBuildVersion) | ||
throws FirebaseAppDistributionException { | ||
return newReleaseBuildVersion < getInstalledAppVersionCode(firebaseApp.getApplicationContext()); | ||
return newReleaseBuildVersion < getInstalledAppVersionCode(applicationContext); | ||
} | ||
|
||
private boolean isNewerBuildVersion(long newReleaseBuildVersion) | ||
throws FirebaseAppDistributionException { | ||
return newReleaseBuildVersion > getInstalledAppVersionCode(firebaseApp.getApplicationContext()); | ||
return newReleaseBuildVersion > getInstalledAppVersionCode(applicationContext); | ||
} | ||
|
||
private boolean hasDifferentAppVersionName(AppDistributionReleaseInternal newRelease) | ||
throws FirebaseAppDistributionException { | ||
return !newRelease | ||
.getDisplayVersion() | ||
.equals(getInstalledAppVersionName(firebaseApp.getApplicationContext())); | ||
return !newRelease.getDisplayVersion().equals(getInstalledAppVersionName(applicationContext)); | ||
} | ||
|
||
@VisibleForTesting | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ | |
|
||
import android.app.Activity; | ||
import android.net.Uri; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
@@ -44,6 +46,9 @@ | |
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class AabUpdaterTest { | ||
private static final String TEST_API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567"; | ||
private static final String TEST_APP_ID_1 = "1:123456789:android:abcdef"; | ||
private static final String TEST_PROJECT_ID = "777777777777"; | ||
private static final String TEST_URL = "https://test-url"; | ||
private static final String REDIRECT_TO_PLAY = "https://redirect-to-play-url"; | ||
private static final ExecutorService testExecutor = Executors.newSingleThreadExecutor(); | ||
|
@@ -72,6 +77,15 @@ public void setup() throws IOException, FirebaseAppDistributionException { | |
|
||
FirebaseApp.clearInstancesForTest(); | ||
|
||
FirebaseApp firebaseApp = | ||
FirebaseApp.initializeApp( | ||
ApplicationProvider.getApplicationContext(), | ||
new FirebaseOptions.Builder() | ||
.setApplicationId(TEST_APP_ID_1) | ||
.setProjectId(TEST_PROJECT_ID) | ||
.setApiKey(TEST_API_KEY) | ||
.build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case you missed my other comment, you don't need to a create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did miss this comment. Will fix now. |
||
|
||
activity = | ||
Robolectric.buildActivity(FirebaseAppDistributionTest.TestActivity.class).create().get(); | ||
shadowActivity = shadowOf(activity); | ||
|
@@ -84,7 +98,11 @@ public void setup() throws IOException, FirebaseAppDistributionException { | |
|
||
aabUpdater = | ||
Mockito.spy( | ||
new AabUpdater(mockLifecycleNotifier, mockHttpsUrlConnectionFactory, testExecutor)); | ||
new AabUpdater( | ||
firebaseApp.getApplicationContext(), | ||
mockLifecycleNotifier, | ||
mockHttpsUrlConnectionFactory, | ||
testExecutor)); | ||
when(mockLifecycleNotifier.getCurrentActivity()).thenReturn(activity); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you put this empty line back?