mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
With more unit test cases (#3269)
This commit is contained in:
parent
d2fb3b36e7
commit
f27749fa51
7 changed files with 139 additions and 30 deletions
|
|
@ -0,0 +1,46 @@
|
|||
package fr.free.nrw.commons.auth
|
||||
|
||||
import com.nhaarman.mockito_kotlin.verify
|
||||
import io.reactivex.Observable
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.wikipedia.dataclient.Service
|
||||
import org.wikipedia.dataclient.mwapi.MwPostResponse
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResult
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class LogoutClientTest {
|
||||
|
||||
@Mock @field:[Inject Named("commons-service")]
|
||||
internal var service: Service? = null
|
||||
|
||||
@InjectMocks
|
||||
var logoutClient: LogoutClient? = null
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
val mwQueryResponse = Mockito.mock(MwQueryResponse::class.java)
|
||||
val mwQueryResult = Mockito.mock(MwQueryResult::class.java)
|
||||
`when`(mwQueryResult!!.csrfToken()).thenReturn("test_token")
|
||||
`when`(mwQueryResponse.query()).thenReturn(mwQueryResult)
|
||||
`when`(service!!.csrfToken)
|
||||
.thenReturn(Observable.just(mwQueryResponse))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun postLogout() {
|
||||
`when`(service!!.postLogout(anyString())).thenReturn(Observable.just(mock(MwPostResponse::class.java)))
|
||||
logoutClient!!.postLogout()
|
||||
verify(service, times(1))!!.csrfToken
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue