Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b6b6f53 authored by Darrell Shi's avatar Darrell Shi
Browse files

Improve CommunalBackupHelperTest stability

Sometimes setUp() can fail, and tearDown() is still invoked, leading to
an exception that lateinit variables may not have been initialized yet.
This change fixes that by using onTearDown() next to the initialation of
lateinit and only clean up if they have been initialized.

Test: atest CommunalBackupHelperTest
Bug: 379255212
Flag: EXEMPT improve unit test only
Change-Id: I3205dba6abcc7b91d145c5f5432b59992515c60b
parent d51ffdf0
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import com.google.common.truth.Truth.assertThat
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -63,22 +62,18 @@ class CommunalBackupHelperTest : SysuiTestCase() {
            Room.inMemoryDatabaseBuilder(context, CommunalDatabase::class.java)
                .allowMainThreadQueries()
                .build()
        onTeardown { database.close() }
        CommunalDatabase.setInstance(database)

        dao = database.communalWidgetDao()
        backupUtils = CommunalBackupUtils(context)

        backupDataFile = File(context.cacheDir, "backup_data_file")
        onTeardown { backupDataFile.delete() }

        underTest = CommunalBackupHelper(UserHandle.SYSTEM, backupUtils)
    }

    @After
    fun teardown() {
        backupDataFile.delete()
        database.close()
    }

    @Test
    @EnableFlags(Flags.FLAG_COMMUNAL_HUB)
    fun backupAndRestoreCommunalHub() {