From 1cf2d695346460afa7b66bf90447f1c0f66a6e98 Mon Sep 17 00:00:00 2001 From: Rechee Date: Mon, 6 Jan 2020 17:40:11 -0800 Subject: [PATCH] creating migration tests --- android/uhabits-core/build.gradle | 2 + .../src/main/resources/migrations/23.sql | 4 +- .../core/database/migrations/Version23Test.kt | 63 ++++++++++++++++++ .../src/test/resources/databases/022.db | Bin 0 -> 32768 bytes 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 android/uhabits-core/src/test/java/org/isoron/uhabits/core/database/migrations/Version23Test.kt create mode 100644 android/uhabits-core/src/test/resources/databases/022.db 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 0000000000000000000000000000000000000000..01237dfc8d4234f74a2cefe6f405f55b8bb01218 GIT binary patch literal 32768 zcmeI)&u$w<90%|jJBimO&Zd#56$zwKbFo#oP&o7mrL{yvRgurK{98~KE6^j&9HyYtVppZV=Xn|S?T z@2=E>^+V-z&E6-Qgi`V$V}y{)X0^xoEjeu5bQRuYO0?DksGL zp>ndZTi>evS$kZ2T;IxH7d3!92tWV=5P$##<`ww*cB#_X-lpGh&7XMUWBx?yDBG^w zzTdgk?Xd2xkM4F@md2V)x=aRI90y1;F(pQB?a6UlNN?yB+~{b z9c(kx9T~VnIfF1Ry!mOe$<140h0-n`MW^XOs96wup6PO*$DU?4-n-dmdNdTTFY>M_ zz}11!&b;N0xEBl4U+%GUZ)jSJ1F6%qJfC~zO6!eh4nvqiMm1)O_nxq z1}$&DHSXAz#?B7?YA?Mo3WW>1Yg3m2U}R}?$HZw6=A+zZCh8-8 zkk50GP)BA?E6l{Ljc>`1OTzhSd988vD*Y@)iw-?=SLsCJFiyjL`fzoMai(lDnfcqM zX3N}Rt}pb-2mf8~9@4eOwQIDO>hi!

!QzXzrTd@UzF|Dc{*#*7U+2_XO*99(7yE zO?-MM|H@4%$$jl6$;1Ky2tWV=5P$##AOHafKmY;|fWYDl)J+$u{Wmc`SReoa2tWV= z5P$##AOHafKmY;|_m#`=SY zlbx+Yw{HJs?*E??`?>wwBAp=m0s#m>00Izz00bZa0SG_<0uX?}#R4`h@6f{6mXxcd z@^&@*svlExvsgR({QnDLzp#I`Pl`F%hX4d1009U<00Izz00bZa0SG`~c?H(#DzR26 z4ZrCBPD(X%BGi6K?3eZ*_AkqOR_HkdAOHafKmY;|fB*y_009U<00J`twH0f%n*9MF k`Tzg)Cjw^5;t&E5fB*y_009U<00Izz00bZafu$Gt7dP<8fB*mh literal 0 HcmV?d00001