#3820 Convert CategoryImagesListFragment to use Pagination (#3821)

This commit is contained in:
Seán Mac Gillicuddy 2020-06-25 10:38:58 +01:00 committed by GitHub
parent 0e5ba98c2e
commit 7817518462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 245 additions and 418 deletions

View file

@ -0,0 +1,49 @@
package fr.free.nrw.commons.explore.categories.media
import com.nhaarman.mockitokotlin2.never
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.explore.paging.LiveDataConverter
import fr.free.nrw.commons.media.MediaClient
import io.reactivex.Single
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
class PageableCategoriesMediaDataSourceTest {
@Mock
lateinit var mediaClient: MediaClient
@Mock
lateinit var liveDataConverter: LiveDataConverter
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
}
@Test
fun `loadFunction calls reset at position 0`() {
val dataSource =
PageableCategoriesMediaDataSource(liveDataConverter, mediaClient)
dataSource.onQueryUpdated("test")
whenever(mediaClient.getMediaListFromCategory("test"))
.thenReturn(Single.just(emptyList()))
assertThat(dataSource.loadFunction(-1, 0), `is`(emptyList()))
verify(mediaClient).resetCategoryContinuation("test")
}
@Test
fun `loadFunction does not call reset at any other position`() {
val dataSource =
PageableCategoriesMediaDataSource(liveDataConverter, mediaClient)
dataSource.onQueryUpdated("test")
whenever(mediaClient.getMediaListFromCategory("test"))
.thenReturn(Single.just(emptyList()))
assertThat(dataSource.loadFunction(-1, 1), `is`(emptyList()))
verify(mediaClient, never()).resetCategoryContinuation("test")
}
}

View file

@ -3,7 +3,7 @@ package fr.free.nrw.commons.explore.categroies
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.category.CategoryClient
import fr.free.nrw.commons.explore.categories.PageableCategoriesDataSource
import fr.free.nrw.commons.explore.categories.search.PageableCategoriesDataSource
import io.reactivex.Observable
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.explore.depictions.child
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
import com.nhaarman.mockitokotlin2.whenever
import depictedItem
import fr.free.nrw.commons.explore.paging.LiveDataConverter

View file

@ -164,7 +164,9 @@ class MediaClientTest {
val entity: Entities.Entity = mock()
whenever(entities.entities()).thenReturn(mapOf("id" to entity))
val media: Media = mock()
whenever(mediaConverter!!.convert(queryPage, entity)).thenReturn(media)
val imageInfo = mock<ImageInfo>()
whenever(queryPage.imageInfo()).thenReturn(imageInfo)
whenever(mediaConverter!!.convert(queryPage, entity, imageInfo)).thenReturn(media)
return Pair(mockResponse, media)
}