mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
creating migration tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
dependencies {
|
||||
annotationProcessor "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
||||
@@ -26,6 +27,7 @@ dependencies {
|
||||
implementation('com.opencsv:opencsv:3.10') {
|
||||
exclude group: 'commons-logging', module: 'commons-logging'
|
||||
}
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
|
||||
}
|
||||
|
||||
sourceCompatibility = "1.8"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
alter table Habits add column question text;
|
||||
|
||||
update Habits set question = description
|
||||
update Habits set question = description;
|
||||
|
||||
update Habits set description = null
|
||||
update Habits set description = null;
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.isoron.uhabits.core.database.migrations
|
||||
|
||||
import org.hamcrest.MatcherAssert
|
||||
import org.hamcrest.Matchers
|
||||
import org.isoron.uhabits.core.BaseUnitTest
|
||||
import org.isoron.uhabits.core.database.Database
|
||||
import org.isoron.uhabits.core.database.MigrationHelper
|
||||
import org.isoron.uhabits.core.models.sqlite.SQLModelFactory
|
||||
import org.isoron.uhabits.core.test.HabitFixtures
|
||||
import org.junit.Test
|
||||
|
||||
class Version23Test: BaseUnitTest() {
|
||||
|
||||
private lateinit var db: Database
|
||||
|
||||
private lateinit var helper: MigrationHelper
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
db = openDatabaseResource("/databases/022.db")
|
||||
helper = MigrationHelper(db)
|
||||
modelFactory = SQLModelFactory(db)
|
||||
habitList = modelFactory.buildHabitList()
|
||||
fixtures = HabitFixtures(modelFactory, habitList)
|
||||
}
|
||||
|
||||
private fun migrateTo23() = helper.migrateTo(23)
|
||||
|
||||
@Test
|
||||
fun `test migrate to 23 creates question column`() {
|
||||
migrateTo23()
|
||||
val cursor = db.query("select question from Habits")
|
||||
cursor.moveToNext()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test migrate to 23 moves description to question column`() {
|
||||
var cursor = db.query("select description from Habits")
|
||||
|
||||
val descriptions = mutableListOf<String?>()
|
||||
while(cursor.moveToNext()){
|
||||
descriptions.add(cursor.getString(0))
|
||||
}
|
||||
|
||||
migrateTo23()
|
||||
cursor = db.query("select question from Habits")
|
||||
|
||||
for(i in 0 until descriptions.size){
|
||||
cursor.moveToNext()
|
||||
MatcherAssert.assertThat(cursor.getString(0), Matchers.equalTo(descriptions[i]))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test migrate to 23 sets description to null`() {
|
||||
migrateTo23()
|
||||
val cursor = db.query("select description from Habits")
|
||||
|
||||
while(cursor.moveToNext()){
|
||||
MatcherAssert.assertThat(cursor.getString(0), Matchers.nullValue())
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
android/uhabits-core/src/test/resources/databases/022.db
Normal file
BIN
android/uhabits-core/src/test/resources/databases/022.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user