Removed butterknife from login activity (#5380)

* Removed butterknife view bindings

* Migrated click listeners to view binding

* Migrate onEditorAction to use ViewBinding

* Finally, removed butterknife
This commit is contained in:
Paul Hawke 2023-11-11 07:54:08 -06:00 committed by GitHub
parent 9620f6eee0
commit 861d2b9bf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 110 deletions

View file

@ -10,6 +10,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.Button
import android.widget.TextView
import androidx.test.core.app.ApplicationProvider
import fr.free.nrw.commons.R
import fr.free.nrw.commons.TestAppAdapter
@ -55,7 +56,7 @@ class LoginActivityUnitTests {
private lateinit var keyEvent: KeyEvent
@Mock
private lateinit var loginButton: Button
private lateinit var textView: TextView
@Mock
private lateinit var bundle: Bundle
@ -95,40 +96,12 @@ class LoginActivityUnitTests {
fun testOnEditorActionCaseDefault() {
val method: Method = LoginActivity::class.java.getDeclaredMethod(
"onEditorAction",
TextView::class.java,
Int::class.java,
KeyEvent::class.java
)
method.isAccessible = true
method.invoke(activity, 0, keyEvent)
}
@Test
@Throws(Exception::class)
fun testOnEditorActionCaseLoginEnabledFirstCase() {
Whitebox.setInternalState(activity, "loginButton", loginButton)
`when`(loginButton.isEnabled).thenReturn(true)
val method: Method = LoginActivity::class.java.getDeclaredMethod(
"onEditorAction",
Int::class.java,
KeyEvent::class.java
)
method.isAccessible = true
method.invoke(activity, EditorInfo.IME_ACTION_DONE, keyEvent)
}
@Test
@Throws(Exception::class)
fun testOnEditorActionCaseLoginEnabledSecondCase() {
Whitebox.setInternalState(activity, "loginButton", loginButton)
`when`(loginButton.isEnabled).thenReturn(true)
`when`(keyEvent.keyCode).thenReturn(KeyEvent.KEYCODE_ENTER)
val method: Method = LoginActivity::class.java.getDeclaredMethod(
"onEditorAction",
Int::class.java,
KeyEvent::class.java
)
method.isAccessible = true
method.invoke(activity, 0, keyEvent)
method.invoke(activity, textView, 0, keyEvent)
}
@Test