1+ package fr.free.nrw.commons.wikidata
2+
3+ import fr.free.nrw.commons.wikidata.model.AddEditTagResponse
4+ import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse
5+ import io.reactivex.Observable
6+ import okhttp3.RequestBody
7+ import org.junit.Before
8+ import org.junit.Test
9+ import org.mockito.ArgumentMatchers.*
10+ import org.mockito.InjectMocks
11+ import org.mockito.Mock
12+ import org.mockito.Mockito.`when`
13+ import org.mockito.Mockito.mock
14+ import org.mockito.MockitoAnnotations
15+ import org.wikipedia.dataclient.mwapi.MwQueryResponse
16+ import org.wikipedia.dataclient.mwapi.MwQueryResult
17+
18+ class WikidataClientTest {
19+
20+ @Mock
21+ internal var wikidataInterface: WikidataInterface ? = null
22+
23+ @InjectMocks
24+ var wikidataClient: WikidataClient ? = null
25+
26+ @Before
27+ @Throws(Exception ::class )
28+ fun setUp () {
29+ MockitoAnnotations .initMocks(this )
30+ val mwQueryResponse = mock(MwQueryResponse ::class .java)
31+ val mwQueryResult = mock(MwQueryResult ::class .java)
32+ `when `(mwQueryResult!! .csrfToken()).thenReturn(" test_token" )
33+ `when `(mwQueryResponse.query()).thenReturn(mwQueryResult)
34+ `when `(wikidataInterface!! .getCsrfToken())
35+ .thenReturn(Observable .just(mwQueryResponse))
36+ }
37+
38+ @Test
39+ fun createClaim () {
40+ `when `(wikidataInterface!! .postCreateClaim(any(RequestBody ::class .java),
41+ any(RequestBody ::class .java),
42+ any(RequestBody ::class .java),
43+ any(RequestBody ::class .java),
44+ any(RequestBody ::class .java),
45+ any(RequestBody ::class .java)))
46+ .thenReturn(Observable .just(mock(WbCreateClaimResponse ::class .java)))
47+ wikidataClient!! .createClaim(" Q1" , " test.jpg" )
48+ }
49+
50+ @Test
51+ fun addEditTag () {
52+ `when `(wikidataInterface!! .addEditTag(anyString(), anyString(), anyString(), anyString()))
53+ .thenReturn(Observable .just(mock(AddEditTagResponse ::class .java)))
54+ wikidataClient!! .addEditTag(1L , " test" , " test" )
55+ }
56+ }
0 commit comments