diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b2a0d518a..7d6bc1bec 100755 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -109,6 +109,7 @@ dependencies { implementation("com.github.martin-stone:hsv-alpha-color-picker-android:3.1.0") // test + testImplementation(kotlin("test")) testImplementation("junit:junit:4.13.2") testImplementation("org.mockito:mockito-core:5.15.2") testImplementation("org.robolectric:robolectric:4.12.1") diff --git a/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt b/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt index 5212984e7..cc6b1fc97 100644 --- a/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt +++ b/app/src/test/java/helium314/keyboard/KeySpecParserTest.kt @@ -2,8 +2,8 @@ package helium314.keyboard import helium314.keyboard.keyboard.internal.KeySpecParser import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals class KeySpecParserTest { @Test fun label() { diff --git a/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt b/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt index 197d127c5..42b261f9e 100644 --- a/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt +++ b/app/src/test/java/helium314/keyboard/KeyboardParserTest.kt @@ -9,6 +9,7 @@ import helium314.keyboard.keyboard.Keyboard import helium314.keyboard.keyboard.KeyboardId import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.internal.KeySpecParser +import helium314.keyboard.keyboard.internal.KeySpecParser.KeySpecParserError import helium314.keyboard.keyboard.internal.KeyboardBuilder import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.TouchPositionCorrection @@ -22,11 +23,6 @@ import helium314.keyboard.latin.RichInputMethodSubtype import helium314.keyboard.latin.utils.AdditionalSubtypeUtils.createEmojiCapableAdditionalSubtype import helium314.keyboard.latin.utils.POPUP_KEYS_LAYOUT import helium314.keyboard.latin.utils.checkKeys -import org.junit.Assert.assertEquals -import org.junit.Assert.assertThrows -import org.junit.Assert.assertTrue -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner @@ -35,6 +31,11 @@ import org.robolectric.annotation.Implementation import org.robolectric.annotation.Implements import org.robolectric.shadows.ShadowLog import java.util.Locale +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import kotlin.test.assertTrue @RunWith(RobolectricTestRunner::class) @Config(shadows = [ @@ -45,8 +46,7 @@ class ParserTest { private lateinit var latinIME: LatinIME private lateinit var params: KeyboardParams - @Before - fun setUp() { + @BeforeTest fun setUp() { latinIME = Robolectric.setupService(LatinIME::class.java) ShadowLog.setupLogging() ShadowLog.stream = System.out @@ -320,7 +320,7 @@ f""", // no newline at the end } @Test fun invalidKeys() { - assertThrows(KeySpecParser.KeySpecParserError::class.java) { + assertFailsWith { RawKeyboardParser.parseJsonString("""[[{ "label": "!icon/clipboard_action_key" }]]""").map { it.mapNotNull { it.compute(params)?.toKeyParams(params) } } } } @@ -402,7 +402,7 @@ f""", // no newline at the end } @Test fun invalidPopupKeys() { - assertThrows(KeySpecParser.KeySpecParserError::class.java) { + assertFailsWith { RawKeyboardParser.parseJsonString("""[[{ "label": "a", "popup": { "main": { "label": "!icon/clipboard_action_key" } } }]]""").map { it.mapNotNull { it.compute(params)?.toKeyParams(params) } } diff --git a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt index 07f904921..08cf13fdc 100644 --- a/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt @@ -24,9 +24,6 @@ import helium314.keyboard.latin.inputlogic.SpaceState import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.ScriptUtils -import org.junit.Assert.assertEquals -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito import org.robolectric.Robolectric @@ -37,6 +34,9 @@ import org.robolectric.annotation.Implements import org.robolectric.shadows.ShadowLog import java.util.* import kotlin.math.min +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals @RunWith(RobolectricTestRunner::class) @Config(shadows = [ @@ -61,7 +61,8 @@ class InputLogicTest { private val composingReader = RichInputConnection::class.java.getDeclaredField("mComposingText").apply { isAccessible = true } private val connectionComposingText get() = (composingReader.get(connection) as CharSequence).toString() - @Before fun setUp() { + @BeforeTest + fun setUp() { latinIME = Robolectric.setupService(LatinIME::class.java) // start logging only after latinIME is created, avoids showing the stack traces if library is not found ShadowLog.setupLogging() diff --git a/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt b/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt index b549e04ed..9fb7eaaf1 100644 --- a/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/LocaleUtilsTest.kt @@ -2,8 +2,8 @@ package helium314.keyboard.latin import helium314.keyboard.latin.common.LocaleUtils.constructLocale -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals class LocaleUtilsTest { @Test fun createLocales() { diff --git a/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt b/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt index d9a04186f..9134a5872 100644 --- a/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/ScriptUtilsTest.kt @@ -6,8 +6,8 @@ import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_CYRILLIC import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_DEVANAGARI import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_LATIN import helium314.keyboard.latin.utils.ScriptUtils.script -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals class ScriptUtilsTest { @Test fun defaultScript() { diff --git a/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt b/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt index cb5f0d9b9..518b6ffe1 100644 --- a/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/StringUtilsTest.kt @@ -3,8 +3,8 @@ package helium314.keyboard.latin import helium314.keyboard.latin.common.StringUtils import helium314.keyboard.latin.common.getFullEmojiAtEnd -import org.junit.Assert.assertEquals -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals // todo: actually this test could/should be significantly expanded... class StringUtilsTest { diff --git a/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt b/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt index baafd2557..c37b43927 100644 --- a/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt @@ -15,8 +15,6 @@ import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.SettingsValuesForSuggestion import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.SuggestionResults -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner @@ -25,6 +23,8 @@ import org.robolectric.annotation.Implementation import org.robolectric.annotation.Implements import org.robolectric.shadows.ShadowLog import java.util.* +import kotlin.test.BeforeTest +import kotlin.test.Test @Suppress("NonAsciiCharacters") @RunWith(RobolectricTestRunner::class) @@ -43,7 +43,7 @@ class SuggestTest { private val thresholdAggressive = "1" private val thresholdVeryAggressive = "2" - @Before fun setUp() { + @BeforeTest fun setUp() { latinIME = Robolectric.setupService(LatinIME::class.java) // start logging only after latinIME is created, avoids showing the stack traces if library is not found ShadowLog.setupLogging()