Convert wikidata/mwapi to kotlin (part 4) (#6010)

* Convert ImageDetails to kotlin

* Convert MwException/MwServiceError to kotlin

* Convert ListUserResponse to kotlin

* Convert MwPostResponse to kotlin

* Convert MwQueryResponse to kotlin

* Convert MwQueryResult to kotlin

* Convert MwQueryPage to kotlin

---------

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
Paul Hawke 2024-12-09 21:18:42 -06:00 committed by GitHub
parent 56ada36b83
commit 73311970c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 474 additions and 615 deletions

View file

@ -139,7 +139,7 @@ class ReviewControllerTest {
@Test
fun testSendThanks() {
shadowOf(Looper.getMainLooper()).idle()
whenever(firstRevision.revisionId).thenReturn(1)
whenever(firstRevision.revisionId()).thenReturn(1)
Whitebox.setInternalState(controller, "firstRevision", firstRevision)
controller.sendThanks(activity)
assertEquals(

View file

@ -95,11 +95,11 @@ class ReviewHelperTest {
@Test
fun getFirstRevisionOfFile() {
val rev1 = mock<MwQueryPage.Revision>()
whenever(rev1.user).thenReturn("TestUser")
whenever(rev1.revisionId).thenReturn(1L)
whenever(rev1.user()).thenReturn("TestUser")
whenever(rev1.revisionId()).thenReturn(1L)
val rev2 = mock<MwQueryPage.Revision>()
whenever(rev2.user).thenReturn("TestUser")
whenever(rev2.revisionId).thenReturn(2L)
whenever(rev2.user()).thenReturn("TestUser")
whenever(rev2.revisionId()).thenReturn(2L)
val page = setupMedia("Test.jpg", rev1, rev2)
whenever(mwQueryResult.firstPage()).thenReturn(page)
@ -107,7 +107,7 @@ class ReviewHelperTest {
val firstRevisionOfFile = reviewHelper.getFirstRevisionOfFile("Test.jpg").blockingFirst()
assertEquals(1, firstRevisionOfFile.revisionId)
assertEquals(1, firstRevisionOfFile.revisionId())
}
@Test

View file

@ -0,0 +1,48 @@
package fr.free.nrw.commons.wikidata.mwapi
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class MwQueryPageTest {
private val didymUsage = MwQueryPage.FileUsage().apply {
setTitle("User:Didym/Mobile upload")
}
@Test
fun checkWhetherFileIsUsedInWikis_nullGlobalUsages() {
assertFalse(checkWhetherFileIsUsedInWikis(null, null))
}
@Test
fun checkWhetherFileIsUsedInWikis_emptyGlobalUsages() {
assertFalse(checkWhetherFileIsUsedInWikis(emptyList(), null))
}
@Test
fun checkWhetherFileIsUsedInWikis_emptyFileUsage() {
assertFalse(checkWhetherFileIsUsedInWikis(emptyList(), emptyList()))
}
@Test
fun checkWhetherFileIsUsedInWikis_singleGlobalUsages() {
assertTrue(checkWhetherFileIsUsedInWikis(listOf(MwQueryPage.GlobalUsage()), null))
}
@Test
fun checkWhetherFileIsUsedInWikis_singleFileUsageContainsDidym() {
assertFalse(checkWhetherFileIsUsedInWikis(null, listOf(didymUsage)))
}
@Test
fun checkWhetherFileIsUsedInWikis_didymIgnoredInList() {
assertTrue(
checkWhetherFileIsUsedInWikis(
null, listOf(
didymUsage, MwQueryPage.FileUsage().apply { setTitle("somewhere else") }
)
)
)
}
}