mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
#3822 Convert SubCategoryImagesListFragment to use Pagination - add tests for ParentCategoriesDataSource
This commit is contained in:
parent
0f091600e8
commit
f384a688a8
3 changed files with 50 additions and 14 deletions
|
|
@ -82,7 +82,7 @@ class CategoryClientTest {
|
||||||
@Test
|
@Test
|
||||||
fun getParentCategoryListFound() {
|
fun getParentCategoryListFound() {
|
||||||
val mockResponse = withMockResponse("Category:Test")
|
val mockResponse = withMockResponse("Category:Test")
|
||||||
whenever(categoryInterface.getParentCategoryList(anyString()))
|
whenever(categoryInterface.getParentCategoryList(anyString(), anyMap()))
|
||||||
.thenReturn(Single.just(mockResponse))
|
.thenReturn(Single.just(mockResponse))
|
||||||
categoryClient.getParentCategoryList("tes")
|
categoryClient.getParentCategoryList("tes")
|
||||||
.test()
|
.test()
|
||||||
|
|
@ -92,7 +92,7 @@ class CategoryClientTest {
|
||||||
@Test
|
@Test
|
||||||
fun getParentCategoryListNull() {
|
fun getParentCategoryListNull() {
|
||||||
val mockResponse = withNullPages()
|
val mockResponse = withNullPages()
|
||||||
whenever(categoryInterface.getParentCategoryList(anyString()))
|
whenever(categoryInterface.getParentCategoryList(anyString(), anyMap()))
|
||||||
.thenReturn(Single.just(mockResponse))
|
.thenReturn(Single.just(mockResponse))
|
||||||
categoryClient.getParentCategoryList("tes")
|
categoryClient.getParentCategoryList("tes")
|
||||||
.test()
|
.test()
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,6 @@ class ContributionBoundaryCallbackTest {
|
||||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
||||||
Single.just(listOf(mock(Media::class.java)))
|
Single.just(listOf(mock(Media::class.java)))
|
||||||
)
|
)
|
||||||
whenever(mediaClient.doesMediaListForUserHaveMorePages(anyString()))
|
|
||||||
.thenReturn(true)
|
|
||||||
contributionBoundaryCallback.onZeroItemsLoaded()
|
contributionBoundaryCallback.onZeroItemsLoaded()
|
||||||
verify(repository).save(anyList<Contribution>());
|
verify(repository).save(anyList<Contribution>());
|
||||||
verify(mediaClient).getMediaListForUser(anyString());
|
verify(mediaClient).getMediaListForUser(anyString());
|
||||||
|
|
@ -73,8 +71,6 @@ class ContributionBoundaryCallbackTest {
|
||||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
||||||
Single.just(listOf(mock(Media::class.java)))
|
Single.just(listOf(mock(Media::class.java)))
|
||||||
)
|
)
|
||||||
whenever(mediaClient.doesMediaListForUserHaveMorePages(anyString()))
|
|
||||||
.thenReturn(true)
|
|
||||||
contributionBoundaryCallback.onItemAtEndLoaded(mock(Contribution::class.java))
|
contributionBoundaryCallback.onItemAtEndLoaded(mock(Contribution::class.java))
|
||||||
verify(repository).save(anyList());
|
verify(repository).save(anyList());
|
||||||
verify(mediaClient).getMediaListForUser(anyString());
|
verify(mediaClient).getMediaListForUser(anyString());
|
||||||
|
|
@ -88,8 +84,6 @@ class ContributionBoundaryCallbackTest {
|
||||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
||||||
Single.just(listOf(mock(Media::class.java)))
|
Single.just(listOf(mock(Media::class.java)))
|
||||||
)
|
)
|
||||||
whenever(mediaClient.doesMediaListForUserHaveMorePages(anyString()))
|
|
||||||
.thenReturn(true)
|
|
||||||
contributionBoundaryCallback.onItemAtFrontLoaded(mock(Contribution::class.java))
|
contributionBoundaryCallback.onItemAtFrontLoaded(mock(Contribution::class.java))
|
||||||
verify(repository).save(anyList());
|
verify(repository).save(anyList());
|
||||||
verify(mediaClient).getMediaListForUser(anyString());
|
verify(mediaClient).getMediaListForUser(anyString());
|
||||||
|
|
@ -103,8 +97,6 @@ class ContributionBoundaryCallbackTest {
|
||||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
||||||
Single.just(listOf(mock(Media::class.java)))
|
Single.just(listOf(mock(Media::class.java)))
|
||||||
)
|
)
|
||||||
whenever(mediaClient.doesMediaListForUserHaveMorePages(anyString()))
|
|
||||||
.thenReturn(true)
|
|
||||||
contributionBoundaryCallback.fetchContributions()
|
contributionBoundaryCallback.fetchContributions()
|
||||||
verify(repository).save(anyList());
|
verify(repository).save(anyList());
|
||||||
verify(mediaClient).getMediaListForUser(anyString());
|
verify(mediaClient).getMediaListForUser(anyString());
|
||||||
|
|
@ -113,8 +105,6 @@ class ContributionBoundaryCallbackTest {
|
||||||
@Test
|
@Test
|
||||||
fun testFetchContributionsForEndOfList() {
|
fun testFetchContributionsForEndOfList() {
|
||||||
whenever(sessionManager.userName).thenReturn("Test")
|
whenever(sessionManager.userName).thenReturn("Test")
|
||||||
whenever(mediaClient.doesMediaListForUserHaveMorePages(anyString()))
|
|
||||||
.thenReturn(false)
|
|
||||||
contributionBoundaryCallback.fetchContributions()
|
contributionBoundaryCallback.fetchContributions()
|
||||||
verify(mediaClient, times(0)).getMediaListForUser(anyString())
|
verify(mediaClient, times(0)).getMediaListForUser(anyString())
|
||||||
verifyNoMoreInteractions(repository)
|
verifyNoMoreInteractions(repository)
|
||||||
|
|
@ -123,8 +113,6 @@ class ContributionBoundaryCallbackTest {
|
||||||
@Test
|
@Test
|
||||||
fun testFetchContributionsFailed() {
|
fun testFetchContributionsFailed() {
|
||||||
whenever(sessionManager.userName).thenReturn("Test")
|
whenever(sessionManager.userName).thenReturn("Test")
|
||||||
whenever(mediaClient.doesMediaListForUserHaveMorePages(anyString()))
|
|
||||||
.thenReturn(true)
|
|
||||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(Single.error(Exception("Error")))
|
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(Single.error(Exception("Error")))
|
||||||
contributionBoundaryCallback.fetchContributions()
|
contributionBoundaryCallback.fetchContributions()
|
||||||
verifyZeroInteractions(repository);
|
verifyZeroInteractions(repository);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package fr.free.nrw.commons.explore.categories.parent
|
||||||
|
|
||||||
|
import com.nhaarman.mockitokotlin2.never
|
||||||
|
import com.nhaarman.mockitokotlin2.verify
|
||||||
|
import com.nhaarman.mockitokotlin2.whenever
|
||||||
|
import fr.free.nrw.commons.category.CategoryClient
|
||||||
|
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||||
|
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 PageableParentCategoriesDataSourceTest{
|
||||||
|
@Mock
|
||||||
|
lateinit var categoryClient: CategoryClient
|
||||||
|
@Mock
|
||||||
|
lateinit var liveDataConverter: LiveDataConverter
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `loadFunction calls reset at position 0`() {
|
||||||
|
val dataSource =
|
||||||
|
PageableParentCategoriesDataSource(liveDataConverter, categoryClient)
|
||||||
|
dataSource.onQueryUpdated("test")
|
||||||
|
whenever(categoryClient.getParentCategoryList("test"))
|
||||||
|
.thenReturn(Single.just(emptyList()))
|
||||||
|
assertThat(dataSource.loadFunction(-1, 0), `is`(emptyList()))
|
||||||
|
verify(categoryClient).resetParentCategoryContinuation("test")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `loadFunction does not call reset at any other position`() {
|
||||||
|
val dataSource =
|
||||||
|
PageableParentCategoriesDataSource(liveDataConverter, categoryClient)
|
||||||
|
dataSource.onQueryUpdated("test")
|
||||||
|
whenever(categoryClient.getParentCategoryList("test"))
|
||||||
|
.thenReturn(Single.just(emptyList()))
|
||||||
|
assertThat(dataSource.loadFunction(-1, 1), `is`(emptyList()))
|
||||||
|
verify(categoryClient, never()).resetParentCategoryContinuation("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue