-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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
- Loading branch information
1 parent
0affe71
commit afdeaae
Showing
5 changed files
with
58 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/src/test/kotlin/fr/free/nrw/commons/category/CategoriesModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters