Skip to content

Commit

Permalink
style: ktFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Oct 27, 2024
1 parent 2df83ba commit b0ffd92
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,48 @@ import java.io.IOException
*/
class PokeRogueDatabaseMigrationTest {
@get:Rule
val helper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
PokeRogueDatabase::class.java
)
val helper =
MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
PokeRogueDatabase::class.java,
)

@Test
@Throws(IOException::class)
@DisplayName("버전 1에서 버전 2로 마이그레이션 데이터 무결성 테스트 - backImageUrl 추가")
fun test_migration1To2() = helper.migrationTestCase(
tableName = PokemonEntity.TABLE_NAME,
from = 1,
to = 2,
onBeforeMigration = {
val contentValue = contentValuesOf(
"id" to 1,
"dexNumber" to 25,
"formName" to "Normal",
"name" to "Pikachu",
"imageUrl" to "url_to_image",
"types" to "Electric",
"generation" to 1,
"baseStat" to 320,
"hp" to 35,
"attack" to 55,
"defense" to 40,
"specialAttack" to 50,
"specialDefense" to 50,
"speed" to 90,
)
insert(PokemonEntity.TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, contentValue)
},
onAfterMigration = {
moveToFirst() shouldBe true
val backImageUrlIndex = getColumnIndex("backImageUrl")
val backImageUrl = getString(backImageUrlIndex)
backImageUrl.shouldBeEmpty()
moveToNext() shouldBe false
},
)
fun test_migration1To2() =
helper.migrationTestCase(
tableName = PokemonEntity.TABLE_NAME,
from = 1,
to = 2,
onBeforeMigration = {
val contentValue =
contentValuesOf(
"id" to 1,
"dexNumber" to 25,
"formName" to "Normal",
"name" to "Pikachu",
"imageUrl" to "url_to_image",
"types" to "Electric",
"generation" to 1,
"baseStat" to 320,
"hp" to 35,
"attack" to 55,
"defense" to 40,
"specialAttack" to 50,
"specialDefense" to 50,
"speed" to 90,
)
insert(PokemonEntity.TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, contentValue)
},
onAfterMigration = {
moveToFirst() shouldBe true
val backImageUrlIndex = getColumnIndex("backImageUrl")
val backImageUrl = getString(backImageUrlIndex)
backImageUrl.shouldBeEmpty()
moveToNext() shouldBe false
},
)

@Test
@DisplayName("모든 database 버전 마이그레이션 테스트")
Expand All @@ -80,10 +83,9 @@ class PokeRogueDatabaseMigrationTest {
Room.databaseBuilder(
testContext,
PokeRogueDatabase::class.java,
"TEST_DB"
"TEST_DB",
).build().apply {
openHelper.writableDatabase.close()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ fun MigrationTestHelper.migrationTestCase(
}

// When
val newDb = runMigrationsAndValidate(
testDbName,
to,
true,
*migrations,
)
val newDb =
runMigrationsAndValidate(
testDbName,
to,
true,
*migrations,
)

// Then
newDb.query("SELECT * FROM $tableName").apply {
onAfterMigration()
}
newDb.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import poke.rogue.helper.local.entity.PokemonEntity
entities = [PokemonEntity::class],
version = 2,
autoMigrations = [
AutoMigration(from = 1, to = 2)
]
AutoMigration(from = 1, to = 2),
],
)
@androidx.room.TypeConverters(PokemonTypeConverters::class)
abstract class PokeRogueDatabase : RoomDatabase() {
Expand Down

0 comments on commit b0ffd92

Please sign in to comment.