Skip to content

Commit

Permalink
app: test: Assert applicationInfo is non-null
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Gupta <[email protected]>
  • Loading branch information
theimpulson committed Sep 9, 2024
1 parent 6a0b88f commit 5977e63
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -167,7 +167,7 @@ internal class ApkBackupRestoreTest : TransportTest() {
coEvery { storagePlugin.getInputStream(token, name) } returns inputStream
every { pm.getPackageArchiveInfo(capture(apkPath), any<Int>()) } 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ internal class ApkRestoreTest : TransportTest() {
} returns apkInputStream
every { pm.getPackageArchiveInfo(any(), any<Int>()) } 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
Expand Down Expand Up @@ -706,7 +706,7 @@ internal class ApkRestoreTest : TransportTest() {
coEvery { storagePlugin.getInputStream(token, name) } returns apkInputStream
every { pm.getPackageArchiveInfo(any(), any<Int>()) } 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<InstallResult>.assertQueuedFailFinished() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
)
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5977e63

Please sign in to comment.