From 4a235c6739ea69ce74326b53553f30abc5cca22a Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Mon, 9 Sep 2024 11:43:44 +0530 Subject: [PATCH] app: test: Assert applicationInfo is non-null Signed-off-by: Aayush Gupta --- .../seedvault/metadata/MetadataManagerTest.kt | 2 +- .../restore/install/ApkBackupRestoreTest.kt | 6 +++--- .../seedvault/restore/install/ApkRestoreTest.kt | 4 ++-- .../stevesoltys/seedvault/worker/ApkBackupTest.kt | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt index f049a827..b9844d9e 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt @@ -342,7 +342,7 @@ class MetadataManagerTest { @Test fun `test onPackageBackedUp()`() { - packageInfo.applicationInfo.flags = FLAG_SYSTEM + packageInfo.applicationInfo!!.flags = FLAG_SYSTEM val updatedMetadata = initialMetadata.copy( time = time, packageMetadataMap = PackageMetadataMap() // otherwise this isn't copied, but referenced 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 e1c7ed81..12c5761c 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 @@ -118,12 +118,12 @@ internal class ApkBackupRestoreTest : TransportTest() { fun `test backup and restore with a split`(@TempDir tmpDir: Path) = runBlocking { val apkBytes = byteArrayOf(0x04, 0x05, 0x06) val tmpFile = File(tmpDir.toAbsolutePath().toString()) - packageInfo.applicationInfo.sourceDir = File(tmpFile, "test.apk").apply { + packageInfo.applicationInfo!!.sourceDir = File(tmpFile, "test.apk").apply { assertTrue(createNewFile()) writeBytes(apkBytes) }.absolutePath packageInfo.splitNames = arrayOf(splitName) - packageInfo.applicationInfo.splitSourceDirs = arrayOf(File(tmpFile, "split.apk").apply { + packageInfo.applicationInfo!!.splitSourceDirs = arrayOf(File(tmpFile, "split.apk").apply { assertTrue(createNewFile()) writeBytes(splitBytes) }.absolutePath) @@ -167,7 +167,7 @@ internal class ApkBackupRestoreTest : TransportTest() { coEvery { storagePlugin.getInputStream(token, name) } returns inputStream every { pm.getPackageArchiveInfo(capture(apkPath), any()) } returns packageInfo every { applicationInfo.loadIcon(pm) } returns icon - every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName + every { pm.getApplicationLabel(packageInfo.applicationInfo!!) } returns appName every { splitCompatChecker.isCompatible(metadata.deviceName, listOf(splitName)) } returns true 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 adccad1b..808723d2 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 @@ -281,7 +281,7 @@ internal class ApkRestoreTest : TransportTest() { } returns apkInputStream every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo every { applicationInfo.loadIcon(pm) } returns icon - every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName + every { pm.getApplicationLabel(packageInfo.applicationInfo!!) } returns appName coEvery { apkInstaller.install(match { it.size == 1 }, packageName, installerName, any()) } returns installResult @@ -706,7 +706,7 @@ internal class ApkRestoreTest : TransportTest() { coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream every { pm.getPackageArchiveInfo(any(), any()) } returns packageInfo every { applicationInfo.loadIcon(pm) } returns icon - every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName + every { pm.getApplicationLabel(packageInfo.applicationInfo!!) } returns appName } private suspend fun TurbineTestContext.assertQueuedFailFinished() { diff --git a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt index 2159ff32..facc4d42 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt @@ -82,7 +82,7 @@ internal class ApkBackupTest : BackupTest() { @Test fun `does not back up test-only apps`() = runBlocking { - packageInfo.applicationInfo.flags = FLAG_TEST_ONLY + packageInfo.applicationInfo!!.flags = FLAG_TEST_ONLY every { settingsManager.isBackupEnabled(any()) } returns true every { settingsManager.backupApks() } returns true @@ -91,7 +91,7 @@ internal class ApkBackupTest : BackupTest() { @Test fun `does not back up system apps`() = runBlocking { - packageInfo.applicationInfo.flags = FLAG_SYSTEM + packageInfo.applicationInfo!!.flags = FLAG_SYSTEM every { settingsManager.isBackupEnabled(any()) } returns true every { settingsManager.backupApks() } returns true @@ -100,7 +100,7 @@ internal class ApkBackupTest : BackupTest() { @Test fun `does not back up the same version`() = runBlocking { - packageInfo.applicationInfo.flags = FLAG_UPDATED_SYSTEM_APP + packageInfo.applicationInfo!!.flags = FLAG_UPDATED_SYSTEM_APP val packageMetadata = packageMetadata.copy( version = packageInfo.longVersionCode ) @@ -112,7 +112,7 @@ internal class ApkBackupTest : BackupTest() { @Test fun `does back up the same version when signatures changes`() { - packageInfo.applicationInfo.sourceDir = "/tmp/doesNotExist" + packageInfo.applicationInfo!!.sourceDir = "/tmp/doesNotExist" expectChecks() @@ -140,7 +140,7 @@ internal class ApkBackupTest : BackupTest() { fun `test successful APK backup`(@TempDir tmpDir: Path) = runBlocking { val apkBytes = byteArrayOf(0x04, 0x05, 0x06) val tmpFile = File(tmpDir.toAbsolutePath().toString()) - packageInfo.applicationInfo.sourceDir = File(tmpFile, "test.apk").apply { + packageInfo.applicationInfo!!.sourceDir = File(tmpFile, "test.apk").apply { assertTrue(createNewFile()) writeBytes(apkBytes) }.absolutePath @@ -174,7 +174,7 @@ internal class ApkBackupTest : BackupTest() { // create base APK val apkBytes = byteArrayOf(0x04, 0x05, 0x06) // not random because of hash val tmpFile = File(tmpDir.toAbsolutePath().toString()) - packageInfo.applicationInfo.sourceDir = File(tmpFile, "test.apk").apply { + packageInfo.applicationInfo!!.sourceDir = File(tmpFile, "test.apk").apply { assertTrue(createNewFile()) writeBytes(apkBytes) }.absolutePath @@ -187,7 +187,7 @@ internal class ApkBackupTest : BackupTest() { val split1Sha256 = "ZqZ1cVH47lXbEncWx-Pc4L6AdLZOIO2lQuXB5GypxB4" val split2Bytes = byteArrayOf(0x01, 0x02, 0x03) val split2Sha256 = "A5BYxvLAy0ksUzsKTRTvd8wPeKvMztUofYShogEc-4E" - packageInfo.applicationInfo.splitSourceDirs = arrayOf( + packageInfo.applicationInfo!!.splitSourceDirs = arrayOf( File(tmpFile, "test-$split1Name.apk").apply { assertTrue(createNewFile()) writeBytes(split1Bytes)