app: test: Assert applicationInfo is non-null

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta 2024-09-09 11:43:44 +05:30
parent 217fd97d3e
commit 4a235c6739
4 changed files with 13 additions and 13 deletions

View file

@ -342,7 +342,7 @@ class MetadataManagerTest {
@Test @Test
fun `test onPackageBackedUp()`() { fun `test onPackageBackedUp()`() {
packageInfo.applicationInfo.flags = FLAG_SYSTEM packageInfo.applicationInfo!!.flags = FLAG_SYSTEM
val updatedMetadata = initialMetadata.copy( val updatedMetadata = initialMetadata.copy(
time = time, time = time,
packageMetadataMap = PackageMetadataMap() // otherwise this isn't copied, but referenced packageMetadataMap = PackageMetadataMap() // otherwise this isn't copied, but referenced

View file

@ -118,12 +118,12 @@ internal class ApkBackupRestoreTest : TransportTest() {
fun `test backup and restore with a split`(@TempDir tmpDir: Path) = runBlocking { fun `test backup and restore with a split`(@TempDir tmpDir: Path) = runBlocking {
val apkBytes = byteArrayOf(0x04, 0x05, 0x06) val apkBytes = byteArrayOf(0x04, 0x05, 0x06)
val tmpFile = File(tmpDir.toAbsolutePath().toString()) val tmpFile = File(tmpDir.toAbsolutePath().toString())
packageInfo.applicationInfo.sourceDir = File(tmpFile, "test.apk").apply { packageInfo.applicationInfo!!.sourceDir = File(tmpFile, "test.apk").apply {
assertTrue(createNewFile()) assertTrue(createNewFile())
writeBytes(apkBytes) writeBytes(apkBytes)
}.absolutePath }.absolutePath
packageInfo.splitNames = arrayOf(splitName) packageInfo.splitNames = arrayOf(splitName)
packageInfo.applicationInfo.splitSourceDirs = arrayOf(File(tmpFile, "split.apk").apply { packageInfo.applicationInfo!!.splitSourceDirs = arrayOf(File(tmpFile, "split.apk").apply {
assertTrue(createNewFile()) assertTrue(createNewFile())
writeBytes(splitBytes) writeBytes(splitBytes)
}.absolutePath) }.absolutePath)
@ -167,7 +167,7 @@ internal class ApkBackupRestoreTest : TransportTest() {
coEvery { storagePlugin.getInputStream(token, name) } returns inputStream coEvery { storagePlugin.getInputStream(token, name) } returns inputStream
every { pm.getPackageArchiveInfo(capture(apkPath), any<Int>()) } returns packageInfo every { pm.getPackageArchiveInfo(capture(apkPath), any<Int>()) } returns packageInfo
every { applicationInfo.loadIcon(pm) } returns icon every { applicationInfo.loadIcon(pm) } 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))
} returns true } returns true

View file

@ -281,7 +281,7 @@ internal class ApkRestoreTest : TransportTest() {
} returns apkInputStream } returns apkInputStream
every { pm.getPackageArchiveInfo(any(), any<Int>()) } returns packageInfo every { pm.getPackageArchiveInfo(any(), any<Int>()) } returns packageInfo
every { applicationInfo.loadIcon(pm) } returns icon every { applicationInfo.loadIcon(pm) } 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())
} returns installResult } returns installResult
@ -706,7 +706,7 @@ internal class ApkRestoreTest : TransportTest() {
coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream
every { pm.getPackageArchiveInfo(any(), any<Int>()) } returns packageInfo every { pm.getPackageArchiveInfo(any(), any<Int>()) } returns packageInfo
every { applicationInfo.loadIcon(pm) } returns icon every { applicationInfo.loadIcon(pm) } returns icon
every { pm.getApplicationLabel(packageInfo.applicationInfo) } returns appName every { pm.getApplicationLabel(packageInfo.applicationInfo!!) } returns appName
} }
private suspend fun TurbineTestContext<InstallResult>.assertQueuedFailFinished() { private suspend fun TurbineTestContext<InstallResult>.assertQueuedFailFinished() {

View file

@ -82,7 +82,7 @@ internal class ApkBackupTest : BackupTest() {
@Test @Test
fun `does not back up test-only apps`() = runBlocking { 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.isBackupEnabled(any()) } returns true
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
@ -91,7 +91,7 @@ internal class ApkBackupTest : BackupTest() {
@Test @Test
fun `does not back up system apps`() = runBlocking { 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.isBackupEnabled(any()) } returns true
every { settingsManager.backupApks() } returns true every { settingsManager.backupApks() } returns true
@ -100,7 +100,7 @@ internal class ApkBackupTest : BackupTest() {
@Test @Test
fun `does not back up the same version`() = runBlocking { 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( val packageMetadata = packageMetadata.copy(
version = packageInfo.longVersionCode version = packageInfo.longVersionCode
) )
@ -112,7 +112,7 @@ internal class ApkBackupTest : BackupTest() {
@Test @Test
fun `does back up the same version when signatures changes`() { fun `does back up the same version when signatures changes`() {
packageInfo.applicationInfo.sourceDir = "/tmp/doesNotExist" packageInfo.applicationInfo!!.sourceDir = "/tmp/doesNotExist"
expectChecks() expectChecks()
@ -140,7 +140,7 @@ internal class ApkBackupTest : BackupTest() {
fun `test successful APK backup`(@TempDir tmpDir: Path) = runBlocking { fun `test successful APK backup`(@TempDir tmpDir: Path) = runBlocking {
val apkBytes = byteArrayOf(0x04, 0x05, 0x06) val apkBytes = byteArrayOf(0x04, 0x05, 0x06)
val tmpFile = File(tmpDir.toAbsolutePath().toString()) val tmpFile = File(tmpDir.toAbsolutePath().toString())
packageInfo.applicationInfo.sourceDir = File(tmpFile, "test.apk").apply { packageInfo.applicationInfo!!.sourceDir = File(tmpFile, "test.apk").apply {
assertTrue(createNewFile()) assertTrue(createNewFile())
writeBytes(apkBytes) writeBytes(apkBytes)
}.absolutePath }.absolutePath
@ -174,7 +174,7 @@ internal class ApkBackupTest : BackupTest() {
// create base APK // create base APK
val apkBytes = byteArrayOf(0x04, 0x05, 0x06) // not random because of hash val apkBytes = byteArrayOf(0x04, 0x05, 0x06) // not random because of hash
val tmpFile = File(tmpDir.toAbsolutePath().toString()) val tmpFile = File(tmpDir.toAbsolutePath().toString())
packageInfo.applicationInfo.sourceDir = File(tmpFile, "test.apk").apply { packageInfo.applicationInfo!!.sourceDir = File(tmpFile, "test.apk").apply {
assertTrue(createNewFile()) assertTrue(createNewFile())
writeBytes(apkBytes) writeBytes(apkBytes)
}.absolutePath }.absolutePath
@ -187,7 +187,7 @@ internal class ApkBackupTest : BackupTest() {
val split1Sha256 = "ZqZ1cVH47lXbEncWx-Pc4L6AdLZOIO2lQuXB5GypxB4" val split1Sha256 = "ZqZ1cVH47lXbEncWx-Pc4L6AdLZOIO2lQuXB5GypxB4"
val split2Bytes = byteArrayOf(0x01, 0x02, 0x03) val split2Bytes = byteArrayOf(0x01, 0x02, 0x03)
val split2Sha256 = "A5BYxvLAy0ksUzsKTRTvd8wPeKvMztUofYShogEc-4E" val split2Sha256 = "A5BYxvLAy0ksUzsKTRTvd8wPeKvMztUofYShogEc-4E"
packageInfo.applicationInfo.splitSourceDirs = arrayOf( packageInfo.applicationInfo!!.splitSourceDirs = arrayOf(
File(tmpFile, "test-$split1Name.apk").apply { File(tmpFile, "test-$split1Name.apk").apply {
assertTrue(createNewFile()) assertTrue(createNewFile())
writeBytes(split1Bytes) writeBytes(split1Bytes)