Set buildTimestamp through manifest meta (#1556)

This commit is contained in:
Mikołaj Pich 2021-10-03 14:13:42 +02:00 committed by GitHub
parent 8e607d48f7
commit 60501fcd72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 19 deletions

View file

@ -16,6 +16,8 @@ abstract class AbstractMigrationTest {
val dbName = "migration-test"
val context: Context get() = ApplicationProvider.getApplicationContext<Context>()
@get:Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
@ -24,7 +26,6 @@ abstract class AbstractMigrationTest {
)
fun getMigratedRoomDatabase(): AppDatabase {
val context = ApplicationProvider.getApplicationContext<Context>()
val database = Room.databaseBuilder(
ApplicationProvider.getApplicationContext(),
AppDatabase::class.java,
@ -32,7 +33,7 @@ abstract class AbstractMigrationTest {
).addMigrations(
*AppDatabase.getMigrations(
SharedPrefProvider(PreferenceManager.getDefaultSharedPreferences(context)),
AppInfo()
AppInfo(context)
)
).build()
// close the database and release any stream resources when the test finishes

View file

@ -29,15 +29,15 @@ class Migration35Test : AbstractMigrationTest() {
close()
}
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo()))
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo(context)))
val db = getMigratedRoomDatabase()
val students = runBlocking { db.studentDao.loadAll() }
assertEquals(2, students.size)
assertTrue { students[0].avatarColor in AppInfo().defaultColorsForAvatar }
assertTrue { students[1].avatarColor in AppInfo().defaultColorsForAvatar }
assertTrue { students[0].avatarColor in AppInfo(context).defaultColorsForAvatar }
assertTrue { students[1].avatarColor in AppInfo(context).defaultColorsForAvatar }
}
private fun createStudent(db: SupportSQLiteDatabase, id: Long) {

View file

@ -32,13 +32,13 @@ class StudentTest {
fun initApi() {
MockKAnnotations.init(this)
studentRepository = StudentRepository(
mockk(),
TestDispatchersProvider(),
studentDb,
semesterDb,
mockSdk,
AppInfo(),
mockk()
context = mockk(),
dispatchers = TestDispatchersProvider(),
studentDb = studentDb,
semesterDb = semesterDb,
sdk = mockSdk,
appInfo = AppInfo(mockk()),
appDatabase = mockk()
)
}