mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
* CategoryClient: fix category search case-sensitivity by converting to lower case as MW api is inherently case-sensitive, the results obtained will be same * CategoryItem: reverting javadoc changes * CategoriesModel: make category search case-insensitive * CategoryItem: fix whitespaces * Add tests for case-insensitivity * CategoryClientTest: add more test cases * CategoryClientTest: fix travis ci test * CategoriesModelTest: changes mage to CategoriesModel and tested
This commit is contained in:
parent
0affe71745
commit
afdeaae075
5 changed files with 58 additions and 39 deletions
|
|
@ -0,0 +1,50 @@
|
|||
package fr.free.nrw.commons.category
|
||||
|
||||
import io.reactivex.Observable
|
||||
import junit.framework.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.*
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryPage
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResult
|
||||
|
||||
//class for testing CategoriesModel class
|
||||
class CategoriesModelTest {
|
||||
@Mock
|
||||
internal var categoryInterface: CategoryInterface? = null
|
||||
|
||||
@Mock
|
||||
internal var categoryItem: CategoryItem? = null
|
||||
|
||||
@InjectMocks
|
||||
var categoryClient: CategoryClient? = null
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
}
|
||||
|
||||
// Test Case for verifying that Categories search (MW api calls) are case-insensitive
|
||||
@Test
|
||||
fun searchAllFoundCaseTest() {
|
||||
val mwQueryPage = Mockito.mock(MwQueryPage::class.java)
|
||||
Mockito.`when`(mwQueryPage.title()).thenReturn("Category:Test")
|
||||
val mwQueryResult = Mockito.mock(MwQueryResult::class.java)
|
||||
Mockito.`when`(mwQueryResult.pages()).thenReturn(listOf(mwQueryPage))
|
||||
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
||||
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||
val categoriesModel: CategoriesModel = CategoriesModel(categoryClient,null,null)
|
||||
|
||||
Mockito.`when`(categoryInterface!!.searchCategoriesForPrefix(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt()))
|
||||
.thenReturn(Observable.just(mockResponse))
|
||||
|
||||
// Checking if both return "Test"
|
||||
val actualCategoryName = categoriesModel!!.searchAll("tes",null).blockingFirst()
|
||||
assertEquals("Test", actualCategoryName.getName())
|
||||
|
||||
val actualCategoryNameCaps = categoriesModel!!.searchAll("Tes",null).blockingFirst()
|
||||
assertEquals("Test", actualCategoryNameCaps.getName())
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +58,7 @@ class CategoryClientTest {
|
|||
{ fail("SearchCategories returned element when it shouldn't have.") },
|
||||
{ s -> throw s })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun searchCategoriesForPrefixFound() {
|
||||
val mwQueryPage = Mockito.mock(MwQueryPage::class.java)
|
||||
|
|
@ -92,6 +93,7 @@ class CategoryClientTest {
|
|||
{ fail("SearchCategories returned element when it shouldn't have.") },
|
||||
{ s -> throw s })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getParentCategoryListFound() {
|
||||
val mwQueryPage = Mockito.mock(MwQueryPage::class.java)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue