Skip to content

Commit

Permalink
Update Mockito and fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vgaidarji committed Mar 15, 2024
1 parent ec5e262 commit 48b19f6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {
implementation 'com.android.support:design:28.0.0'
// todo: firebase app distribution
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:2.0.2-beta'
testImplementation 'org.mockito:mockito-core:5.11.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/vgaidarji/cimatters/LoginPresenter.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.vgaidarji.cimatters

import android.util.Log

internal class LoginPresenter(private val view: LoginView) {
fun onLoginClick(email: String, password: String) {
Log.d("test123","email + ${email}, password + ${password}, ${email == EMAIL && password == PASSWORD}")
if (email == EMAIL && password == PASSWORD) {
view.openNextActivity()
} else {
Expand Down
10 changes: 5 additions & 5 deletions app/src/test/java/com/vgaidarji/cimatters/LoginPresenterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ package com.vgaidarji.cimatters

import org.junit.Before
import org.junit.Test
import org.mockito.Matchers
import org.mockito.Mockito
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.*

class LoginPresenterTest {
private lateinit var view: LoginView
private var presenter: LoginPresenter? = null
@Before
@Throws(Exception::class)
fun setUp() {
view = Mockito.mock(LoginView::class.java)
view = mock(LoginView::class.java)
presenter = LoginPresenter(view)
}

@Test
@Throws(Exception::class)
fun onLoginClick_shouldOpenNextActivityForAllowedCredentials() {
presenter!!.onLoginClick("[email protected]", "1111")
Mockito.verify(view)?.openNextActivity()
verify(view)?.openNextActivity()
}

@Test
@Throws(Exception::class)
fun onLoginClick_shouldShowErrorForIncorrectCredentials() {
presenter!!.onLoginClick("[email protected]", "not_a_password")
Mockito.verify(view)?.showError(Matchers.anyString())
verify(view)?.showError(ArgumentMatchers.anyString())
}
}

0 comments on commit 48b19f6

Please sign in to comment.