diff --git a/android/uhabits-core/build.gradle b/android/uhabits-core/build.gradle index 1537f0b7a..0e89a2eb7 100644 --- a/android/uhabits-core/build.gradle +++ b/android/uhabits-core/build.gradle @@ -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" diff --git a/android/uhabits-core/src/main/resources/migrations/23.sql b/android/uhabits-core/src/main/resources/migrations/23.sql index d61b4d454..0afc69fe7 100644 --- a/android/uhabits-core/src/main/resources/migrations/23.sql +++ b/android/uhabits-core/src/main/resources/migrations/23.sql @@ -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 \ No newline at end of file +update Habits set description = null; \ No newline at end of file diff --git a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/database/migrations/Version23Test.kt b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/database/migrations/Version23Test.kt new file mode 100644 index 000000000..da6767370 --- /dev/null +++ b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/database/migrations/Version23Test.kt @@ -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() + 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()) + } + } +} \ No newline at end of file diff --git a/android/uhabits-core/src/test/resources/databases/022.db b/android/uhabits-core/src/test/resources/databases/022.db new file mode 100644 index 000000000..01237dfc8 Binary files /dev/null and b/android/uhabits-core/src/test/resources/databases/022.db differ