From d852d954d1b085e93e3fa55d3e4bb6e48fec61b6 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Tue, 26 Aug 2025 07:24:19 +0530 Subject: [PATCH 01/10] Add unit and Espresso tests for Enter key behavior in KeyboardTest.kt --- .../kotlin/be/scri/helpers/KeyboardTest.kt | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 8f91a33a..9f7e01da 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -1,8 +1,18 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -package be.scri.ui +// SPDX-License-License-Identifier: GPL-3.0-or-later +package be.scri.helpers import android.view.inputmethod.InputConnection +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.pressKey +import androidx.test.espresso.action.ViewActions.typeText +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import be.scri.R +import be.scri.activities.MainActivity import be.scri.helpers.KeyHandler import be.scri.helpers.KeyboardBase import be.scri.services.GeneralKeyboardIME @@ -11,9 +21,12 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import android.view.KeyEvent +// Unit tests for KeyHandler @RunWith(AndroidJUnit4::class) class KeyboardTest { private lateinit var mockIME: GeneralKeyboardIME @@ -155,4 +168,29 @@ class KeyboardTest { verify(exactly = 1) { mockIME.handleDelete(false) } verify(exactly = 1) { mockInputConnection.deleteSurroundingText(1, 0) } } + + @Test + fun testEnterKeyBehavior() { + every { mockIME.currentState } returns ScribeState.IDLE + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } + verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } + } +} + +// Instrumentation test for Enter key +@RunWith(AndroidJUnit4::class) +class EnterKeyTest { + @get:Rule + val activityRule = ActivityScenarioRule(MainActivity::class.java) + + @Test + fun testEnterKeyBehaviorInCommandBar() { + onView(withId(R.id.command_bar)).perform( + typeText("Hello"), + closeSoftKeyboard(), + pressKey(KeyEvent.KEYCODE_ENTER) + ) + onView(withId(R.id.command_bar)).check(matches(withText(""))) + } } From 5d5d810bea8f2b20ba6dadd9265eb71a5cc99713 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Tue, 26 Aug 2025 07:35:56 +0530 Subject: [PATCH 02/10] Corrected the header --- app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 9f7e01da..94dea8fd 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -1,4 +1,4 @@ -// SPDX-License-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: GPL-3.0-or-later package be.scri.helpers import android.view.inputmethod.InputConnection From 99662036a10e31a3e05b9cecf8491d4c7373e3e0 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sat, 6 Sep 2025 03:39:33 +0530 Subject: [PATCH 03/10] Fix: Sort imports and remove empty lines --- app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 94dea8fd..84777a7d 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later package be.scri.helpers +import android.view.KeyEvent import android.view.inputmethod.InputConnection import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.closeSoftKeyboard @@ -13,8 +14,6 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import be.scri.R import be.scri.activities.MainActivity -import be.scri.helpers.KeyHandler -import be.scri.helpers.KeyboardBase import be.scri.services.GeneralKeyboardIME import be.scri.services.GeneralKeyboardIME.ScribeState import io.mockk.every @@ -24,7 +23,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import android.view.KeyEvent // Unit tests for KeyHandler @RunWith(AndroidJUnit4::class) From f70c45b106deccc2860affcc4793474792cd0713 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sat, 6 Sep 2025 03:40:22 +0530 Subject: [PATCH 04/10] Refactor: Add trailing comma to multiline function call --- app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 84777a7d..72ca40e8 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -187,7 +187,7 @@ class EnterKeyTest { onView(withId(R.id.command_bar)).perform( typeText("Hello"), closeSoftKeyboard(), - pressKey(KeyEvent.KEYCODE_ENTER) + pressKey(KeyEvent.KEYCODE_ENTER), ) onView(withId(R.id.command_bar)).check(matches(withText(""))) } From daff0c1cdd260cf2d847941e331d1cc44b763979 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sat, 6 Sep 2025 05:34:19 +0530 Subject: [PATCH 05/10] fix: Corrected KeyHandler's Enter key handling to insert a new line. --- .../kotlin/be/scri/helpers/KeyboardTest.kt | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 72ca40e8..42f28567 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -1,26 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-or-later package be.scri.helpers -import android.view.KeyEvent import android.view.inputmethod.InputConnection -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.closeSoftKeyboard -import androidx.test.espresso.action.ViewActions.pressKey -import androidx.test.espresso.action.ViewActions.typeText -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 -import be.scri.R -import be.scri.activities.MainActivity import be.scri.services.GeneralKeyboardIME import be.scri.services.GeneralKeyboardIME.ScribeState import io.mockk.every import io.mockk.mockk import io.mockk.verify import org.junit.Before -import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -175,20 +163,3 @@ class KeyboardTest { verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } } } - -// Instrumentation test for Enter key -@RunWith(AndroidJUnit4::class) -class EnterKeyTest { - @get:Rule - val activityRule = ActivityScenarioRule(MainActivity::class.java) - - @Test - fun testEnterKeyBehaviorInCommandBar() { - onView(withId(R.id.command_bar)).perform( - typeText("Hello"), - closeSoftKeyboard(), - pressKey(KeyEvent.KEYCODE_ENTER), - ) - onView(withId(R.id.command_bar)).check(matches(withText(""))) - } -} From 75d0c4c1d6b74b93235c7490c325f172a2ba5886 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sat, 20 Sep 2025 22:00:44 +0530 Subject: [PATCH 06/10] handle eenter key based on IME actions for correct behavior --- .../main/java/be/scri/helpers/KeyHandler.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/helpers/KeyHandler.kt b/app/src/main/java/be/scri/helpers/KeyHandler.kt index 922c99cd..fa8e6d52 100644 --- a/app/src/main/java/be/scri/helpers/KeyHandler.kt +++ b/app/src/main/java/be/scri/helpers/KeyHandler.kt @@ -4,6 +4,7 @@ package be.scri.helpers import android.content.Context import android.util.Log +import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputConnection import be.scri.services.GeneralKeyboardIME import be.scri.services.GeneralKeyboardIME.ScribeState @@ -235,7 +236,28 @@ class KeyHandler( * editor action) to the main IME class. */ private fun handleEnterKey() { - ime.handleKeycodeEnter() + val inputConnection = ime.currentInputConnection + val editorInfo = ime.currentInputEditorInfo + + if (inputConnection != null && editorInfo != null) { + val imeAction = editorInfo.imeOptions and EditorInfo.IME_MASK_ACTION + + when (imeAction) { + EditorInfo.IME_ACTION_GO, + EditorInfo.IME_ACTION_SEARCH, + EditorInfo.IME_ACTION_SEND, + EditorInfo.IME_ACTION_NEXT, + EditorInfo.IME_ACTION_DONE, + -> { + // performs the editor action + inputConnection.performEditorAction(imeAction) + } + else -> { + // default behaviour for inserting a new line + inputConnection.commitText("\n", 1) + } + } + } } /** From 6c6904f68c644d38015702dcd184456e6baeae4b Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sat, 20 Sep 2025 22:01:22 +0530 Subject: [PATCH 07/10] Test: added the comprehensive tests for Enter key's IME action handling --- .../kotlin/be/scri/helpers/KeyboardTest.kt | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index cb1fe48d..95776725 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later package be.scri.helpers +import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputConnection import android.widget.Button import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -73,9 +74,48 @@ class KeyboardTest { } @Test - fun testEnterKeyBehavior() { - every { mockIME.currentState } returns ScribeState.IDLE + fun testEnterKeyInsertsNewLineForNormalInput() { + every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_NONE } + every { mockInputConnection.commitText(any(), any()) } returns true + + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + verify(exactly = 1) { mockInputConnection.commitText("\n", 1) } + verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } + } + + @Test + fun testEnterKeySendsActionForSearch() { + every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_SEARCH } + every { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEARCH) } returns true + + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + verify(exactly = 1) { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEARCH) } + verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } + verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } + } + + @Test + fun testEnterKeySendsActionForSend() { + every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_SEND } + every { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEND) } returns true + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + verify(exactly = 1) { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEND) } + verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } + verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } + } + + @Test + fun testEnterKeySendsActionForDone() { + every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_DONE } + every { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE) } returns true + + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + verify(exactly = 1) { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE) } verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } } From 9ee47376ded7a2dd7962150209e64ece3128dad7 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Sat, 20 Sep 2025 22:09:45 +0530 Subject: [PATCH 08/10] Fixed the lint issues --- app/src/main/java/be/scri/helpers/KeyHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/helpers/KeyHandler.kt b/app/src/main/java/be/scri/helpers/KeyHandler.kt index fa8e6d52..22ee63af 100644 --- a/app/src/main/java/be/scri/helpers/KeyHandler.kt +++ b/app/src/main/java/be/scri/helpers/KeyHandler.kt @@ -248,7 +248,7 @@ class KeyHandler( EditorInfo.IME_ACTION_SEND, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_DONE, - -> { + -> { // performs the editor action inputConnection.performEditorAction(imeAction) } From 27524e2ee233549ec4507cc5dc690abc9b5a24d3 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Fri, 26 Sep 2025 12:12:08 +0530 Subject: [PATCH 09/10] fix: enter key now checks for commands before doing a new line --- app/src/main/java/be/scri/helpers/KeyHandler.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/be/scri/helpers/KeyHandler.kt b/app/src/main/java/be/scri/helpers/KeyHandler.kt index 22ee63af..a45e23ef 100644 --- a/app/src/main/java/be/scri/helpers/KeyHandler.kt +++ b/app/src/main/java/be/scri/helpers/KeyHandler.kt @@ -236,6 +236,14 @@ class KeyHandler( * editor action) to the main IME class. */ private fun handleEnterKey() { + // step 1: checks if the keyboard is in a command state (not IDLE). + if (ime.currentState != ScribeState.IDLE) { + // reintorducing the call to the state-aware logic for command execution. + ime.handleKeycodeEnter() + return + } + + // step 2: if in IDLE state, proceed with standard IME action/newline logic. val inputConnection = ime.currentInputConnection val editorInfo = ime.currentInputEditorInfo From 8047446be2eb3b25724d3058bd66bc7c7b8072f7 Mon Sep 17 00:00:00 2001 From: jagadeesh-18-bot Date: Fri, 26 Sep 2025 12:12:55 +0530 Subject: [PATCH 10/10] refactor:combined all Enter key tests into a single, parameterized test case --- .../kotlin/be/scri/helpers/KeyboardTest.kt | 101 ++++++++++-------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt index 95776725..6a28bdbd 100644 --- a/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt +++ b/app/src/androidTest/kotlin/be/scri/helpers/KeyboardTest.kt @@ -7,6 +7,7 @@ import android.widget.Button import androidx.test.ext.junit.runners.AndroidJUnit4 import be.scri.services.GeneralKeyboardIME import be.scri.services.GeneralKeyboardIME.ScribeState +import io.mockk.clearMocks import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -14,6 +15,19 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +private enum class EnterKeyExpectation { + PERFORM_ACTION, + COMMIT_NEWLINE, + DEFERRED_TO_IME, +} + +/** this repreesents a single test case for the parameterized Enter key test. */ +private data class EnterKeyTest( + val imeAction: Int, + val scribeState: ScribeState, + val expectation: EnterKeyExpectation, +) + // Unit tests for KeyHandler @RunWith(AndroidJUnit4::class) class KeyboardTest { @@ -34,6 +48,7 @@ class KeyboardTest { every { mockIME.keyboard } returns mockk(relaxed = true) every { mockIME.currentState } returns ScribeState.IDLE every { mockIME.language } returns "German" + every { mockIME.handleKeycodeEnter() } returns Unit keyHandler = KeyHandler(mockIME) suggestionHandler = SuggestionHandler(mockIME) @@ -74,50 +89,50 @@ class KeyboardTest { } @Test - fun testEnterKeyInsertsNewLineForNormalInput() { - every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_NONE } - every { mockInputConnection.commitText(any(), any()) } returns true - - keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") - - verify(exactly = 1) { mockInputConnection.commitText("\n", 1) } - verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } - } - - @Test - fun testEnterKeySendsActionForSearch() { - every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_SEARCH } - every { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEARCH) } returns true - - keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") - - verify(exactly = 1) { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEARCH) } - verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } - verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } - } - - @Test - fun testEnterKeySendsActionForSend() { - every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_SEND } - every { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEND) } returns true - - keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") - - verify(exactly = 1) { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEND) } - verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } - verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } - } - - @Test - fun testEnterKeySendsActionForDone() { - every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = EditorInfo.IME_ACTION_DONE } - every { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE) } returns true - - keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + fun testEnterKeyBehavior_Parameterized() { + val testCases = + listOf( + EnterKeyTest(EditorInfo.IME_ACTION_NONE, ScribeState.IDLE, EnterKeyExpectation.COMMIT_NEWLINE), + EnterKeyTest(EditorInfo.IME_ACTION_SEARCH, ScribeState.IDLE, EnterKeyExpectation.PERFORM_ACTION), + EnterKeyTest(EditorInfo.IME_ACTION_SEND, ScribeState.IDLE, EnterKeyExpectation.PERFORM_ACTION), + EnterKeyTest(EditorInfo.IME_ACTION_DONE, ScribeState.IDLE, EnterKeyExpectation.PERFORM_ACTION), + EnterKeyTest(EditorInfo.IME_ACTION_SEND, ScribeState.TRANSLATE, EnterKeyExpectation.DEFERRED_TO_IME), + EnterKeyTest(EditorInfo.IME_ACTION_NONE, ScribeState.CONJUGATE, EnterKeyExpectation.DEFERRED_TO_IME), + EnterKeyTest(EditorInfo.IME_ACTION_SEARCH, ScribeState.PLURAL, EnterKeyExpectation.DEFERRED_TO_IME), + ) + + testCases.forEach { case -> + every { mockIME.currentInputEditorInfo } returns EditorInfo().apply { imeOptions = case.imeAction } + every { mockIME.currentState } returns case.scribeState + + keyHandler.handleKey(KeyboardBase.KEYCODE_ENTER, "en") + + when (case.expectation) { + EnterKeyExpectation.PERFORM_ACTION -> { + verify(exactly = 1) { mockInputConnection.performEditorAction(case.imeAction) } + verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } + verify(exactly = 0) { mockIME.handleKeycodeEnter() } + } + EnterKeyExpectation.COMMIT_NEWLINE -> { + verify(exactly = 1) { mockInputConnection.commitText("\n", 1) } + verify(exactly = 0) { mockInputConnection.performEditorAction(any()) } + verify(exactly = 0) { mockIME.handleKeycodeEnter() } + } + EnterKeyExpectation.DEFERRED_TO_IME -> { + // ensures the custom command logic takes precedence + verify(exactly = 1) { mockIME.handleKeycodeEnter() } + verify(exactly = 0) { mockInputConnection.performEditorAction(any()) } + verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } + } + } - verify(exactly = 1) { mockInputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE) } - verify(exactly = 0) { mockInputConnection.commitText(any(), any()) } - verify(exactly = 0) { mockInputConnection.sendKeyEvent(any()) } + // cleans up mocks for the next iteration in the loop + clearMocks(mockInputConnection, mockIME) + every { mockIME.currentInputConnection } returns mockInputConnection + // fix: restores the mock using returns Unit + every { mockIME.handleKeycodeEnter() } returns Unit + every { mockIME.keyboard } returns mockk(relaxed = true) + } } @Test