forked from commons-app/apps-android-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With wikidata client tests (commons-app#3240)
- Loading branch information
1 parent
8472c63
commit 0f5422f
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/test/kotlin/fr/free/nrw/commons/wikidata/WikidataClientTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package fr.free.nrw.commons.wikidata | ||
|
||
import fr.free.nrw.commons.wikidata.model.AddEditTagResponse | ||
import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse | ||
import io.reactivex.Observable | ||
import okhttp3.RequestBody | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.ArgumentMatchers.* | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.Mockito.mock | ||
import org.mockito.MockitoAnnotations | ||
import org.wikipedia.dataclient.mwapi.MwQueryResponse | ||
import org.wikipedia.dataclient.mwapi.MwQueryResult | ||
|
||
class WikidataClientTest { | ||
|
||
@Mock | ||
internal var wikidataInterface: WikidataInterface? = null | ||
|
||
@InjectMocks | ||
var wikidataClient: WikidataClient? = null | ||
|
||
@Before | ||
@Throws(Exception::class) | ||
fun setUp() { | ||
MockitoAnnotations.initMocks(this) | ||
val mwQueryResponse = mock(MwQueryResponse::class.java) | ||
val mwQueryResult = mock(MwQueryResult::class.java) | ||
`when`(mwQueryResult!!.csrfToken()).thenReturn("test_token") | ||
`when`(mwQueryResponse.query()).thenReturn(mwQueryResult) | ||
`when`(wikidataInterface!!.getCsrfToken()) | ||
.thenReturn(Observable.just(mwQueryResponse)) | ||
} | ||
|
||
@Test | ||
fun createClaim() { | ||
`when`(wikidataInterface!!.postCreateClaim(any(RequestBody::class.java), | ||
any(RequestBody::class.java), | ||
any(RequestBody::class.java), | ||
any(RequestBody::class.java), | ||
any(RequestBody::class.java), | ||
any(RequestBody::class.java))) | ||
.thenReturn(Observable.just(mock(WbCreateClaimResponse::class.java))) | ||
wikidataClient!!.createClaim("Q1", "test.jpg") | ||
} | ||
|
||
@Test | ||
fun addEditTag() { | ||
`when`(wikidataInterface!!.addEditTag(anyString(), anyString(), anyString(), anyString())) | ||
.thenReturn(Observable.just(mock(AddEditTagResponse::class.java))) | ||
wikidataClient!!.addEditTag(1L, "test", "test") | ||
} | ||
} |