Mock ApplicationInfo
as it now calls the native SystemClock.uptimeMillis() method which is hard to mock
diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt
index 97012e3..d201d89 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt
@@ -134,13 +134,7 @@
every { crypto.getNameForApk(salt, packageName, "") } returns name
coEvery { storagePlugin.getInputStream(token, name) } returns inputStream
every { pm.getPackageArchiveInfo(capture(apkPath), any()) } returns packageInfo
- every {
- @Suppress("UNRESOLVED_REFERENCE")
- pm.loadItemIcon(
- packageInfo.applicationInfo,
- packageInfo.applicationInfo
- )
- } returns icon
+ every { applicationInfo.loadIcon(pm) } returns icon
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
every {
splitCompatChecker.isCompatible(metadata.deviceName, listOf(splitName))
diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt
index ad73040..bd920bc 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt
@@ -1,7 +1,6 @@
package com.stevesoltys.seedvault.restore.install
import android.content.Context
-import android.content.pm.ApplicationInfo
import android.content.pm.ApplicationInfo.FLAG_INSTALLED
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
@@ -177,13 +176,7 @@
legacyStoragePlugin.getApkInputStream(token, packageName, "")
} returns apkInputStream
every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo
- every {
- @Suppress("UNRESOLVED_REFERENCE")
- pm.loadItemIcon(
- packageInfo.applicationInfo,
- packageInfo.applicationInfo
- )
- } returns icon
+ every { applicationInfo.loadIcon(pm) } returns icon
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
coEvery {
apkInstaller.install(match { it.size == 1 }, packageName, installerName, any())
@@ -200,13 +193,11 @@
runBlocking {
val packageMetadata = this@ApkRestoreTest.packageMetadata.copy(system = true)
packageMetadataMap[packageName] = packageMetadata
- packageInfo.applicationInfo = mockk()
val installedPackageInfo: PackageInfo = mockk()
val willFail = Random.nextBoolean()
val isSystemApp = Random.nextBoolean()
cacheBaseApkAndGetInfo(tmpDir)
- every { packageInfo.applicationInfo.loadIcon(pm) } returns icon
every { storagePlugin.providerPackageName } returns storageProviderPackageName
if (willFail) {
@@ -214,7 +205,7 @@
pm.getPackageInfo(packageName, 0)
} throws PackageManager.NameNotFoundException()
} else {
- installedPackageInfo.applicationInfo = ApplicationInfo().apply {
+ installedPackageInfo.applicationInfo = mockk {
flags =
if (!isSystemApp) FLAG_INSTALLED else FLAG_SYSTEM or FLAG_UPDATED_SYSTEM_APP
}
@@ -422,13 +413,7 @@
every { crypto.getNameForApk(salt, packageName, "") } returns name
coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream
every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo
- every {
- @Suppress("UNRESOLVED_REFERENCE")
- pm.loadItemIcon(
- packageInfo.applicationInfo,
- packageInfo.applicationInfo
- )
- } returns icon
+ every { applicationInfo.loadIcon(pm) } returns icon
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
}
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt
index 2f4e0cd..35e81b2 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt
@@ -37,12 +37,13 @@
protected val sigInfo: SigningInfo = mockk()
protected val token = Random.nextLong()
+ protected val applicationInfo = mockk<ApplicationInfo> {
+ flags = FLAG_ALLOW_BACKUP or FLAG_INSTALLED
+ }
protected val packageInfo = PackageInfo().apply {
packageName = "org.example"
longVersionCode = Random.nextLong()
- applicationInfo = ApplicationInfo().apply {
- flags = FLAG_ALLOW_BACKUP or FLAG_INSTALLED
- }
+ applicationInfo = this@TransportTest.applicationInfo
signingInfo = sigInfo
}
protected val pmPackageInfo = PackageInfo().apply {
diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt
index 9a58f3f..d5facae 100644
--- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt
+++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt
@@ -5,7 +5,6 @@
import android.app.backup.BackupTransport.TRANSPORT_OK
import android.app.backup.BackupTransport.TRANSPORT_PACKAGE_REJECTED
import android.app.backup.BackupTransport.TRANSPORT_QUOTA_EXCEEDED
-import android.content.pm.ApplicationInfo
import android.content.pm.ApplicationInfo.FLAG_STOPPED
import android.content.pm.PackageInfo
import android.net.Uri
@@ -399,7 +398,9 @@
PackageInfo().apply {
packageName = "org.example.2"
// the second package does not get backed up, because it is stopped
- applicationInfo = ApplicationInfo().apply { flags = FLAG_STOPPED }
+ applicationInfo = mockk {
+ flags = FLAG_STOPPED
+ }
}
)
val packageMetadata: PackageMetadata = mockk()