diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.java deleted file mode 100644 index 0a0af0734..000000000 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program 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. - * - * This program 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.kiwix.kiwixmobile.data.local; - -import android.content.Context; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.SmallTest; -import androidx.test.platform.app.InstrumentationRegistry; -import com.yahoo.squidb.data.SquidCursor; -import com.yahoo.squidb.sql.Query; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.kiwix.kiwixmobile.core.data.local.KiwixDatabase; -import org.kiwix.kiwixmobile.core.data.local.entity.Bookmark; - -import static org.junit.Assert.assertArrayEquals; - -@RunWith(AndroidJUnit4.class) -@SmallTest -public class KiwixDatabaseTest { - - private final Context context; - - public KiwixDatabaseTest() { - context = InstrumentationRegistry.getInstrumentation().getTargetContext(); - } - - @Test - @SuppressWarnings("CharsetObjectCanBeUsed") // Standard charset throws exception on < API19 - public void testMigrateDatabase() throws IOException { - KiwixDatabase kiwixDatabase = new KiwixDatabase(context, null, null, null, null); - kiwixDatabase.recreate(); - String testId = "8ce5775a-10a9-bbf3-178a-9df69f23263c"; - String[] testBookmarks = new String[] { "Test1", "Test2", "Test3" }; - String fileName = context.getFilesDir().getAbsolutePath() + File.separator + testId + ".txt"; - File f = new File(fileName); - if (!f.createNewFile()) { - throw new IOException("Unable to create file for testing migration"); - } - Writer writer = - new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), - "UTF-8")); - for (String bookmark : testBookmarks) { - writer.write(bookmark + "\n"); - } - writer.close(); - kiwixDatabase.migrateBookmarksVersion6(); - - ArrayList bookmarkTitles = new ArrayList<>(); - try { - SquidCursor bookmarkCursor = kiwixDatabase.query(Bookmark.class, - Query.selectDistinct(Bookmark.BOOKMARK_TITLE) - .where(Bookmark.ZIM_ID.eq(testId) - .or(Bookmark.ZIM_NAME.eq(""))) - .orderBy(Bookmark.BOOKMARK_TITLE.asc())); - while (bookmarkCursor.moveToNext()) { - bookmarkTitles.add(bookmarkCursor.get(Bookmark.BOOKMARK_TITLE)); - } - } catch (Exception exception) { - exception.printStackTrace(); - } - assertArrayEquals(testBookmarks, bookmarkTitles.toArray()); - - // TODO Add new migration test for version 16 - } -} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.kt new file mode 100644 index 000000000..b724156f1 --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/data/local/KiwixDatabaseTest.kt @@ -0,0 +1,96 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program 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. + * + * This program 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.kiwix.kiwixmobile.data.local + +import android.content.Context +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import androidx.test.platform.app.InstrumentationRegistry +import com.yahoo.squidb.sql.Query +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.kiwix.kiwixmobile.core.data.local.KiwixDatabase +import org.kiwix.kiwixmobile.core.data.local.entity.Bookmark +import java.io.BufferedWriter +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.io.OutputStreamWriter +import java.io.Writer + +@RunWith(AndroidJUnit4::class) +@SmallTest +class KiwixDatabaseTest { + private val context: Context = InstrumentationRegistry.getInstrumentation().targetContext + + @Test @Throws(IOException::class) // Standard charset throws exception on < API19 + fun testMigrateDatabase() { + val kiwixDatabase = KiwixDatabase( + context, + null, + null, + null, + null + ) + kiwixDatabase.recreate() + val testId = "8ce5775a-10a9-bbf3-178a-9df69f23263c" + val testBookmarks = arrayOf("Test1", "Test2", "Test3") + val fileName = context.filesDir.absolutePath + File.separator + testId + ".txt" + val f = File(fileName) + if (!f.createNewFile()) { + throw IOException("Unable to create file for testing migration") + } + val writer: Writer = BufferedWriter( + OutputStreamWriter( + FileOutputStream(fileName), + "UTF-8" + ) + ) + for (bookmark in testBookmarks) { + writer.write( + """ + $bookmark + + """.trimIndent() + ) + } + writer.close() + kiwixDatabase.migrateBookmarksVersion6() + val bookmarkTitles = ArrayList() + try { + val bookmarkCursor = kiwixDatabase.query( + Bookmark::class.java, + Query.selectDistinct(Bookmark.BOOKMARK_TITLE) + .where( + Bookmark.ZIM_ID.eq(testId) + .or(Bookmark.ZIM_NAME.eq("")) + ) + .orderBy(Bookmark.BOOKMARK_TITLE.asc()) + ) + while (bookmarkCursor.moveToNext()) { + bookmarkTitles.add(bookmarkCursor.get(Bookmark.BOOKMARK_TITLE)) + } + } catch (exception: Exception) { + exception.printStackTrace() + } + Assert.assertArrayEquals(testBookmarks, bookmarkTitles.toTypedArray()) + + // TODO Add new migration test for version 16 + } +} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt index e75074883..6ae944f9b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationRobot.kt @@ -63,7 +63,6 @@ class TopLevelDestinationRobot : BaseRobot() { fun clickDownloadOnBottomNav(func: OnlineLibraryRobot.() -> Unit) { clickOn(ViewId(R.id.downloadsFragment)) onlineLibrary(func) - pressBack() } private fun inNavDrawer(navDrawerAction: () -> Unit) {