Mock ApplicationInfo
as it now calls the native SystemClock.uptimeMillis() method which is hard to mock
This commit is contained in:
parent
65fa49132e
commit
d72bee523b
4 changed files with 11 additions and 30 deletions
|
@ -134,13 +134,7 @@ internal class ApkBackupRestoreTest : TransportTest() {
|
||||||
every { crypto.getNameForApk(salt, packageName, "") } returns name
|
every { crypto.getNameForApk(salt, packageName, "") } returns name
|
||||||
coEvery { storagePlugin.getInputStream(token, name) } returns inputStream
|
coEvery { storagePlugin.getInputStream(token, name) } returns inputStream
|
||||||
every { pm.getPackageArchiveInfo(capture(apkPath), any()) } returns packageInfo
|
every { pm.getPackageArchiveInfo(capture(apkPath), any()) } returns packageInfo
|
||||||
every {
|
every { applicationInfo.loadIcon(pm) } returns icon
|
||||||
@Suppress("UNRESOLVED_REFERENCE")
|
|
||||||
pm.loadItemIcon(
|
|
||||||
packageInfo.applicationInfo,
|
|
||||||
packageInfo.applicationInfo
|
|
||||||
)
|
|
||||||
} returns icon
|
|
||||||
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
|
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
|
||||||
every {
|
every {
|
||||||
splitCompatChecker.isCompatible(metadata.deviceName, listOf(splitName))
|
splitCompatChecker.isCompatible(metadata.deviceName, listOf(splitName))
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.stevesoltys.seedvault.restore.install
|
package com.stevesoltys.seedvault.restore.install
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.ApplicationInfo
|
|
||||||
import android.content.pm.ApplicationInfo.FLAG_INSTALLED
|
import android.content.pm.ApplicationInfo.FLAG_INSTALLED
|
||||||
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
|
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
|
||||||
import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
|
import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
|
||||||
|
@ -177,13 +176,7 @@ internal class ApkRestoreTest : TransportTest() {
|
||||||
legacyStoragePlugin.getApkInputStream(token, packageName, "")
|
legacyStoragePlugin.getApkInputStream(token, packageName, "")
|
||||||
} returns apkInputStream
|
} returns apkInputStream
|
||||||
every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo
|
every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo
|
||||||
every {
|
every { applicationInfo.loadIcon(pm) } returns icon
|
||||||
@Suppress("UNRESOLVED_REFERENCE")
|
|
||||||
pm.loadItemIcon(
|
|
||||||
packageInfo.applicationInfo,
|
|
||||||
packageInfo.applicationInfo
|
|
||||||
)
|
|
||||||
} returns icon
|
|
||||||
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
|
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
|
||||||
coEvery {
|
coEvery {
|
||||||
apkInstaller.install(match { it.size == 1 }, packageName, installerName, any())
|
apkInstaller.install(match { it.size == 1 }, packageName, installerName, any())
|
||||||
|
@ -200,13 +193,11 @@ internal class ApkRestoreTest : TransportTest() {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val packageMetadata = this@ApkRestoreTest.packageMetadata.copy(system = true)
|
val packageMetadata = this@ApkRestoreTest.packageMetadata.copy(system = true)
|
||||||
packageMetadataMap[packageName] = packageMetadata
|
packageMetadataMap[packageName] = packageMetadata
|
||||||
packageInfo.applicationInfo = mockk()
|
|
||||||
val installedPackageInfo: PackageInfo = mockk()
|
val installedPackageInfo: PackageInfo = mockk()
|
||||||
val willFail = Random.nextBoolean()
|
val willFail = Random.nextBoolean()
|
||||||
val isSystemApp = Random.nextBoolean()
|
val isSystemApp = Random.nextBoolean()
|
||||||
|
|
||||||
cacheBaseApkAndGetInfo(tmpDir)
|
cacheBaseApkAndGetInfo(tmpDir)
|
||||||
every { packageInfo.applicationInfo.loadIcon(pm) } returns icon
|
|
||||||
every { storagePlugin.providerPackageName } returns storageProviderPackageName
|
every { storagePlugin.providerPackageName } returns storageProviderPackageName
|
||||||
|
|
||||||
if (willFail) {
|
if (willFail) {
|
||||||
|
@ -214,7 +205,7 @@ internal class ApkRestoreTest : TransportTest() {
|
||||||
pm.getPackageInfo(packageName, 0)
|
pm.getPackageInfo(packageName, 0)
|
||||||
} throws PackageManager.NameNotFoundException()
|
} throws PackageManager.NameNotFoundException()
|
||||||
} else {
|
} else {
|
||||||
installedPackageInfo.applicationInfo = ApplicationInfo().apply {
|
installedPackageInfo.applicationInfo = mockk {
|
||||||
flags =
|
flags =
|
||||||
if (!isSystemApp) FLAG_INSTALLED else FLAG_SYSTEM or FLAG_UPDATED_SYSTEM_APP
|
if (!isSystemApp) FLAG_INSTALLED else FLAG_SYSTEM or FLAG_UPDATED_SYSTEM_APP
|
||||||
}
|
}
|
||||||
|
@ -422,13 +413,7 @@ internal class ApkRestoreTest : TransportTest() {
|
||||||
every { crypto.getNameForApk(salt, packageName, "") } returns name
|
every { crypto.getNameForApk(salt, packageName, "") } returns name
|
||||||
coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream
|
coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream
|
||||||
every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo
|
every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo
|
||||||
every {
|
every { applicationInfo.loadIcon(pm) } returns icon
|
||||||
@Suppress("UNRESOLVED_REFERENCE")
|
|
||||||
pm.loadItemIcon(
|
|
||||||
packageInfo.applicationInfo,
|
|
||||||
packageInfo.applicationInfo
|
|
||||||
)
|
|
||||||
} returns icon
|
|
||||||
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
|
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,13 @@ internal abstract class TransportTest {
|
||||||
|
|
||||||
protected val sigInfo: SigningInfo = mockk()
|
protected val sigInfo: SigningInfo = mockk()
|
||||||
protected val token = Random.nextLong()
|
protected val token = Random.nextLong()
|
||||||
|
protected val applicationInfo = mockk<ApplicationInfo> {
|
||||||
|
flags = FLAG_ALLOW_BACKUP or FLAG_INSTALLED
|
||||||
|
}
|
||||||
protected val packageInfo = PackageInfo().apply {
|
protected val packageInfo = PackageInfo().apply {
|
||||||
packageName = "org.example"
|
packageName = "org.example"
|
||||||
longVersionCode = Random.nextLong()
|
longVersionCode = Random.nextLong()
|
||||||
applicationInfo = ApplicationInfo().apply {
|
applicationInfo = this@TransportTest.applicationInfo
|
||||||
flags = FLAG_ALLOW_BACKUP or FLAG_INSTALLED
|
|
||||||
}
|
|
||||||
signingInfo = sigInfo
|
signingInfo = sigInfo
|
||||||
}
|
}
|
||||||
protected val pmPackageInfo = PackageInfo().apply {
|
protected val pmPackageInfo = PackageInfo().apply {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.app.backup.BackupTransport.TRANSPORT_NOT_INITIALIZED
|
||||||
import android.app.backup.BackupTransport.TRANSPORT_OK
|
import android.app.backup.BackupTransport.TRANSPORT_OK
|
||||||
import android.app.backup.BackupTransport.TRANSPORT_PACKAGE_REJECTED
|
import android.app.backup.BackupTransport.TRANSPORT_PACKAGE_REJECTED
|
||||||
import android.app.backup.BackupTransport.TRANSPORT_QUOTA_EXCEEDED
|
import android.app.backup.BackupTransport.TRANSPORT_QUOTA_EXCEEDED
|
||||||
import android.content.pm.ApplicationInfo
|
|
||||||
import android.content.pm.ApplicationInfo.FLAG_STOPPED
|
import android.content.pm.ApplicationInfo.FLAG_STOPPED
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -399,7 +398,9 @@ internal class BackupCoordinatorTest : BackupTest() {
|
||||||
PackageInfo().apply {
|
PackageInfo().apply {
|
||||||
packageName = "org.example.2"
|
packageName = "org.example.2"
|
||||||
// the second package does not get backed up, because it is stopped
|
// 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()
|
val packageMetadata: PackageMetadata = mockk()
|
||||||
|
|
Loading…
Reference in a new issue