From ec42fda3369cf4e3d9e752352bdc65f501908302 Mon Sep 17 00:00:00 2001 From: Quentin Hibon Date: Thu, 21 Jan 2021 00:01:56 +0100 Subject: [PATCH] Convert AndroidDatabaseTest --- .../uhabits/database/AndroidDatabaseTest.java | 59 ------------------- .../uhabits/database/AndroidDatabaseTest.kt | 49 +++++++++++++++ 2 files changed, 49 insertions(+), 59 deletions(-) delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.kt diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.java deleted file mode 100644 index fe09fc951..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * This file is part of Loop Habit Tracker. - * - * Loop Habit Tracker is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Loop Habit Tracker is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -package org.isoron.uhabits.database; - -import android.database.sqlite.*; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.core.database.*; -import org.junit.*; - -import java.util.*; - -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.core.IsEqual.*; - - -public class AndroidDatabaseTest extends BaseAndroidTest -{ - private AndroidDatabase db; - - @Override - public void setUp() - { - super.setUp(); - db = new AndroidDatabase(SQLiteDatabase.create(null), null); - db.execute("create table test(color int, name string)"); - } - - @Test - public void testInsert() throws Exception - { - HashMap map = new HashMap<>(); - map.put("name", "asd"); - map.put("color", null); - db.insert("test", map); - - Cursor c = db.query("select * from test"); - c.moveToNext(); - assertNull(c.getInt(0)); - assertThat(c.getString(1), equalTo("asd")); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.kt new file mode 100644 index 000000000..11661a09a --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/database/AndroidDatabaseTest.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package org.isoron.uhabits.database + +import android.database.sqlite.SQLiteDatabase +import org.hamcrest.MatcherAssert +import org.hamcrest.core.IsEqual +import org.isoron.uhabits.BaseAndroidTest +import org.isoron.uhabits.core.database.Cursor +import org.junit.Test +import java.util.HashMap + +class AndroidDatabaseTest : BaseAndroidTest() { + private var db: AndroidDatabase? = null + override fun setUp() { + super.setUp() + db = AndroidDatabase(SQLiteDatabase.create(null), null) + db!!.execute("create table test(color int, name string)") + } + + @Test + @Throws(Exception::class) + fun testInsert() { + val map = HashMap() + map["name"] = "asd" + map["color"] = null + db!!.insert("test", map) + val c: Cursor = db!!.query("select * from test") + c.moveToNext() + assertNull(c.getInt(0)) + MatcherAssert.assertThat(c.getString(1), IsEqual.equalTo("asd")) + } +}