mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Issue-5662-kotlinstyle (#5833)
* *.kt: bulk correction of formatting using ktlint --format * *.kt: replace wildcard imports and second stage auto format ktlint --format * QuizQuestionTest.kt: modified property names to camel case to meet ktlint standard * LevelControllerTest.kt: modified property names to camel case to meet ktlint standard * QuizActivityUnitTest.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: modified property names to camel case to meet ktlint standard * UploadWorker.kt: modified property names to camel case to meet ktlint standard * UploadClient.kt: modified property names to camel case to meet ktlint standard * BasePagingPresenter.kt: modified property names to camel case to meet ktlint standard * DescriptionEditActivity.kt: modified property names to camel case to meet ktlint standard * OnSwipeTouchListener.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: corrected excessive line length to meet ktlint standard * DepictedItem.kt: corrected property name format and catch format to for ktlint standard * UploadCategoryAdapter.kt: corrected class definition format to meet ktlint standard * CustomSelectorActivity.kt: reformatted function names to first letter lowercase to meet ktlint standard * MediaDetailFragmentUnitTests.kt: fix string literal indentation to meet ktlint standard * NotForUploadDao.kt: file renamed to match class name, new file NotForUploadStatusDao.kt * UploadedDao.kt: file renamed to match class name, new file UploadedStatusDao.kt * Urls.kt: fixed excessive line length for ktLint standard * Snak_partial.kt & Statement_partial.kt: refactored to remove underscores in class names to meet ktLint standard * *.kt: fixed consecutive KDOC error for ktLint * PageableBaseDataSourceTest.kt & UploadPresenterTest.kt: fixed excessive line lengths to meet ktLint standard * CheckboxTriStatesTest.kt: renamed file to match class name to meet ktLint standard * .kt: resolved backing-property-naming error in ktLint, made matching properties public, matched names and refactored * TestConnectionFactory.kt: fixed property naming to adhere to ktLint standard
This commit is contained in:
parent
950539c55c
commit
2d82a430c4
405 changed files with 11032 additions and 9137 deletions
|
|
@ -18,11 +18,9 @@ import org.robolectric.fakes.RoboMenu
|
|||
import org.robolectric.fakes.RoboMenuItem
|
||||
import org.robolectric.shadows.ShadowActivity
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class AboutActivityUnitTests {
|
||||
|
||||
private lateinit var activity: AboutActivity
|
||||
|
||||
private lateinit var context: Context
|
||||
|
|
@ -116,5 +114,4 @@ class AboutActivityUnitTests {
|
|||
fun testOnSupportNavigateUp() {
|
||||
activity.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,16 +8,18 @@ import org.mockito.Mock
|
|||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class FakeContextWrapper(base: Context?) : ContextWrapper(base) {
|
||||
|
||||
class FakeContextWrapper(
|
||||
base: Context?,
|
||||
) : ContextWrapper(base) {
|
||||
@Mock
|
||||
private lateinit var mMockAccountManager: AccountManager
|
||||
|
||||
override fun getSystemService(name: String): Any {
|
||||
return if (ACCOUNT_SERVICE == name) {
|
||||
override fun getSystemService(name: String): Any =
|
||||
if (ACCOUNT_SERVICE == name) {
|
||||
mMockAccountManager
|
||||
} else super.getSystemService(name)
|
||||
}
|
||||
} else {
|
||||
super.getSystemService(name)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ACCOUNT = Account("test@example.com", BuildConfig.ACCOUNT_TYPE)
|
||||
|
|
@ -27,7 +29,8 @@ class FakeContextWrapper(base: Context?) : ContextWrapper(base) {
|
|||
init {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
Mockito.`when`(mMockAccountManager.accounts).thenReturn(ACCOUNTS)
|
||||
Mockito.`when`(mMockAccountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE))
|
||||
Mockito
|
||||
.`when`(mMockAccountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE))
|
||||
.thenReturn(ACCOUNTS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,20 +7,23 @@ import org.mockito.Mock
|
|||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class FakeContextWrapperWithException(base: Context?) : ContextWrapper(base) {
|
||||
|
||||
class FakeContextWrapperWithException(
|
||||
base: Context?,
|
||||
) : ContextWrapper(base) {
|
||||
@Mock
|
||||
private lateinit var mMockAccountManager: AccountManager
|
||||
|
||||
override fun getSystemService(name: String): Any {
|
||||
return if (ACCOUNT_SERVICE == name) {
|
||||
override fun getSystemService(name: String): Any =
|
||||
if (ACCOUNT_SERVICE == name) {
|
||||
mMockAccountManager
|
||||
} else super.getSystemService(name)
|
||||
}
|
||||
} else {
|
||||
super.getSystemService(name)
|
||||
}
|
||||
|
||||
init {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
Mockito.`when`(mMockAccountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE))
|
||||
Mockito
|
||||
.`when`(mMockAccountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE))
|
||||
.thenThrow(SecurityException("Permission Denied"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ class LatLngTests {
|
|||
assertPrettyCoordinateString("0.0 S, 1.0 W", place)
|
||||
}
|
||||
|
||||
private fun assertPrettyCoordinateString(expected: String, place: LatLng) =
|
||||
assertEquals(expected, place.prettyCoordinateString)
|
||||
private fun assertPrettyCoordinateString(
|
||||
expected: String,
|
||||
place: LatLng,
|
||||
) = assertEquals(expected, place.prettyCoordinateString)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
/**
|
||||
* Test methods in media data extractor
|
||||
*/
|
||||
class MediaDataExtractorTest {
|
||||
|
||||
@Mock
|
||||
internal var mediaClient: MediaClient? = null
|
||||
|
||||
@InjectMocks
|
||||
var mediaDataExtractor: MediaDataExtractor? = null
|
||||
|
||||
|
|
@ -38,17 +36,17 @@ class MediaDataExtractorTest {
|
|||
@Test
|
||||
fun fetchMediaDetails() {
|
||||
`when`(mediaClient?.getMedia(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(mock(Media::class.java)))
|
||||
.thenReturn(Single.just(mock(Media::class.java)))
|
||||
|
||||
`when`(mediaClient?.checkPageExistsUsingTitle(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(true))
|
||||
.thenReturn(Single.just(true))
|
||||
|
||||
`when`(mediaClient?.getPageHtml(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just("Test"))
|
||||
.thenReturn(Single.just("Test"))
|
||||
|
||||
//val fetchMediaDetails = mediaDataExtractor?.fetchMediaDetails("File:Test.jpg", null)
|
||||
// val fetchMediaDetails = mediaDataExtractor?.fetchMediaDetails("File:Test.jpg", null)
|
||||
|
||||
//assertTrue(fetchMediaDetails is Media)
|
||||
// assertTrue(fetchMediaDetails is Media)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -56,4 +54,4 @@ class MediaDataExtractorTest {
|
|||
`when`(mediaDataExtractor?.getCurrentWikiText(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just("Test"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,3 @@ class MediaTest {
|
|||
assertEquals("Example 1 2", m.displayTitle)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,13 @@ import fr.free.nrw.commons.nearby.Label
|
|||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.nearby.Sitelinks
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
import fr.free.nrw.commons.wikidata.model.DataValue
|
||||
import fr.free.nrw.commons.wikidata.model.DepictSearchItem
|
||||
import fr.free.nrw.commons.wikidata.model.*
|
||||
import java.util.*
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
import fr.free.nrw.commons.wikidata.model.SnakPartial
|
||||
import fr.free.nrw.commons.wikidata.model.StatementPartial
|
||||
import fr.free.nrw.commons.wikidata.model.WikiBaseEntityValue
|
||||
import java.util.Date
|
||||
|
||||
fun depictedItem(
|
||||
name: String = "label",
|
||||
|
|
@ -18,7 +22,7 @@ fun depictedItem(
|
|||
instanceOfs: List<String> = listOf(),
|
||||
commonsCategories: List<CategoryItem> = listOf(),
|
||||
isSelected: Boolean = false,
|
||||
id: String = "entityId"
|
||||
id: String = "entityId",
|
||||
) = DepictedItem(
|
||||
name = name,
|
||||
description = description,
|
||||
|
|
@ -26,12 +30,15 @@ fun depictedItem(
|
|||
instanceOfs = instanceOfs,
|
||||
commonsCategories = commonsCategories,
|
||||
isSelected = isSelected,
|
||||
id = id
|
||||
id = id,
|
||||
)
|
||||
|
||||
fun categoryItem(name: String = "name", description: String = "desc",
|
||||
thumbUrl: String = "thumbUrl", selected: Boolean = false) =
|
||||
CategoryItem(name, description, thumbUrl, selected)
|
||||
fun categoryItem(
|
||||
name: String = "name",
|
||||
description: String = "desc",
|
||||
thumbUrl: String = "thumbUrl",
|
||||
selected: Boolean = false,
|
||||
) = CategoryItem(name, description, thumbUrl, selected)
|
||||
|
||||
fun media(
|
||||
thumbUrl: String? = "thumbUrl",
|
||||
|
|
@ -42,13 +49,13 @@ fun media(
|
|||
license: String? = "license",
|
||||
licenseUrl: String? = "licenseUrl",
|
||||
author: String? = "creator",
|
||||
user:String?="user",
|
||||
user: String? = "user",
|
||||
pageId: String = "pageId",
|
||||
categories: List<String>? = listOf("categories"),
|
||||
coordinates: LatLng? = LatLng(0.0, 0.0, 0.0f),
|
||||
captions: Map<String, String> = mapOf("en" to "caption"),
|
||||
descriptions: Map<String, String> = mapOf("en" to "description"),
|
||||
depictionIds: List<String> = listOf("depictionId")
|
||||
depictionIds: List<String> = listOf("depictionId"),
|
||||
) = Media(
|
||||
pageId,
|
||||
thumbUrl,
|
||||
|
|
@ -64,7 +71,7 @@ fun media(
|
|||
coordinates,
|
||||
captions,
|
||||
descriptions,
|
||||
depictionIds
|
||||
depictionIds,
|
||||
)
|
||||
|
||||
fun depictSearchItem(
|
||||
|
|
@ -72,7 +79,7 @@ fun depictSearchItem(
|
|||
pageId: String = "pageid",
|
||||
url: String = "url",
|
||||
label: String = "label",
|
||||
description: String = "description"
|
||||
description: String = "description",
|
||||
) = DepictSearchItem(id, pageId, url, label, description)
|
||||
|
||||
fun place(
|
||||
|
|
@ -85,39 +92,36 @@ fun place(
|
|||
siteLinks: Sitelinks? = null,
|
||||
pic: String = "pic",
|
||||
exists: Boolean = false,
|
||||
entityID: String = "entityID"
|
||||
): Place {
|
||||
return Place(lang, name, label, longDescription, latLng, category, siteLinks, pic, exists, entityID)
|
||||
}
|
||||
entityID: String = "entityID",
|
||||
): Place = Place(lang, name, label, longDescription, latLng, category, siteLinks, pic, exists, entityID)
|
||||
|
||||
fun entityId(wikiBaseEntityValue: WikiBaseEntityValue = wikiBaseEntityValue()) =
|
||||
DataValue.EntityId(wikiBaseEntityValue)
|
||||
fun entityId(wikiBaseEntityValue: WikiBaseEntityValue = wikiBaseEntityValue()) = DataValue.EntityId(wikiBaseEntityValue)
|
||||
|
||||
fun wikiBaseEntityValue(
|
||||
entityType: String = "type",
|
||||
id: String = "id",
|
||||
numericId: Long = 0
|
||||
numericId: Long = 0,
|
||||
) = WikiBaseEntityValue(entityType, id, numericId)
|
||||
|
||||
fun statement(
|
||||
mainSnak: Snak_partial = snak(),
|
||||
mainSnak: SnakPartial = snak(),
|
||||
rank: String = "rank",
|
||||
type: String = "type"
|
||||
) = Statement_partial(mainSnak, type, rank)
|
||||
type: String = "type",
|
||||
) = StatementPartial(mainSnak, type, rank)
|
||||
|
||||
fun snak(
|
||||
snakType: String = "type",
|
||||
property: String = "property",
|
||||
dataValue: DataValue = valueString("")
|
||||
) = Snak_partial(snakType, property, dataValue)
|
||||
dataValue: DataValue = valueString(""),
|
||||
) = SnakPartial(snakType, property, dataValue)
|
||||
|
||||
fun valueString(value: String) = DataValue.ValueString(value)
|
||||
|
||||
fun entity(
|
||||
labels: Map<String, String> = emptyMap(),
|
||||
descriptions: Map<String, String> = emptyMap(),
|
||||
statements: Map<String, List<Statement_partial>>? = emptyMap(),
|
||||
id: String = "id"
|
||||
statements: Map<String, List<StatementPartial>>? = emptyMap(),
|
||||
id: String = "id",
|
||||
) = mock<Entities.Entity>().apply {
|
||||
val mockedLabels = labels.mockLabels()
|
||||
whenever(labels()).thenReturn(mockedLabels)
|
||||
|
|
@ -127,8 +131,7 @@ fun entity(
|
|||
whenever(id()).thenReturn(id)
|
||||
}
|
||||
|
||||
private fun Map<String, String>.mockLabels(): Map<String, Entities.Label> {
|
||||
return mapValues { entry ->
|
||||
private fun Map<String, String>.mockLabels(): Map<String, Entities.Label> =
|
||||
mapValues { entry ->
|
||||
mock<Entities.Label>().also { whenever(it.value()).thenReturn(entry.value) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons
|
|||
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
import fr.free.nrw.commons.nearby.NearbyController.loadAttractionsFromLocationToBaseMarkerOptions
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -12,13 +11,15 @@ import org.robolectric.annotation.Config
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class NearbyControllerTest {
|
||||
|
||||
@Test
|
||||
fun testNullAttractions() {
|
||||
val location = LatLng(0.0, 0.0, 0f)
|
||||
|
||||
val options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, null)
|
||||
val options =
|
||||
loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
null,
|
||||
)
|
||||
|
||||
assertEquals(0, options.size.toLong())
|
||||
}
|
||||
|
|
@ -27,8 +28,11 @@ class NearbyControllerTest {
|
|||
fun testEmptyList() {
|
||||
val location = LatLng(0.0, 0.0, 0f)
|
||||
|
||||
val options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, emptyList())
|
||||
val options =
|
||||
loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location,
|
||||
emptyList(),
|
||||
)
|
||||
|
||||
assertEquals(0, options.size.toLong())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,14 +46,15 @@ class OkHttpJsonApiClientTests {
|
|||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
okHttpJsonApiClient = OkHttpJsonApiClient(
|
||||
okhttpClient,
|
||||
depictsClient,
|
||||
wikiMediaToolforgeUrl,
|
||||
sparqlQueryUrl,
|
||||
campaignsUrl,
|
||||
gson
|
||||
)
|
||||
okHttpJsonApiClient =
|
||||
OkHttpJsonApiClient(
|
||||
okhttpClient,
|
||||
depictsClient,
|
||||
wikiMediaToolforgeUrl,
|
||||
sparqlQueryUrl,
|
||||
campaignsUrl,
|
||||
gson,
|
||||
)
|
||||
Mockito.`when`(okhttpClient.newCall(any())).thenReturn(call)
|
||||
Mockito.`when`(call.execute()).thenReturn(response)
|
||||
}
|
||||
|
|
@ -69,7 +70,6 @@ class OkHttpJsonApiClientTests {
|
|||
}
|
||||
verify(okhttpClient).newCall(any())
|
||||
verify(call).execute()
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -83,6 +83,5 @@ class OkHttpJsonApiClientTests {
|
|||
}
|
||||
verify(okhttpClient).newCall(any())
|
||||
verify(call).execute()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,28 +17,30 @@ import fr.free.nrw.commons.location.LocationServiceManager
|
|||
class TestCommonsApplication : Application() {
|
||||
private var mockApplicationComponent: CommonsApplicationComponent? = null
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
if (mockApplicationComponent == null) {
|
||||
mockApplicationComponent = DaggerCommonsApplicationComponent.builder()
|
||||
mockApplicationComponent =
|
||||
DaggerCommonsApplicationComponent
|
||||
.builder()
|
||||
.appModule(MockCommonsApplicationModule(this))
|
||||
.build()
|
||||
}
|
||||
super.onCreate()
|
||||
setTheme(R.style.Theme_AppCompat)
|
||||
context=applicationContext
|
||||
context = applicationContext
|
||||
}
|
||||
|
||||
companion object{
|
||||
private var context: Context?=null
|
||||
fun getContext(): Context? {
|
||||
return context
|
||||
}
|
||||
companion object {
|
||||
private var context: Context? = null
|
||||
|
||||
fun getContext(): Context? = context
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class MockCommonsApplicationModule(appContext: Context) : CommonsApplicationModule(appContext) {
|
||||
class MockCommonsApplicationModule(
|
||||
appContext: Context,
|
||||
) : CommonsApplicationModule(appContext) {
|
||||
val accountUtil: AccountUtil = mock()
|
||||
val defaultSharedPreferences: JsonKvStore = mock()
|
||||
val locationServiceManager: LocationServiceManager = mock()
|
||||
|
|
@ -58,7 +60,10 @@ class MockCommonsApplicationModule(appContext: Context) : CommonsApplicationModu
|
|||
|
||||
override fun providesAccountUtil(context: Context): AccountUtil = accountUtil
|
||||
|
||||
override fun providesDefaultKvStore(context: Context, gson: Gson): JsonKvStore = defaultSharedPreferences
|
||||
override fun providesDefaultKvStore(
|
||||
context: Context,
|
||||
gson: Gson,
|
||||
): JsonKvStore = defaultSharedPreferences
|
||||
|
||||
override fun provideLocationServiceManager(context: Context): LocationServiceManager = locationServiceManager
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory.HttpStatusException
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory.HttpStatusException
|
||||
import java.io.IOException
|
||||
|
||||
fun createTestClient(): OkHttpClient = OkHttpClient.Builder()
|
||||
.addInterceptor(UnsuccessfulResponseInterceptor())
|
||||
.addInterceptor(TestStubInterceptor())
|
||||
.build()
|
||||
fun createTestClient(): OkHttpClient =
|
||||
OkHttpClient
|
||||
.Builder()
|
||||
.addInterceptor(UnsuccessfulResponseInterceptor())
|
||||
.addInterceptor(TestStubInterceptor())
|
||||
.build()
|
||||
|
||||
private class TestStubInterceptor : Interceptor {
|
||||
interface Callback {
|
||||
|
|
@ -18,14 +20,15 @@ private class TestStubInterceptor : Interceptor {
|
|||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
return if (CALLBACK != null) {
|
||||
CALLBACK!!.getResponse(chain)
|
||||
} else chain.proceed(chain.request())
|
||||
}
|
||||
override fun intercept(chain: Interceptor.Chain): Response =
|
||||
if (callback != null) {
|
||||
callback!!.getResponse(chain)
|
||||
} else {
|
||||
chain.proceed(chain.request())
|
||||
}
|
||||
|
||||
companion object {
|
||||
var CALLBACK: Callback? = null
|
||||
var callback: Callback? = null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ import java.lang.reflect.Modifier
|
|||
|
||||
object TestUtility {
|
||||
@Throws(java.lang.Exception::class)
|
||||
fun setFinalStatic(field: Field, newValue: Any?) {
|
||||
fun setFinalStatic(
|
||||
field: Field,
|
||||
newValue: Any?,
|
||||
) {
|
||||
try {
|
||||
field.isAccessible = true
|
||||
// remove final modifier from field
|
||||
|
|
@ -21,4 +24,4 @@ object TestUtility {
|
|||
e.stackTrace
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package fr.free.nrw.commons
|
|||
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import java.util.*
|
||||
import java.util.Calendar
|
||||
|
||||
class UtilsTest {
|
||||
@Test
|
||||
|
|
@ -25,4 +25,4 @@ class UtilsTest {
|
|||
cal.set(2022, Calendar.DECEMBER, 1)
|
||||
Assertions.assertEquals(2022, Utils.getWikiLovesMonumentsYear(cal))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import org.robolectric.shadows.ShadowIntent
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class WelcomeActivityUnitTest {
|
||||
|
||||
private lateinit var activity: WelcomeActivity
|
||||
private lateinit var finishTutorialButton: TextView
|
||||
|
||||
|
|
@ -32,8 +31,10 @@ class WelcomeActivityUnitTest {
|
|||
@Before
|
||||
fun setUp() {
|
||||
val intent = Intent().putExtra("isQuiz", true)
|
||||
activity = Robolectric.buildActivity(WelcomeActivity::class.java, intent)
|
||||
.get()
|
||||
activity =
|
||||
Robolectric
|
||||
.buildActivity(WelcomeActivity::class.java, intent)
|
||||
.get()
|
||||
activity.onCreate(null)
|
||||
finishTutorialButton = activity.findViewById(R.id.finishTutorialButton)
|
||||
}
|
||||
|
|
@ -77,5 +78,4 @@ class WelcomeActivityUnitTest {
|
|||
fun testOnBackPressed() {
|
||||
activity.onBackPressed()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package fr.free.nrw.commons.actions
|
|||
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import fr.free.nrw.commons.wikidata.model.edit.Edit
|
||||
import io.reactivex.Observable
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
|
@ -9,12 +11,11 @@ import org.mockito.ArgumentMatchers
|
|||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import fr.free.nrw.commons.wikidata.model.edit.Edit
|
||||
|
||||
class PageEditClientTest {
|
||||
@Mock
|
||||
private lateinit var csrfTokenClient: CsrfTokenClient
|
||||
|
||||
@Mock
|
||||
private lateinit var pageEditInterface: PageEditInterface
|
||||
|
||||
|
|
@ -52,16 +53,17 @@ class PageEditClientTest {
|
|||
@Test
|
||||
fun testAppendEdit() {
|
||||
Mockito.`when`(csrfTokenClient.getTokenBlocking()).thenReturn("test")
|
||||
Mockito.`when`(
|
||||
pageEditInterface.postAppendEdit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString()
|
||||
Mockito
|
||||
.`when`(
|
||||
pageEditInterface.postAppendEdit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
),
|
||||
).thenReturn(
|
||||
Observable.just(edit),
|
||||
)
|
||||
).thenReturn(
|
||||
Observable.just(edit)
|
||||
)
|
||||
Mockito.`when`(edit.edit()).thenReturn(editResult)
|
||||
Mockito.`when`(editResult.editSucceeded()).thenReturn(true)
|
||||
pageEditClient.appendEdit("test", "test", "test").test()
|
||||
|
|
@ -88,7 +90,12 @@ class PageEditClientTest {
|
|||
fun testSetCaptions() {
|
||||
Mockito.`when`(csrfTokenClient.getTokenBlocking()).thenReturn("test")
|
||||
pageEditClient.setCaptions("test", "test", "en", "test")
|
||||
verify(pageEditInterface).postCaptions(eq("test"), eq("test"), eq("en"),
|
||||
eq("test"), eq("test"))
|
||||
verify(pageEditInterface).postCaptions(
|
||||
eq("test"),
|
||||
eq("test"),
|
||||
eq("en"),
|
||||
eq("test"),
|
||||
eq("test"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons.actions
|
|||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -14,13 +15,13 @@ import org.mockito.Mockito.`when`
|
|||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@PrepareForTest(CommonsApplication::class)
|
||||
class ThanksClientTest {
|
||||
@Mock
|
||||
private lateinit var csrfTokenClient: CsrfTokenClient
|
||||
|
||||
@Mock
|
||||
private lateinit var service: ThanksInterface
|
||||
|
||||
|
|
@ -52,4 +53,4 @@ class ThanksClientTest {
|
|||
thanksClient.thank(1L)
|
||||
verify(service).thank(ArgumentMatchers.anyString(), ArgumentMatchers.any(), eq("test"), eq("test"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import org.robolectric.annotation.Config
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class AccountUtilUnitTest {
|
||||
|
||||
private lateinit var context: FakeContextWrapper
|
||||
private lateinit var accountUtil: AccountUtil
|
||||
|
||||
|
|
@ -58,4 +57,4 @@ class AccountUtilUnitTest {
|
|||
FakeContextWrapperWithException(ApplicationProvider.getApplicationContext())
|
||||
Assert.assertEquals(AccountUtil.account(context), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.auth.login.LoginResult
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
|
|
@ -30,11 +30,9 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.fakes.RoboMenuItem
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class LoginActivityUnitTests {
|
||||
|
||||
private lateinit var menuItem: MenuItem
|
||||
private lateinit var context: Context
|
||||
|
||||
|
|
@ -92,12 +90,13 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnEditorActionCaseDefault() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onEditorAction",
|
||||
TextView::class.java,
|
||||
Int::class.java,
|
||||
KeyEvent::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onEditorAction",
|
||||
TextView::class.java,
|
||||
Int::class.java,
|
||||
KeyEvent::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, textView, 0, keyEvent)
|
||||
}
|
||||
|
|
@ -105,9 +104,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSkipLogin() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"skipLogin"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"skipLogin",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -115,9 +115,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testForgotPassword() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"forgotPassword"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"forgotPassword",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -125,9 +126,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPrivacyPolicyClicked() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onPrivacyPolicyClicked"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onPrivacyPolicyClicked",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -135,9 +137,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSignUp() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"signUp"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"signUp",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -145,10 +148,11 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPostCreate() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onPostCreate",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onPostCreate",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
|
@ -157,9 +161,10 @@ class LoginActivityUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testOnDestroy() {
|
||||
`when`(progressDialog.isShowing).thenReturn(true)
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -168,9 +173,10 @@ class LoginActivityUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testOnDestroyWithException() {
|
||||
`when`(progressDialog.isShowing).thenThrow(NullPointerException())
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -178,10 +184,11 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnLoginSuccessCaseDefault() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onLoginSuccess",
|
||||
LoginResult::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onLoginSuccess",
|
||||
LoginResult::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, loginResult)
|
||||
}
|
||||
|
|
@ -190,10 +197,11 @@ class LoginActivityUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testOnLoginSuccess() {
|
||||
`when`(progressDialog.isShowing).thenReturn(true)
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onLoginSuccess",
|
||||
LoginResult::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onLoginSuccess",
|
||||
LoginResult::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, loginResult)
|
||||
}
|
||||
|
|
@ -201,9 +209,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowPasswordResetPrompt() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"showPasswordResetPrompt"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"showPasswordResetPrompt",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -211,9 +220,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHideProgress() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"hideProgress"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"hideProgress",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -225,9 +235,10 @@ class LoginActivityUnitTests {
|
|||
`when`(applicationKvStore.getBoolean("login_skipped", false)).thenReturn(true)
|
||||
`when`(sessionManager.currentAccount).thenReturn(account)
|
||||
`when`(sessionManager.isUserLoggedIn).thenReturn(true)
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onResume"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onResume",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -235,9 +246,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnStart() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onStart"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onStart",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -245,9 +257,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnStop() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onStop"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onStop",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -255,9 +268,10 @@ class LoginActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPostResume() {
|
||||
val method: Method = LoginActivity::class.java.getDeclaredMethod(
|
||||
"onPostResume"
|
||||
)
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"onPostResume",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,10 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.annotation.LooperMode
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class SessionManagerUnitTests {
|
||||
|
||||
private lateinit var sessionManager: SessionManager
|
||||
private lateinit var accountManager: AccountManager
|
||||
|
||||
|
|
@ -59,9 +57,10 @@ class SessionManagerUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testRemoveAccountCaseNull() {
|
||||
val method: Method = SessionManager::class.java.getDeclaredMethod(
|
||||
"removeAccount"
|
||||
)
|
||||
val method: Method =
|
||||
SessionManager::class.java.getDeclaredMethod(
|
||||
"removeAccount",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(sessionManager)
|
||||
}
|
||||
|
|
@ -71,10 +70,11 @@ class SessionManagerUnitTests {
|
|||
fun testUpdateAccount() {
|
||||
`when`(loginResult.userName).thenReturn("username")
|
||||
`when`(loginResult.password).thenReturn("password")
|
||||
val method: Method = SessionManager::class.java.getDeclaredMethod(
|
||||
"updateAccount",
|
||||
LoginResult::class.java
|
||||
)
|
||||
val method: Method =
|
||||
SessionManager::class.java.getDeclaredMethod(
|
||||
"updateAccount",
|
||||
LoginResult::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(sessionManager, loginResult)
|
||||
}
|
||||
|
|
@ -118,11 +118,12 @@ class SessionManagerUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testCreateAccount() {
|
||||
val method: Method = SessionManager::class.java.getDeclaredMethod(
|
||||
"createAccount",
|
||||
String::class.java,
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
SessionManager::class.java.getDeclaredMethod(
|
||||
"createAccount",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
Assert.assertEquals(method.invoke(sessionManager, "username", "password"), true)
|
||||
}
|
||||
|
|
@ -130,10 +131,11 @@ class SessionManagerUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetUserLoggedIn() {
|
||||
val method: Method = SessionManager::class.java.getDeclaredMethod(
|
||||
"setUserLoggedIn",
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
SessionManager::class.java.getDeclaredMethod(
|
||||
"setUserLoggedIn",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(sessionManager, true)
|
||||
}
|
||||
|
|
@ -141,9 +143,10 @@ class SessionManagerUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetUserName() {
|
||||
val method: Method = SessionManager::class.java.getDeclaredMethod(
|
||||
"getUserName"
|
||||
)
|
||||
val method: Method =
|
||||
SessionManager::class.java.getDeclaredMethod(
|
||||
"getUserName",
|
||||
)
|
||||
method.isAccessible = true
|
||||
Assert.assertEquals(method.invoke(sessionManager), null)
|
||||
}
|
||||
|
|
@ -151,11 +154,11 @@ class SessionManagerUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetPassword() {
|
||||
val method: Method = SessionManager::class.java.getDeclaredMethod(
|
||||
"getPassword"
|
||||
)
|
||||
val method: Method =
|
||||
SessionManager::class.java.getDeclaredMethod(
|
||||
"getPassword",
|
||||
)
|
||||
method.isAccessible = true
|
||||
Assert.assertEquals(method.invoke(sessionManager), null)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,9 @@ import org.robolectric.Robolectric
|
|||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class SignupActivityTest {
|
||||
|
||||
private lateinit var activity: SignupActivity
|
||||
|
||||
@Mock
|
||||
|
|
@ -49,4 +47,4 @@ class SignupActivityTest {
|
|||
`when`(webView.canGoBack()).thenReturn(true)
|
||||
activity.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.mockito.MockitoAnnotations
|
|||
import java.lang.reflect.Field
|
||||
|
||||
class WikiAccountAuthenticatorServiceUnitTest {
|
||||
|
||||
private lateinit var service: WikiAccountAuthenticatorService
|
||||
|
||||
@Before
|
||||
|
|
@ -30,5 +29,4 @@ class WikiAccountAuthenticatorServiceUnitTest {
|
|||
field.set(service, null)
|
||||
Assert.assertEquals(service.onBind(null), null)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import org.robolectric.annotation.LooperMode
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class WikiAccountAuthenticatorUnitTest {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var authenticator: WikiAccountAuthenticator
|
||||
|
||||
|
|
@ -64,7 +63,7 @@ class WikiAccountAuthenticatorUnitTest {
|
|||
val intent: Intent? = bundle.getParcelable(AccountManager.KEY_INTENT)
|
||||
Assert.assertEquals(
|
||||
intent?.extras!![AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE],
|
||||
response
|
||||
response,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +88,7 @@ class WikiAccountAuthenticatorUnitTest {
|
|||
fun testGetAuthTokenLabelCaseNonNull() {
|
||||
Assert.assertEquals(
|
||||
authenticator.getAuthTokenLabel(BuildConfig.ACCOUNT_TYPE),
|
||||
AccountUtil.AUTH_TOKEN_TYPE
|
||||
AccountUtil.AUTH_TOKEN_TYPE,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -110,5 +109,4 @@ class WikiAccountAuthenticatorUnitTest {
|
|||
val bundle: Bundle? = authenticator.getAccountRemovalAllowed(response, account)
|
||||
Assert.assertEquals(bundle?.getBoolean(AccountManager.KEY_BOOLEAN_RESULT), true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package fr.free.nrw.commons.auth.csrf
|
|||
|
||||
import com.google.gson.stream.MalformedJsonException
|
||||
import fr.free.nrw.commons.MockWebServerTest
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory.HttpStatusException
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.auth.login.LoginClient
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwException
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
|
|
@ -11,8 +13,6 @@ import org.mockito.ArgumentMatchers.isA
|
|||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.verify
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwException
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory.HttpStatusException
|
||||
|
||||
class CsrfTokenClientTest : MockWebServerTest() {
|
||||
private val cb = mock(CsrfTokenClient.Callback::class.java)
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@ import android.net.Uri
|
|||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.stream.MalformedJsonException
|
||||
import fr.free.nrw.commons.MockWebServerTest
|
||||
import io.reactivex.observers.TestObserver
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import fr.free.nrw.commons.wikidata.model.WikiSite
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import fr.free.nrw.commons.wikidata.json.NamespaceTypeAdapter
|
||||
import fr.free.nrw.commons.wikidata.json.PostProcessingTypeAdapter
|
||||
import fr.free.nrw.commons.wikidata.json.UriTypeAdapter
|
||||
import fr.free.nrw.commons.wikidata.json.WikiSiteTypeAdapter
|
||||
import fr.free.nrw.commons.wikidata.model.WikiSite
|
||||
import fr.free.nrw.commons.wikidata.model.page.Namespace
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import io.reactivex.observers.TestObserver
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
|
@ -21,29 +21,36 @@ import retrofit2.converter.gson.GsonConverterFactory
|
|||
class UserExtendedInfoClientTest : MockWebServerTest() {
|
||||
private var apiService: LoginInterface? = null
|
||||
private val observer = TestObserver<MwQueryResponse>()
|
||||
private val gson = GsonBuilder()
|
||||
.registerTypeHierarchyAdapter(Uri::class.java, UriTypeAdapter()
|
||||
.nullSafe())
|
||||
.registerTypeHierarchyAdapter(
|
||||
Namespace::class.java, NamespaceTypeAdapter()
|
||||
.nullSafe())
|
||||
.registerTypeAdapter(
|
||||
WikiSite::class.java, WikiSiteTypeAdapter()
|
||||
.nullSafe())
|
||||
.registerTypeAdapterFactory(PostProcessingTypeAdapter())
|
||||
.create()
|
||||
private val gson =
|
||||
GsonBuilder()
|
||||
.registerTypeHierarchyAdapter(
|
||||
Uri::class.java,
|
||||
UriTypeAdapter()
|
||||
.nullSafe(),
|
||||
).registerTypeHierarchyAdapter(
|
||||
Namespace::class.java,
|
||||
NamespaceTypeAdapter()
|
||||
.nullSafe(),
|
||||
).registerTypeAdapter(
|
||||
WikiSite::class.java,
|
||||
WikiSiteTypeAdapter()
|
||||
.nullSafe(),
|
||||
).registerTypeAdapterFactory(PostProcessingTypeAdapter())
|
||||
.create()
|
||||
|
||||
@Before
|
||||
@Throws(Throwable::class)
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
apiService = Retrofit.Builder()
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl(server().url)
|
||||
.build()
|
||||
.create(LoginInterface::class.java)
|
||||
apiService =
|
||||
Retrofit
|
||||
.Builder()
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl(server().url)
|
||||
.build()
|
||||
.create(LoginInterface::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -57,9 +64,14 @@ class UserExtendedInfoClientTest : MockWebServerTest() {
|
|||
.assertComplete()
|
||||
.assertNoErrors()
|
||||
.assertValue { result: MwQueryResponse ->
|
||||
result.query()!!
|
||||
.userInfo()!!.id() == 24531888 && result.query()!!.getUserResponse("USER")!!
|
||||
.name() == "USER"
|
||||
result
|
||||
.query()!!
|
||||
.userInfo()!!
|
||||
.id() == 24531888 &&
|
||||
result
|
||||
.query()!!
|
||||
.getUserResponse("USER")!!
|
||||
.name() == "USER"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ import fr.free.nrw.commons.Media
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksBinding
|
||||
import fr.free.nrw.commons.databinding.FragmentFeaturedRootBinding
|
||||
import fr.free.nrw.commons.explore.ParentViewPager
|
||||
|
|
@ -44,7 +44,6 @@ import java.lang.reflect.Field
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class BookmarkListRootFragmentUnitTest {
|
||||
|
||||
private lateinit var fragment: BookmarkListRootFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
|
|
@ -328,5 +327,4 @@ class BookmarkListRootFragmentUnitTest {
|
|||
field.set(fragment, null)
|
||||
Assert.assertEquals(fragment.backPressed(), false)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@ class BookmarksPagerAdapterTests {
|
|||
fun testGetPageTitle() {
|
||||
bookmarksPagerAdapter.getPageTitle(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,4 @@ class LoggedOutBookmarksPagerAdapterTests {
|
|||
fun testGetPageTitle() {
|
||||
bookmarksPagerAdapter.getPageTitle(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import java.util.ArrayList
|
|||
class BookmarkItemsControllerTest {
|
||||
@Mock
|
||||
var bookmarkDao: BookmarkItemsDao? = null
|
||||
|
||||
@InjectMocks
|
||||
lateinit var bookmarkItemsController: BookmarkItemsController
|
||||
|
||||
|
|
@ -33,9 +34,21 @@ class BookmarkItemsControllerTest {
|
|||
val list = ArrayList<DepictedItem>()
|
||||
list.add(
|
||||
DepictedItem(
|
||||
"name", "description", "image url", listOf("instance"),
|
||||
listOf(CategoryItem("category name", "category description",
|
||||
"category thumbnail", false)), true, "id")
|
||||
"name",
|
||||
"description",
|
||||
"image url",
|
||||
listOf("instance"),
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"category name",
|
||||
"category description",
|
||||
"category thumbnail",
|
||||
false,
|
||||
),
|
||||
),
|
||||
true,
|
||||
"id",
|
||||
),
|
||||
)
|
||||
return list
|
||||
}
|
||||
|
|
@ -49,4 +62,4 @@ class BookmarkItemsControllerTest {
|
|||
bookmarkItemsController.loadFavoritesItems()
|
||||
Assert.assertEquals(1, bookmarkedItems.size.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,31 @@ import android.database.MatrixCursor
|
|||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.net.Uri
|
||||
import android.os.RemoteException
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.anyOrNull
|
||||
import com.nhaarman.mockitokotlin2.argumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.inOrder
|
||||
import com.nhaarman.mockitokotlin2.isA
|
||||
import com.nhaarman.mockitokotlin2.isNull
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.*
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_CATEGORIES_DESCRIPTION_LIST
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_CATEGORIES_NAME_LIST
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_CATEGORIES_THUMBNAIL_LIST
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_DESCRIPTION
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_ID
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_IMAGE
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_INSTANCE_LIST
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_IS_SELECTED
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.COLUMN_NAME
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.CREATE_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.DROP_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.onCreate
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.onDelete
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table.onUpdate
|
||||
import fr.free.nrw.commons.category.CategoryItem
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
import org.junit.Assert
|
||||
|
|
@ -23,17 +45,18 @@ import org.robolectric.annotation.Config
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class BookmarkItemsDaoTest {
|
||||
private val columns = arrayOf(
|
||||
COLUMN_NAME,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_IMAGE,
|
||||
COLUMN_INSTANCE_LIST,
|
||||
COLUMN_CATEGORIES_NAME_LIST,
|
||||
COLUMN_CATEGORIES_DESCRIPTION_LIST,
|
||||
COLUMN_CATEGORIES_THUMBNAIL_LIST,
|
||||
COLUMN_IS_SELECTED,
|
||||
COLUMN_ID,
|
||||
)
|
||||
private val columns =
|
||||
arrayOf(
|
||||
COLUMN_NAME,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_IMAGE,
|
||||
COLUMN_INSTANCE_LIST,
|
||||
COLUMN_CATEGORIES_NAME_LIST,
|
||||
COLUMN_CATEGORIES_DESCRIPTION_LIST,
|
||||
COLUMN_CATEGORIES_THUMBNAIL_LIST,
|
||||
COLUMN_IS_SELECTED,
|
||||
COLUMN_ID,
|
||||
)
|
||||
private val client: ContentProviderClient = mock()
|
||||
private val database: SQLiteDatabase = mock()
|
||||
private val captor = argumentCaptor<ContentValues>()
|
||||
|
|
@ -46,12 +69,23 @@ class BookmarkItemsDaoTest {
|
|||
*/
|
||||
@Before
|
||||
fun setUp() {
|
||||
exampleItemBookmark = DepictedItem("itemName", "itemDescription",
|
||||
"itemImageUrl", listOf("instance"), listOf(
|
||||
CategoryItem("category name", "category description",
|
||||
"category thumbnail", false)
|
||||
), false,
|
||||
"itemID")
|
||||
exampleItemBookmark =
|
||||
DepictedItem(
|
||||
"itemName",
|
||||
"itemDescription",
|
||||
"itemImageUrl",
|
||||
listOf("instance"),
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"category name",
|
||||
"category description",
|
||||
"category thumbnail",
|
||||
false,
|
||||
),
|
||||
),
|
||||
false,
|
||||
"itemID",
|
||||
)
|
||||
testObject = BookmarkItemsDao { client }
|
||||
}
|
||||
|
||||
|
|
@ -79,9 +113,17 @@ class BookmarkItemsDaoTest {
|
|||
Assert.assertEquals("itemDescription", it.description)
|
||||
Assert.assertEquals("itemImageUrl", it.imageUrl)
|
||||
Assert.assertEquals(listOf("instance"), it.instanceOfs)
|
||||
Assert.assertEquals(listOf(CategoryItem("category name",
|
||||
"category description",
|
||||
"category thumbnail", false)), it.commonsCategories)
|
||||
Assert.assertEquals(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"category name",
|
||||
"category description",
|
||||
"category thumbnail",
|
||||
false,
|
||||
),
|
||||
),
|
||||
it.commonsCategories,
|
||||
)
|
||||
Assert.assertEquals(false, it.isSelected)
|
||||
Assert.assertEquals("itemID", it.id)
|
||||
}
|
||||
|
|
@ -96,13 +138,12 @@ class BookmarkItemsDaoTest {
|
|||
val result = testObject.allBookmarksItems
|
||||
|
||||
Assert.assertEquals(14, (result.size))
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException::class)
|
||||
fun getAllItemsBookmarksTranslatesExceptions() {
|
||||
whenever(client.query(any(), any(), anyOrNull(), any(), anyOrNull())).thenThrow(
|
||||
RemoteException("")
|
||||
RemoteException(""),
|
||||
)
|
||||
testObject.allBookmarksItems
|
||||
}
|
||||
|
|
@ -131,7 +172,6 @@ class BookmarkItemsDaoTest {
|
|||
verify(mockCursor).close()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun updateNewItemBookmark() {
|
||||
whenever(client.insert(any(), any())).thenReturn(Uri.EMPTY)
|
||||
|
|
@ -143,39 +183,39 @@ class BookmarkItemsDaoTest {
|
|||
Assert.assertEquals(9, cv.size())
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.name,
|
||||
cv.getAsString(COLUMN_NAME)
|
||||
cv.getAsString(COLUMN_NAME),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.description,
|
||||
cv.getAsString(COLUMN_DESCRIPTION)
|
||||
cv.getAsString(COLUMN_DESCRIPTION),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.imageUrl,
|
||||
cv.getAsString(COLUMN_IMAGE)
|
||||
cv.getAsString(COLUMN_IMAGE),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.instanceOfs[0],
|
||||
cv.getAsString(COLUMN_INSTANCE_LIST)
|
||||
cv.getAsString(COLUMN_INSTANCE_LIST),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.commonsCategories[0].name,
|
||||
cv.getAsString(COLUMN_CATEGORIES_NAME_LIST)
|
||||
cv.getAsString(COLUMN_CATEGORIES_NAME_LIST),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.commonsCategories[0].description,
|
||||
cv.getAsString(COLUMN_CATEGORIES_DESCRIPTION_LIST)
|
||||
cv.getAsString(COLUMN_CATEGORIES_DESCRIPTION_LIST),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.commonsCategories[0].thumbnail,
|
||||
cv.getAsString(COLUMN_CATEGORIES_THUMBNAIL_LIST)
|
||||
cv.getAsString(COLUMN_CATEGORIES_THUMBNAIL_LIST),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.isSelected,
|
||||
cv.getAsBoolean(COLUMN_IS_SELECTED)
|
||||
cv.getAsBoolean(COLUMN_IS_SELECTED),
|
||||
)
|
||||
Assert.assertEquals(
|
||||
exampleItemBookmark.id,
|
||||
cv.getAsString(COLUMN_ID)
|
||||
cv.getAsString(COLUMN_ID),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -186,8 +226,11 @@ class BookmarkItemsDaoTest {
|
|||
whenever(client.query(any(), any(), any(), any(), anyOrNull())).thenReturn(createCursor(1))
|
||||
|
||||
Assert.assertFalse(testObject.updateBookmarkItem(exampleItemBookmark))
|
||||
verify(client).delete(eq(BookmarkItemsContentProvider.uriForName(exampleItemBookmark.id)),
|
||||
isNull(), isNull())
|
||||
verify(client).delete(
|
||||
eq(BookmarkItemsContentProvider.uriForName(exampleItemBookmark.id)),
|
||||
isNull(),
|
||||
isNull(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -199,7 +242,7 @@ class BookmarkItemsDaoTest {
|
|||
@Test(expected = RuntimeException::class)
|
||||
fun findItemBookmarkTranslatesExceptions() {
|
||||
whenever(client.query(any(), any(), anyOrNull(), any(), anyOrNull())).thenThrow(
|
||||
RemoteException("")
|
||||
RemoteException(""),
|
||||
)
|
||||
testObject.findBookmarkItem(exampleItemBookmark.id)
|
||||
}
|
||||
|
|
@ -351,12 +394,22 @@ class BookmarkItemsDaoTest {
|
|||
verifyNoInteractions(database)
|
||||
}
|
||||
|
||||
private fun createCursor(rowCount: Int) = MatrixCursor(columns, rowCount).apply {
|
||||
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("itemName", "itemDescription",
|
||||
"itemImageUrl", "instance", "category name", "category description",
|
||||
"category thumbnail", false, "itemID"))
|
||||
private fun createCursor(rowCount: Int) =
|
||||
MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(
|
||||
listOf(
|
||||
"itemName",
|
||||
"itemDescription",
|
||||
"itemImageUrl",
|
||||
"instance",
|
||||
"category name",
|
||||
"category description",
|
||||
"category thumbnail",
|
||||
false,
|
||||
"itemID",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
|
|
@ -15,8 +14,8 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.category.CategoryItem
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksItemsBinding
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
|
|
@ -32,13 +31,11 @@ import org.robolectric.RobolectricTestRunner
|
|||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class BookmarkItemsFragmentUnitTest {
|
||||
|
||||
private lateinit var fragment: BookmarkItemsFragment
|
||||
private lateinit var context: Context
|
||||
private lateinit var view: View
|
||||
|
|
@ -63,11 +60,21 @@ class BookmarkItemsFragmentUnitTest {
|
|||
val list = ArrayList<DepictedItem>()
|
||||
list.add(
|
||||
DepictedItem(
|
||||
"name", "description", "image url", listOf("instance"),
|
||||
"name",
|
||||
"description",
|
||||
"image url",
|
||||
listOf("instance"),
|
||||
listOf(
|
||||
CategoryItem("category name", "category description",
|
||||
"category thumbnail", false)
|
||||
), true, "id")
|
||||
CategoryItem(
|
||||
"category name",
|
||||
"category description",
|
||||
"category thumbnail",
|
||||
false,
|
||||
),
|
||||
),
|
||||
true,
|
||||
"id",
|
||||
),
|
||||
)
|
||||
return list
|
||||
}
|
||||
|
|
@ -88,8 +95,9 @@ class BookmarkItemsFragmentUnitTest {
|
|||
fragmentTransaction.commit()
|
||||
|
||||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = layoutInflater
|
||||
.inflate(R.layout.fragment_bookmarks_items, null) as View
|
||||
view =
|
||||
layoutInflater
|
||||
.inflate(R.layout.fragment_bookmarks_items, null) as View
|
||||
binding = FragmentBookmarksItemsBinding.inflate(layoutInflater)
|
||||
|
||||
statusTextView = view.findViewById(R.id.status_message)
|
||||
|
|
@ -99,14 +107,13 @@ class BookmarkItemsFragmentUnitTest {
|
|||
fragment.controller = controller
|
||||
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test init items when non empty
|
||||
*/
|
||||
@Test
|
||||
fun testInitNonEmpty(){
|
||||
fun testInitNonEmpty() {
|
||||
whenever(controller.loadFavoritesItems()).thenReturn(mockBookmarkList)
|
||||
val method: Method =
|
||||
BookmarkItemsFragment::class.java.getDeclaredMethod("initList", Context::class.java)
|
||||
|
|
@ -120,8 +127,7 @@ class BookmarkItemsFragmentUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreateView() {
|
||||
|
||||
fragment.onCreateView(layoutInflater,null,savedInstanceState)
|
||||
fragment.onCreateView(layoutInflater, null, savedInstanceState)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,15 +7,44 @@ import android.database.MatrixCursor
|
|||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.net.Uri
|
||||
import android.os.RemoteException
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.anyOrNull
|
||||
import com.nhaarman.mockitokotlin2.argumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.inOrder
|
||||
import com.nhaarman.mockitokotlin2.isA
|
||||
import com.nhaarman.mockitokotlin2.isNull
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsContentProvider.BASE_URI
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.*
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_CATEGORY
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_COMMONS_LINK
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_DESCRIPTION
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_EXISTS
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_IMAGE_URL
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_LABEL_ICON
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_LABEL_TEXT
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_LANGUAGE
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_LAT
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_LONG
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_NAME
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_PIC
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_WIKIDATA_LINK
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.COLUMN_WIKIPEDIA_LINK
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.CREATE_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.DROP_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.onCreate
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.onDelete
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.onUpdate
|
||||
import fr.free.nrw.commons.location.LatLng
|
||||
import fr.free.nrw.commons.nearby.Label
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.nearby.Sitelinks
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -26,20 +55,23 @@ import org.robolectric.annotation.Config
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class BookMarkLocationDaoTest {
|
||||
private val columns = arrayOf(COLUMN_NAME,
|
||||
COLUMN_LANGUAGE,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_CATEGORY,
|
||||
COLUMN_LABEL_TEXT,
|
||||
COLUMN_LABEL_ICON,
|
||||
COLUMN_IMAGE_URL,
|
||||
COLUMN_WIKIPEDIA_LINK,
|
||||
COLUMN_WIKIDATA_LINK,
|
||||
COLUMN_COMMONS_LINK,
|
||||
COLUMN_LAT,
|
||||
COLUMN_LONG,
|
||||
COLUMN_PIC,
|
||||
COLUMN_EXISTS)
|
||||
private val columns =
|
||||
arrayOf(
|
||||
COLUMN_NAME,
|
||||
COLUMN_LANGUAGE,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_CATEGORY,
|
||||
COLUMN_LABEL_TEXT,
|
||||
COLUMN_LABEL_ICON,
|
||||
COLUMN_IMAGE_URL,
|
||||
COLUMN_WIKIPEDIA_LINK,
|
||||
COLUMN_WIKIDATA_LINK,
|
||||
COLUMN_COMMONS_LINK,
|
||||
COLUMN_LAT,
|
||||
COLUMN_LONG,
|
||||
COLUMN_PIC,
|
||||
COLUMN_EXISTS,
|
||||
)
|
||||
private val client: ContentProviderClient = mock()
|
||||
private val database: SQLiteDatabase = mock()
|
||||
private val captor = argumentCaptor<ContentValues>()
|
||||
|
|
@ -55,16 +87,25 @@ class BookMarkLocationDaoTest {
|
|||
fun setUp() {
|
||||
exampleLabel = Label.FOREST
|
||||
exampleUri = Uri.parse("wikimedia/uri")
|
||||
exampleLocation = LatLng(40.0,51.4, 1f)
|
||||
exampleLocation = LatLng(40.0, 51.4, 1f)
|
||||
|
||||
builder = Sitelinks.Builder()
|
||||
builder.setWikipediaLink("wikipediaLink")
|
||||
builder.setWikidataLink("wikidataLink")
|
||||
builder.setCommonsLink("commonsLink")
|
||||
|
||||
|
||||
examplePlaceBookmark = Place("en", "placeName", exampleLabel, "placeDescription"
|
||||
, exampleLocation, "placeCategory", builder.build(),"picName",false)
|
||||
examplePlaceBookmark =
|
||||
Place(
|
||||
"en",
|
||||
"placeName",
|
||||
exampleLabel,
|
||||
"placeDescription",
|
||||
exampleLocation,
|
||||
"placeCategory",
|
||||
builder.build(),
|
||||
"picName",
|
||||
false,
|
||||
)
|
||||
testObject = BookmarkLocationsDao { client }
|
||||
}
|
||||
|
||||
|
|
@ -276,8 +317,8 @@ class BookMarkLocationDaoTest {
|
|||
verify(database).execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_exists STRING;")
|
||||
}
|
||||
|
||||
private fun createCursor(rows: Int): Cursor {
|
||||
return MatrixCursor(columns, rows).apply {
|
||||
private fun createCursor(rows: Int): Cursor =
|
||||
MatrixCursor(columns, rows).apply {
|
||||
repeat(rows) {
|
||||
newRow().apply {
|
||||
add("placeName")
|
||||
|
|
@ -297,5 +338,4 @@ class BookMarkLocationDaoTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,16 @@ import java.util.ArrayList
|
|||
class BookmarkLocationControllerTest {
|
||||
@Mock
|
||||
var bookmarkDao: BookmarkLocationsDao? = null
|
||||
|
||||
@InjectMocks
|
||||
lateinit var bookmarkLocationsController: BookmarkLocationsController
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
whenever(bookmarkDao!!.allBookmarksLocations)
|
||||
.thenReturn(mockBookmarkList)
|
||||
}
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
whenever(bookmarkDao!!.allBookmarksLocations)
|
||||
.thenReturn(mockBookmarkList)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mock bookmark list
|
||||
|
|
@ -32,7 +33,17 @@ class BookmarkLocationControllerTest {
|
|||
val list = ArrayList<Place>()
|
||||
list.add(
|
||||
Place(
|
||||
"en", "a place", null, "a description", null, "a cat", null, null, true, "entityID")
|
||||
"en",
|
||||
"a place",
|
||||
null,
|
||||
"a description",
|
||||
null,
|
||||
"a cat",
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
"entityID",
|
||||
),
|
||||
)
|
||||
list.add(
|
||||
Place(
|
||||
|
|
@ -45,8 +56,8 @@ class BookmarkLocationControllerTest {
|
|||
null,
|
||||
null,
|
||||
true,
|
||||
"entityID"
|
||||
)
|
||||
"entityID",
|
||||
),
|
||||
)
|
||||
return list
|
||||
}
|
||||
|
|
@ -60,4 +71,4 @@ class BookmarkLocationControllerTest {
|
|||
bookmarkLocationsController!!.loadFavoritesLocations()
|
||||
Assert.assertEquals(2, bookmarkedLocations.size.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
|
|
@ -15,8 +14,8 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.contributions.ContributionController
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksLocationsBinding
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
|
|
@ -40,7 +39,6 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class BookmarkLocationFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: BookmarkLocationsFragment
|
||||
private lateinit var context: Context
|
||||
private lateinit var view: View
|
||||
|
|
@ -87,7 +85,8 @@ class BookmarkLocationFragmentUnitTests {
|
|||
null,
|
||||
null,
|
||||
true,
|
||||
"entityID")
|
||||
"entityID",
|
||||
),
|
||||
)
|
||||
return list
|
||||
}
|
||||
|
|
@ -108,28 +107,28 @@ class BookmarkLocationFragmentUnitTests {
|
|||
fragmentTransaction.commit()
|
||||
|
||||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = layoutInflater
|
||||
.inflate(R.layout.fragment_bookmarks_locations, null) as View
|
||||
view =
|
||||
layoutInflater
|
||||
.inflate(R.layout.fragment_bookmarks_locations, null) as View
|
||||
binding = FragmentBookmarksLocationsBinding.bind(view)
|
||||
|
||||
statusTextView = view.findViewById(R.id.statusMessage)
|
||||
progressBar = view.findViewById(R.id.loadingImagesProgressBar)
|
||||
recyclerView = view.findViewById(R.id.listView)
|
||||
commonPlaceClickActions = CommonPlaceClickActions(store,activity,contributionController)
|
||||
commonPlaceClickActions = CommonPlaceClickActions(store, activity, contributionController)
|
||||
|
||||
fragment.bookmarkLocationDao = bookmarkLocationDao
|
||||
fragment.controller = controller
|
||||
fragment.commonPlaceClickActions = commonPlaceClickActions
|
||||
Whitebox.setInternalState(fragment, "adapter", adapter)
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test init places when non empty
|
||||
*/
|
||||
@Test
|
||||
fun testInitNonEmpty(){
|
||||
fun testInitNonEmpty() {
|
||||
whenever(controller.loadFavoritesLocations()).thenReturn(mockBookmarkList)
|
||||
val method: Method =
|
||||
BookmarkLocationsFragment::class.java.getDeclaredMethod("initList")
|
||||
|
|
@ -143,7 +142,7 @@ class BookmarkLocationFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreateView() {
|
||||
fragment.onCreateView(layoutInflater,null,savedInstanceState)
|
||||
fragment.onCreateView(layoutInflater, null, savedInstanceState)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,23 +7,39 @@ import android.database.MatrixCursor
|
|||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.net.Uri
|
||||
import android.os.RemoteException
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.anyOrNull
|
||||
import com.nhaarman.mockitokotlin2.argumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.inOrder
|
||||
import com.nhaarman.mockitokotlin2.isA
|
||||
import com.nhaarman.mockitokotlin2.isNull
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.bookmarks.models.Bookmark
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider.BASE_URI
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.*
|
||||
import org.junit.Assert.*
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.COLUMN_CREATOR
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.COLUMN_MEDIA_NAME
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.CREATE_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.DROP_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.onCreate
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.onDelete
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao.Table.onUpdate
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.verifyNoInteractions
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class BookmarkPictureDaoTest {
|
||||
|
||||
private val columns = arrayOf(COLUMN_MEDIA_NAME, COLUMN_CREATOR)
|
||||
private val client: ContentProviderClient = mock()
|
||||
private val database: SQLiteDatabase = mock()
|
||||
|
|
@ -70,8 +86,7 @@ class BookmarkPictureDaoTest {
|
|||
|
||||
var result = testObject.allBookmarks
|
||||
|
||||
assertEquals(14,(result.size))
|
||||
|
||||
assertEquals(14, (result.size))
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException::class)
|
||||
|
|
@ -103,7 +118,6 @@ class BookmarkPictureDaoTest {
|
|||
verify(mockCursor).close()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun updateNewBookmark() {
|
||||
whenever(client.insert(any(), any())).thenReturn(exampleBookmark.contentUri)
|
||||
|
|
@ -210,9 +224,10 @@ class BookmarkPictureDaoTest {
|
|||
verify(database).execSQL(CREATE_TABLE_STATEMENT)
|
||||
}
|
||||
|
||||
private fun createCursor(rowCount: Int) = MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("mediaName", "creatorName"))
|
||||
private fun createCursor(rowCount: Int) =
|
||||
MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("mediaName", "creatorName"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import org.mockito.ArgumentMatchers
|
|||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Tests for bookmark pictures controller
|
||||
|
|
@ -40,10 +39,9 @@ class BookmarkPicturesControllerTest {
|
|||
.thenReturn(mockBookmarkList)
|
||||
whenever(
|
||||
mediaClient!!.getMedia(
|
||||
ArgumentMatchers.anyString()
|
||||
)
|
||||
)
|
||||
.thenReturn(Single.just(mockMedia))
|
||||
ArgumentMatchers.anyString(),
|
||||
),
|
||||
).thenReturn(Single.just(mockMedia))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +81,7 @@ class BookmarkPicturesControllerTest {
|
|||
}
|
||||
|
||||
private val mockMedia: Media
|
||||
private get() = media(filename="File:Test.jpg")
|
||||
private get() = media(filename = "File:Test.jpg")
|
||||
|
||||
/**
|
||||
* Test case where current bookmarks don't match the bookmarks in DB
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.content.Context
|
|||
import android.os.Bundle
|
||||
import android.os.Looper.getMainLooper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.GridView
|
||||
|
|
@ -18,13 +17,11 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.times
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.category.GridViewAdapter
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksPicturesBinding
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
|
|
@ -43,12 +40,10 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.annotation.LooperMode
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class BookmarkPicturesFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: BookmarkPicturesFragment
|
||||
|
||||
private lateinit var binding: FragmentBookmarksPicturesBinding
|
||||
|
|
@ -107,11 +102,15 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
|
||||
fragment.controller = controller
|
||||
|
||||
Whitebox.setInternalState(fragment, "gridAdapter", GridViewAdapter(
|
||||
context,
|
||||
0,
|
||||
listOf(media())
|
||||
))
|
||||
Whitebox.setInternalState(
|
||||
fragment,
|
||||
"gridAdapter",
|
||||
GridViewAdapter(
|
||||
context,
|
||||
0,
|
||||
listOf(media()),
|
||||
),
|
||||
)
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
Whitebox.setInternalState(binding, "statusMessage", statusTextView)
|
||||
|
|
@ -178,10 +177,11 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHandleError() {
|
||||
val method: Method = BookmarkPicturesFragment::class.java.getDeclaredMethod(
|
||||
"handleError",
|
||||
Throwable::class.java
|
||||
)
|
||||
val method: Method =
|
||||
BookmarkPicturesFragment::class.java.getDeclaredMethod(
|
||||
"handleError",
|
||||
Throwable::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, throwable)
|
||||
}
|
||||
|
|
@ -190,10 +190,11 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testHandleSuccess() {
|
||||
gridAdapter.addItems(listOf(media()))
|
||||
val method: Method = BookmarkPicturesFragment::class.java.getDeclaredMethod(
|
||||
"handleSuccess",
|
||||
List::class.java
|
||||
)
|
||||
val method: Method =
|
||||
BookmarkPicturesFragment::class.java.getDeclaredMethod(
|
||||
"handleSuccess",
|
||||
List::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, listOf(media()))
|
||||
verify(progressBar, times(1)).setVisibility(GONE)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import android.app.Activity
|
|||
import android.view.View
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.campaigns.models.Campaign
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
|
@ -22,7 +22,6 @@ import java.lang.reflect.Method
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class CampaignViewUnitTests {
|
||||
|
||||
private lateinit var activityController: ActivityController<Activity>
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var campaignView: CampaignView
|
||||
|
|
@ -80,11 +79,11 @@ class CampaignViewUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testInit() {
|
||||
val method: Method = CampaignView::class.java.getDeclaredMethod(
|
||||
"init"
|
||||
)
|
||||
val method: Method =
|
||||
CampaignView::class.java.getDeclaredMethod(
|
||||
"init",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(campaignView)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ import org.mockito.Mockito
|
|||
import org.mockito.MockitoAnnotations
|
||||
import java.lang.reflect.Field
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class CampaignsPresenterTest {
|
||||
|
|
@ -44,9 +46,9 @@ class CampaignsPresenterTest {
|
|||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
testScheduler=TestScheduler()
|
||||
campaignsSingle= Single.just(campaignResponseDTO)
|
||||
campaignsPresenter= CampaignsPresenter(okHttpJsonApiClient,testScheduler,testScheduler)
|
||||
testScheduler = TestScheduler()
|
||||
campaignsSingle = Single.just(campaignResponseDTO)
|
||||
campaignsPresenter = CampaignsPresenter(okHttpJsonApiClient, testScheduler, testScheduler)
|
||||
campaignsPresenter.onAttachView(view)
|
||||
Mockito.`when`(okHttpJsonApiClient.campaigns).thenReturn(campaignsSingle)
|
||||
}
|
||||
|
|
@ -62,17 +64,17 @@ class CampaignsPresenterTest {
|
|||
@Test
|
||||
fun getCampaignsTestNonEmptyCampaigns() {
|
||||
campaignsPresenter.getCampaigns()
|
||||
var campaigns= ArrayList<Campaign>()
|
||||
var campaigns = ArrayList<Campaign>()
|
||||
campaigns.add(campaign)
|
||||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT)
|
||||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC")
|
||||
Mockito.`when`(campaignResponseDTO.campaigns).thenReturn(campaigns)
|
||||
var calendar = Calendar.getInstance()
|
||||
calendar.add(Calendar.DATE,-1)
|
||||
calendar.add(Calendar.DATE, -1)
|
||||
val startDateString = simpleDateFormat.format(calendar.time).toString()
|
||||
calendar= Calendar.getInstance()
|
||||
calendar.add(Calendar.DATE,3)
|
||||
val endDateString= simpleDateFormat.format(calendar.time).toString()
|
||||
calendar = Calendar.getInstance()
|
||||
calendar.add(Calendar.DATE, 3)
|
||||
val endDateString = simpleDateFormat.format(calendar.time).toString()
|
||||
Mockito.`when`(campaign.endDate).thenReturn(endDateString)
|
||||
Mockito.`when`(campaign.startDate).thenReturn(startDateString)
|
||||
Mockito.`when`(campaignResponseDTO.campaigns).thenReturn(campaigns)
|
||||
|
|
@ -105,5 +107,4 @@ class CampaignsPresenterTest {
|
|||
disposableField.set(campaignsPresenter, disposable)
|
||||
campaignsPresenter.onDetachView()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ import org.mockito.ArgumentMatchers
|
|||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
//class for testing CategoriesModel class
|
||||
// class for testing CategoriesModel class
|
||||
class CategoriesModelTest {
|
||||
|
||||
@Mock
|
||||
internal lateinit var categoryDao: CategoryDao
|
||||
|
||||
|
|
@ -41,59 +40,125 @@ class CategoriesModelTest {
|
|||
fun searchAllFoundCaseTest() {
|
||||
val categoriesModel = CategoriesModel(categoryClient, mock(), mock())
|
||||
|
||||
val expectedList = listOf(CategoryItem(
|
||||
"Test", "", "", false))
|
||||
val expectedList =
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"Test",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
)
|
||||
whenever(
|
||||
categoryClient.searchCategoriesForPrefix(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyInt(),
|
||||
ArgumentMatchers.anyInt()
|
||||
)
|
||||
)
|
||||
.thenReturn(Single.just(expectedList))
|
||||
ArgumentMatchers.anyInt(),
|
||||
),
|
||||
).thenReturn(Single.just(expectedList))
|
||||
|
||||
// Checking if both return "Test"
|
||||
val expectedItems = expectedList.map { CategoryItem(
|
||||
it.name, it.description, it.thumbnail, false) }
|
||||
val expectedItems =
|
||||
expectedList.map {
|
||||
CategoryItem(
|
||||
it.name,
|
||||
it.description,
|
||||
it.thumbnail,
|
||||
false,
|
||||
)
|
||||
}
|
||||
var categoryTerm = "Test"
|
||||
categoriesModel.searchAll(categoryTerm, emptyList(), emptyList())
|
||||
categoriesModel
|
||||
.searchAll(categoryTerm, emptyList(), emptyList())
|
||||
.test()
|
||||
.assertValues(expectedItems)
|
||||
|
||||
verify(categoryClient).searchCategoriesForPrefix(
|
||||
categoryTerm,
|
||||
CategoriesModel.SEARCH_CATS_LIMIT
|
||||
CategoriesModel.SEARCH_CATS_LIMIT,
|
||||
)
|
||||
|
||||
categoriesModel.searchAll(categoryTerm, emptyList(), emptyList())
|
||||
categoriesModel
|
||||
.searchAll(categoryTerm, emptyList(), emptyList())
|
||||
.test()
|
||||
.assertValues(expectedItems)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `searchAll with empty search terms creates results from gps, title search & recents`() {
|
||||
val gpsCategoryModel: GpsCategoryModel = mock()
|
||||
val depictedItem = depictedItem(commonsCategories = listOf(CategoryItem(
|
||||
"depictionCategory", "", "", false)))
|
||||
val depictedItem =
|
||||
depictedItem(
|
||||
commonsCategories =
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"depictionCategory",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
whenever(gpsCategoryModel.categoriesFromLocation)
|
||||
.thenReturn(BehaviorSubject.createDefault(listOf(CategoryItem(
|
||||
"gpsCategory", "", "", false))))
|
||||
.thenReturn(
|
||||
BehaviorSubject.createDefault(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"gpsCategory",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
whenever(
|
||||
categoryClient.searchCategories(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyInt(),
|
||||
ArgumentMatchers.anyInt()
|
||||
)
|
||||
ArgumentMatchers.anyInt(),
|
||||
),
|
||||
).thenReturn(
|
||||
Single.just(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"titleSearch",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
whenever(categoryDao.recentCategories(25)).thenReturn(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"recentCategories",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
)
|
||||
whenever(
|
||||
categoryClient.getCategoriesByName(
|
||||
"depictionCategory",
|
||||
"depictionCategory",
|
||||
25,
|
||||
),
|
||||
).thenReturn(
|
||||
Single.just(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"commonsCategories",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.thenReturn(Single.just(listOf(CategoryItem(
|
||||
"titleSearch", "", "", false))))
|
||||
whenever(categoryDao.recentCategories(25)).thenReturn(listOf(CategoryItem(
|
||||
"recentCategories","","", false)))
|
||||
whenever(categoryClient.getCategoriesByName("depictionCategory",
|
||||
"depictionCategory", 25)).thenReturn(Single.just(listOf(CategoryItem(
|
||||
"commonsCategories","","", false))))
|
||||
val imageTitleList = listOf("Test")
|
||||
CategoriesModel(categoryClient, categoryDao, gpsCategoryModel)
|
||||
.searchAll("", imageTitleList, listOf(depictedItem))
|
||||
|
|
@ -103,8 +168,8 @@ class CategoriesModelTest {
|
|||
categoryItem("commonsCategories"),
|
||||
categoryItem("gpsCategory"),
|
||||
categoryItem("titleSearch"),
|
||||
categoryItem("recentCategories")
|
||||
)
|
||||
categoryItem("recentCategories"),
|
||||
),
|
||||
)
|
||||
imageTitleList.forEach {
|
||||
verify(categoryClient).searchCategories(it, CategoriesModel.SEARCH_CATS_LIMIT)
|
||||
|
|
@ -113,103 +178,121 @@ class CategoriesModelTest {
|
|||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetCategoriesByName(){
|
||||
fun testGetCategoriesByName() {
|
||||
categoriesModel.getCategoriesByName(listOf("Test"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test buildCategories when it returns non empty list`(){
|
||||
whenever(categoryClient.getCategoriesByName("Test",
|
||||
"Test", CategoriesModel.SEARCH_CATS_LIMIT
|
||||
)).thenReturn(Single.just(listOf(categoryItem())))
|
||||
fun `Test buildCategories when it returns non empty list`() {
|
||||
whenever(
|
||||
categoryClient.getCategoriesByName(
|
||||
"Test",
|
||||
"Test",
|
||||
CategoriesModel.SEARCH_CATS_LIMIT,
|
||||
),
|
||||
).thenReturn(Single.just(listOf(categoryItem())))
|
||||
categoriesModel.buildCategories("Test")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test buildCategories when it returns empty list`(){
|
||||
whenever(categoryClient.getCategoriesByName("Test",
|
||||
"Test", CategoriesModel.SEARCH_CATS_LIMIT
|
||||
)).thenReturn(Single.just(emptyList()))
|
||||
fun `Test buildCategories when it returns empty list`() {
|
||||
whenever(
|
||||
categoryClient.getCategoriesByName(
|
||||
"Test",
|
||||
"Test",
|
||||
CategoriesModel.SEARCH_CATS_LIMIT,
|
||||
),
|
||||
).thenReturn(Single.just(emptyList()))
|
||||
categoriesModel.buildCategories("Test")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetSelectedExistingCategories(){
|
||||
fun testGetSelectedExistingCategories() {
|
||||
categoriesModel.getSelectedExistingCategories()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetSelectedExistingCategories(){
|
||||
fun testSetSelectedExistingCategories() {
|
||||
categoriesModel.setSelectedExistingCategories(mutableListOf("Test"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is null and item is selected`(){
|
||||
fun `Test onCategoryItemClicked when media is null and item is selected`() {
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"name",
|
||||
"des",
|
||||
"image",
|
||||
true
|
||||
), null)
|
||||
true,
|
||||
),
|
||||
null,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is null and item is not selected`(){
|
||||
fun `Test onCategoryItemClicked when media is null and item is not selected`() {
|
||||
categoriesModel.onCategoryItemClicked(categoryItem(), null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is selected and media contains category`(){
|
||||
fun `Test onCategoryItemClicked when media is not null and item is selected and media contains category`() {
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"categories",
|
||||
"des",
|
||||
"image",
|
||||
true
|
||||
), media())
|
||||
true,
|
||||
),
|
||||
media(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is selected and media does not contains category`(){
|
||||
fun `Test onCategoryItemClicked when media is not null and item is selected and media does not contains category`() {
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"name",
|
||||
"des",
|
||||
"image",
|
||||
true
|
||||
), media())
|
||||
true,
|
||||
),
|
||||
media(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is not selected and media contains category`(){
|
||||
fun `Test onCategoryItemClicked when media is not null and item is not selected and media contains category`() {
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"categories",
|
||||
"des",
|
||||
"image",
|
||||
false
|
||||
), media())
|
||||
false,
|
||||
),
|
||||
media(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `Test onCategoryItemClicked when media is not null and item is not selected and media does not contains category`(){
|
||||
fun `Test onCategoryItemClicked when media is not null and item is not selected and media does not contains category`() {
|
||||
categoriesModel.onCategoryItemClicked(
|
||||
CategoryItem(
|
||||
"name",
|
||||
"des",
|
||||
"image",
|
||||
false
|
||||
), media())
|
||||
false,
|
||||
),
|
||||
media(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,19 @@ package fr.free.nrw.commons.category
|
|||
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResult
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.*
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.ArgumentMatchers.anyMap
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResult
|
||||
|
||||
class CategoryClientTest {
|
||||
@Mock
|
||||
|
|
@ -32,10 +34,12 @@ class CategoryClientTest {
|
|||
val mockResponse = withMockResponse("Category:Test")
|
||||
whenever(categoryInterface.searchCategories(anyString(), anyInt(), anyInt()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.searchCategories("tes", 10)
|
||||
categoryClient
|
||||
.searchCategories("tes", 10)
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "", "", false)))
|
||||
categoryClient.searchCategories("tes", 10, 10)
|
||||
categoryClient
|
||||
.searchCategories("tes", 10, 10)
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "", "", false)))
|
||||
}
|
||||
|
|
@ -45,22 +49,27 @@ class CategoryClientTest {
|
|||
val mockResponse = withNullPages()
|
||||
whenever(categoryInterface.searchCategories(anyString(), anyInt(), anyInt()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.searchCategories("tes", 10)
|
||||
categoryClient
|
||||
.searchCategories("tes", 10)
|
||||
.test()
|
||||
.assertValues(emptyList())
|
||||
categoryClient.searchCategories("tes", 10, 10)
|
||||
categoryClient
|
||||
.searchCategories("tes", 10, 10)
|
||||
.test()
|
||||
.assertValues(emptyList())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun searchCategoriesForPrefixFound() {
|
||||
val mockResponse = withMockResponse("Category:Test")
|
||||
whenever(categoryInterface.searchCategoriesForPrefix(anyString(), anyInt(), anyInt()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.searchCategoriesForPrefix("tes", 10)
|
||||
categoryClient
|
||||
.searchCategoriesForPrefix("tes", 10)
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "", "", false)))
|
||||
categoryClient.searchCategoriesForPrefix("tes", 10, 10)
|
||||
categoryClient
|
||||
.searchCategoriesForPrefix("tes", 10, 10)
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "", "", false)))
|
||||
}
|
||||
|
|
@ -70,10 +79,12 @@ class CategoryClientTest {
|
|||
val mockResponse = withNullPages()
|
||||
whenever(categoryInterface.searchCategoriesForPrefix(anyString(), anyInt(), anyInt()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.searchCategoriesForPrefix("tes", 10)
|
||||
categoryClient
|
||||
.searchCategoriesForPrefix("tes", 10)
|
||||
.test()
|
||||
.assertValues(emptyList())
|
||||
categoryClient.searchCategoriesForPrefix("tes", 10, 10)
|
||||
categoryClient
|
||||
.searchCategoriesForPrefix("tes", 10, 10)
|
||||
.test()
|
||||
.assertValues(emptyList())
|
||||
}
|
||||
|
|
@ -81,33 +92,71 @@ class CategoryClientTest {
|
|||
@Test
|
||||
fun getCategoriesByNameFound() {
|
||||
val mockResponse = withMockResponse("Category:Test")
|
||||
whenever(categoryInterface.getCategoriesByName(anyString(), anyString(),
|
||||
anyInt(), anyInt()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.getCategoriesByName("tes", "tes", 10)
|
||||
whenever(
|
||||
categoryInterface.getCategoriesByName(
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyInt(),
|
||||
anyInt(),
|
||||
),
|
||||
).thenReturn(Single.just(mockResponse))
|
||||
categoryClient
|
||||
.getCategoriesByName("tes", "tes", 10)
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "",
|
||||
"", false)))
|
||||
categoryClient.getCategoriesByName("tes" , "tes",
|
||||
10, 10)
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "",
|
||||
"", false)))
|
||||
.assertValues(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"Test",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
)
|
||||
categoryClient
|
||||
.getCategoriesByName(
|
||||
"tes",
|
||||
"tes",
|
||||
10,
|
||||
10,
|
||||
).test()
|
||||
.assertValues(
|
||||
listOf(
|
||||
CategoryItem(
|
||||
"Test",
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getCategoriesByNameNull() {
|
||||
val mockResponse = withNullPages()
|
||||
whenever(categoryInterface.getCategoriesByName(anyString(), anyString(),
|
||||
anyInt(), anyInt()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.getCategoriesByName("tes", "tes",
|
||||
10)
|
||||
.test()
|
||||
whenever(
|
||||
categoryInterface.getCategoriesByName(
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyInt(),
|
||||
anyInt(),
|
||||
),
|
||||
).thenReturn(Single.just(mockResponse))
|
||||
categoryClient
|
||||
.getCategoriesByName(
|
||||
"tes",
|
||||
"tes",
|
||||
10,
|
||||
).test()
|
||||
.assertValues(emptyList())
|
||||
categoryClient.getCategoriesByName("tes", "tes",
|
||||
10, 10)
|
||||
.test()
|
||||
categoryClient
|
||||
.getCategoriesByName(
|
||||
"tes",
|
||||
"tes",
|
||||
10,
|
||||
10,
|
||||
).test()
|
||||
.assertValues(emptyList())
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +165,8 @@ class CategoryClientTest {
|
|||
val mockResponse = withMockResponse("Category:Test")
|
||||
whenever(categoryInterface.getParentCategoryList(anyString(), anyMap()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.getParentCategoryList("tes")
|
||||
categoryClient
|
||||
.getParentCategoryList("tes")
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "", "", false)))
|
||||
}
|
||||
|
|
@ -126,7 +176,8 @@ class CategoryClientTest {
|
|||
val mockResponse = withNullPages()
|
||||
whenever(categoryInterface.getParentCategoryList(anyString(), anyMap()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.getParentCategoryList("tes")
|
||||
categoryClient
|
||||
.getParentCategoryList("tes")
|
||||
.test()
|
||||
.assertValues(emptyList())
|
||||
}
|
||||
|
|
@ -136,7 +187,8 @@ class CategoryClientTest {
|
|||
val mockResponse = withMockResponse("Category:Test")
|
||||
whenever(categoryInterface.getSubCategoryList("tes", emptyMap()))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.getSubCategoryList("tes")
|
||||
categoryClient
|
||||
.getSubCategoryList("tes")
|
||||
.test()
|
||||
.assertValues(listOf(CategoryItem("Test", "", "", false)))
|
||||
}
|
||||
|
|
@ -144,12 +196,14 @@ class CategoryClientTest {
|
|||
@Test
|
||||
fun getSubCategoryListNull() {
|
||||
val mockResponse = withNullPages()
|
||||
whenever(categoryInterface.getSubCategoryList(
|
||||
anyString(),
|
||||
anyMap()
|
||||
))
|
||||
.thenReturn(Single.just(mockResponse))
|
||||
categoryClient.getSubCategoryList("tes")
|
||||
whenever(
|
||||
categoryInterface.getSubCategoryList(
|
||||
anyString(),
|
||||
anyMap(),
|
||||
),
|
||||
).thenReturn(Single.just(mockResponse))
|
||||
categoryClient
|
||||
.getSubCategoryList("tes")
|
||||
.test()
|
||||
.assertValues(emptyList())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,55 @@ import android.database.Cursor
|
|||
import android.database.MatrixCursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.os.RemoteException
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import fr.free.nrw.commons.BuildConfig
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.anyOrNull
|
||||
import com.nhaarman.mockitokotlin2.argumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.inOrder
|
||||
import com.nhaarman.mockitokotlin2.isA
|
||||
import com.nhaarman.mockitokotlin2.isNull
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.category.CategoryContentProvider.BASE_URI
|
||||
import fr.free.nrw.commons.category.CategoryContentProvider.uriForId
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.*
|
||||
import org.junit.Assert.*
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.ALL_FIELDS
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_DESCRIPTION
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_ID
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_LAST_USED
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_NAME
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_THUMBNAIL
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_TIMES_USED
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.CREATE_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.DROP_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.onCreate
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.onDelete
|
||||
import fr.free.nrw.commons.category.CategoryDao.Table.onUpdate
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.verifyNoInteractions
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class CategoryDaoTest {
|
||||
|
||||
private val columns = arrayOf(COLUMN_ID, COLUMN_NAME, COLUMN_DESCRIPTION,
|
||||
COLUMN_THUMBNAIL, COLUMN_LAST_USED, COLUMN_TIMES_USED)
|
||||
private val columns =
|
||||
arrayOf(
|
||||
COLUMN_ID,
|
||||
COLUMN_NAME,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_THUMBNAIL,
|
||||
COLUMN_LAST_USED,
|
||||
COLUMN_TIMES_USED,
|
||||
)
|
||||
private val client: ContentProviderClient = mock()
|
||||
private val database: SQLiteDatabase = mock()
|
||||
private val captor = argumentCaptor<ContentValues>()
|
||||
|
|
@ -138,8 +166,15 @@ class CategoryDaoTest {
|
|||
fun saveNewCategory() {
|
||||
val contentUri = CategoryContentProvider.uriForId(111)
|
||||
whenever(client.insert(isA(), isA())).thenReturn(contentUri)
|
||||
val category = Category(null, "showImageWithItem", "description",
|
||||
"image", Date(234L), 1)
|
||||
val category =
|
||||
Category(
|
||||
null,
|
||||
"showImageWithItem",
|
||||
"description",
|
||||
"image",
|
||||
Date(234L),
|
||||
1,
|
||||
)
|
||||
|
||||
testObject.save(category)
|
||||
|
||||
|
|
@ -199,11 +234,11 @@ class CategoryDaoTest {
|
|||
assertEquals(2, category?.timesUsed)
|
||||
|
||||
verify(client).query(
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
eq("$COLUMN_NAME=?"),
|
||||
queryCaptor.capture(),
|
||||
isNull()
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
eq("$COLUMN_NAME=?"),
|
||||
queryCaptor.capture(),
|
||||
isNull(),
|
||||
)
|
||||
assertEquals("showImageWithItem", queryCaptor.firstValue[0])
|
||||
}
|
||||
|
|
@ -253,11 +288,11 @@ class CategoryDaoTest {
|
|||
assertEquals("showImageWithItem", result[0].name)
|
||||
|
||||
verify(client).query(
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
isNull(),
|
||||
queryCaptor.capture(),
|
||||
eq("$COLUMN_LAST_USED DESC")
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
isNull(),
|
||||
queryCaptor.capture(),
|
||||
eq("$COLUMN_LAST_USED DESC"),
|
||||
)
|
||||
assertEquals(0, queryCaptor.firstValue.size)
|
||||
}
|
||||
|
|
@ -271,10 +306,10 @@ class CategoryDaoTest {
|
|||
assertEquals(5, result.size)
|
||||
}
|
||||
|
||||
private fun createCursor(rowCount: Int) = MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("1", "showImageWithItem", "description", "image", "123", "2"))
|
||||
private fun createCursor(rowCount: Int) =
|
||||
MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("1", "showImageWithItem", "description", "image", "123", "2"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import java.lang.reflect.Field
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class CategoryDetailsActivityUnitTests {
|
||||
|
||||
private lateinit var activity: CategoryDetailsActivity
|
||||
|
||||
private lateinit var context: Context
|
||||
|
|
@ -38,7 +37,6 @@ class CategoryDetailsActivityUnitTests {
|
|||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
|
|
@ -110,5 +108,4 @@ class CategoryDetailsActivityUnitTests {
|
|||
fun testViewPagerNotifyDataSetChanged() {
|
||||
activity.viewPagerNotifyDataSetChanged()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.robolectric.annotation.LooperMode
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class CategoryEditHelperUnitTests {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var helper: CategoryEditHelper
|
||||
|
||||
|
|
@ -46,18 +45,25 @@ class CategoryEditHelperUnitTests {
|
|||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
helper = CategoryEditHelper(notificationHelper, pageEditClient, viewUtilWrapper,
|
||||
"")
|
||||
Mockito.`when`(media.filename).thenReturn("File:Example.jpg")
|
||||
Mockito.`when`(pageEditClient.getCurrentWikiText(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(""))
|
||||
Mockito.`when`(
|
||||
pageEditClient.edit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString()
|
||||
helper =
|
||||
CategoryEditHelper(
|
||||
notificationHelper,
|
||||
pageEditClient,
|
||||
viewUtilWrapper,
|
||||
"",
|
||||
)
|
||||
).thenReturn(Observable.just(true))
|
||||
Mockito.`when`(media.filename).thenReturn("File:Example.jpg")
|
||||
Mockito
|
||||
.`when`(pageEditClient.getCurrentWikiText(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(""))
|
||||
Mockito
|
||||
.`when`(
|
||||
pageEditClient.edit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
),
|
||||
).thenReturn(Observable.just(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -72,19 +78,23 @@ class CategoryEditHelperUnitTests {
|
|||
helper.makeCategoryEdit(context, media, listOf("Test"), "[[Category:Test]]")
|
||||
Mockito.verify(viewUtilWrapper, Mockito.times(1)).showShortToast(
|
||||
context,
|
||||
context.getString(R.string.category_edit_helper_make_edit_toast)
|
||||
context.getString(R.string.category_edit_helper_make_edit_toast),
|
||||
)
|
||||
Mockito.verify(pageEditClient, Mockito.times(1)).edit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString()
|
||||
ArgumentMatchers.anyString(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testMakeUnCategoryEdit() {
|
||||
helper.makeCategoryEdit(context, media, listOf("Test"), "== {{int:filedesc}} ==\n" +
|
||||
helper.makeCategoryEdit(
|
||||
context,
|
||||
media,
|
||||
listOf("Test"),
|
||||
"== {{int:filedesc}} ==\n" +
|
||||
"{{Information\n" +
|
||||
"|description=\n" +
|
||||
"|source={{own}}\n" +
|
||||
|
|
@ -97,15 +107,16 @@ class CategoryEditHelperUnitTests {
|
|||
"{{self|cc-zero}}\n" +
|
||||
"\n" +
|
||||
"{{Uploaded from Mobile|platform=Android|version=3.1.1-debug-master~e7a9ba9ad}}\n" +
|
||||
"{{Uncategorized|year=2022|month=April|day=23}}")
|
||||
"{{Uncategorized|year=2022|month=April|day=23}}",
|
||||
)
|
||||
Mockito.verify(viewUtilWrapper, Mockito.times(1)).showShortToast(
|
||||
context,
|
||||
context.getString(R.string.category_edit_helper_make_edit_toast)
|
||||
context.getString(R.string.category_edit_helper_make_edit_toast),
|
||||
)
|
||||
Mockito.verify(pageEditClient, Mockito.times(1)).edit(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString()
|
||||
ArgumentMatchers.anyString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import java.lang.reflect.Method
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class GridViewAdapterUnitTest {
|
||||
|
||||
private lateinit var gridViewAdapter: GridViewAdapter
|
||||
private lateinit var activity: CategoryDetailsActivity
|
||||
private lateinit var context: Context
|
||||
|
|
@ -47,10 +46,8 @@ class GridViewAdapterUnitTest {
|
|||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
||||
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
SoLoader.setInTestMode()
|
||||
|
|
@ -59,8 +56,10 @@ class GridViewAdapterUnitTest {
|
|||
|
||||
activity = Robolectric.buildActivity(CategoryDetailsActivity::class.java).get()
|
||||
|
||||
convertView = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.layout_category_images, null) as View
|
||||
convertView =
|
||||
LayoutInflater
|
||||
.from(activity)
|
||||
.inflate(R.layout.layout_category_images, null) as View
|
||||
|
||||
gridViewAdapter = GridViewAdapter(context, 0, images)
|
||||
}
|
||||
|
|
@ -116,11 +115,13 @@ class GridViewAdapterUnitTest {
|
|||
@Test
|
||||
fun testSetUploaderView() {
|
||||
`when`(media1.author).thenReturn("author")
|
||||
val method: Method = GridViewAdapter::class.java.getDeclaredMethod(
|
||||
"setUploaderView", Media::class.java, TextView::class.java
|
||||
)
|
||||
val method: Method =
|
||||
GridViewAdapter::class.java.getDeclaredMethod(
|
||||
"setUploaderView",
|
||||
Media::class.java,
|
||||
TextView::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(gridViewAdapter, media1, textView)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ class ContributionBoundaryCallbackTest {
|
|||
whenever(mediaClient.getMediaListForUser(anyString()))
|
||||
.thenReturn(Single.just(listOf(media())))
|
||||
contributionBoundaryCallback.onZeroItemsLoaded()
|
||||
verify(repository).save(anyList<Contribution>());
|
||||
verify(mediaClient).getMediaListForUser(anyString());
|
||||
verify(repository).save(anyList<Contribution>())
|
||||
verify(mediaClient).getMediaListForUser(anyString())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -74,8 +74,8 @@ class ContributionBoundaryCallbackTest {
|
|||
whenever(mediaClient.getMediaListForUser(anyString()))
|
||||
.thenReturn(Single.just(listOf(media())))
|
||||
contributionBoundaryCallback.onItemAtEndLoaded(mock(Contribution::class.java))
|
||||
verify(repository).save(anyList());
|
||||
verify(mediaClient).getMediaListForUser(anyString());
|
||||
verify(repository).save(anyList())
|
||||
verify(mediaClient).getMediaListForUser(anyString())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -94,27 +94,29 @@ class ContributionBoundaryCallbackTest {
|
|||
.thenReturn(Single.just(listOf(1L, 2L)))
|
||||
whenever(sessionManager.userName).thenReturn("Test")
|
||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(
|
||||
Single.just(listOf(media()))
|
||||
)
|
||||
val method: Method = ContributionBoundaryCallback::class.java.getDeclaredMethod(
|
||||
"fetchContributions"
|
||||
Single.just(listOf(media())),
|
||||
)
|
||||
val method: Method =
|
||||
ContributionBoundaryCallback::class.java.getDeclaredMethod(
|
||||
"fetchContributions",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionBoundaryCallback)
|
||||
verify(repository).save(anyList());
|
||||
verify(mediaClient).getMediaListForUser(anyString());
|
||||
verify(repository).save(anyList())
|
||||
verify(mediaClient).getMediaListForUser(anyString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFetchContributionsFailed() {
|
||||
whenever(sessionManager.userName).thenReturn("Test")
|
||||
whenever(mediaClient.getMediaListForUser(anyString())).thenReturn(Single.error(Exception("Error")))
|
||||
val method: Method = ContributionBoundaryCallback::class.java.getDeclaredMethod(
|
||||
"fetchContributions"
|
||||
)
|
||||
val method: Method =
|
||||
ContributionBoundaryCallback::class.java.getDeclaredMethod(
|
||||
"fetchContributions",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionBoundaryCallback)
|
||||
verifyNoInteractions(repository)
|
||||
verify(mediaClient).getMediaListForUser(anyString());
|
||||
verify(mediaClient).getMediaListForUser(anyString())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,8 @@ import android.net.Uri
|
|||
import android.os.Looper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.facebook.soloader.SoLoader
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.R
|
||||
|
|
@ -25,7 +20,7 @@ import org.junit.Before
|
|||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.reflect.Whitebox
|
||||
|
|
@ -34,16 +29,13 @@ import org.robolectric.RobolectricTestRunner
|
|||
import org.robolectric.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
@PrepareForTest(ContributionViewHolder::class)
|
||||
class ContributionViewHolderUnitTests {
|
||||
|
||||
private lateinit var contributionViewHolder: ContributionViewHolder
|
||||
private lateinit var activity: ProfileActivity
|
||||
private lateinit var parent: View
|
||||
|
|
@ -66,7 +58,7 @@ class ContributionViewHolderUnitTests {
|
|||
@Mock
|
||||
private lateinit var media: Media
|
||||
|
||||
private lateinit var bindind : LayoutContributionBinding
|
||||
private lateinit var bindind: LayoutContributionBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
|
@ -82,8 +74,9 @@ class ContributionViewHolderUnitTests {
|
|||
Whitebox.setInternalState(contributionViewHolder, "binding", bindind)
|
||||
|
||||
setFinalStatic(
|
||||
ContributionViewHolder::class.java.getDeclaredField("compositeDisposable"),
|
||||
compositeDisposable)
|
||||
ContributionViewHolder::class.java.getDeclaredField("compositeDisposable"),
|
||||
compositeDisposable,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -108,11 +101,12 @@ class ContributionViewHolderUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testChooseImageSource() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"chooseImageSource",
|
||||
String::class.java,
|
||||
Uri::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"chooseImageSource",
|
||||
String::class.java,
|
||||
Uri::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder, "", uri)
|
||||
}
|
||||
|
|
@ -121,10 +115,11 @@ class ContributionViewHolderUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testDisplayWikipediaButton() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"displayWikipediaButton",
|
||||
Boolean::class.javaObjectType
|
||||
)
|
||||
val method: Method =
|
||||
ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"displayWikipediaButton",
|
||||
Boolean::class.javaObjectType,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder, false)
|
||||
}
|
||||
|
|
@ -134,10 +129,11 @@ class ContributionViewHolderUnitTests {
|
|||
fun testCheckIfMediaExistsOnWikipediaPageCaseNull() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(contribution.wikidataPlace).thenReturn(null)
|
||||
val method: Method = ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"checkIfMediaExistsOnWikipediaPage",
|
||||
Contribution::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionViewHolder::class.java.getDeclaredMethod(
|
||||
"checkIfMediaExistsOnWikipediaPage",
|
||||
Contribution::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(contributionViewHolder, contribution)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ package fr.free.nrw.commons.contributions
|
|||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
|
|
@ -12,10 +16,9 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.campaigns.CampaignView
|
||||
import fr.free.nrw.commons.campaigns.models.Campaign
|
||||
import fr.free.nrw.commons.databinding.FragmentContributionsBinding
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
|
||||
|
|
@ -29,7 +32,10 @@ import org.junit.Assert
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.*
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.anyBoolean
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
|
|
@ -46,7 +52,6 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ContributionsFragmentUnitTests {
|
||||
|
||||
@Mock
|
||||
private lateinit var mediaDetailPagerFragment: MediaDetailPagerFragment
|
||||
|
||||
|
|
@ -105,7 +110,6 @@ class ContributionsFragmentUnitTests {
|
|||
context = ApplicationProvider.getApplicationContext()
|
||||
activity = Robolectric.buildActivity(MainActivity::class.java).create().get()
|
||||
|
||||
|
||||
fragment = ContributionsFragment.newInstance()
|
||||
val fragmentManager: FragmentManager = activity.supportFragmentManager
|
||||
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
||||
|
|
@ -113,8 +117,10 @@ class ContributionsFragmentUnitTests {
|
|||
fragmentTransaction.commit()
|
||||
|
||||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.fragment_contributions, null) as View
|
||||
view =
|
||||
LayoutInflater
|
||||
.from(activity)
|
||||
.inflate(R.layout.fragment_contributions, null) as View
|
||||
|
||||
nearbyNotificationCardView = view.findViewById(R.id.card_view_nearby)
|
||||
campaignView = view.findViewById(R.id.campaigns_view)
|
||||
|
|
@ -157,17 +163,20 @@ class ContributionsFragmentUnitTests {
|
|||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(notificationController.getNotifications(anyBoolean())).thenReturn(singleNotification)
|
||||
`when`(notificationController.getNotifications(anyBoolean()).subscribeOn(any())).thenReturn(
|
||||
singleNotification
|
||||
singleNotification,
|
||||
)
|
||||
`when`(
|
||||
notificationController.getNotifications(anyBoolean()).subscribeOn(any()).observeOn(
|
||||
any()
|
||||
)
|
||||
any(),
|
||||
),
|
||||
).thenReturn(singleNotification)
|
||||
`when`(
|
||||
notificationController.getNotifications(anyBoolean()).subscribeOn(any()).observeOn(
|
||||
any()
|
||||
).subscribe()
|
||||
notificationController
|
||||
.getNotifications(anyBoolean())
|
||||
.subscribeOn(any())
|
||||
.observeOn(
|
||||
any(),
|
||||
).subscribe(),
|
||||
).thenReturn(compositeDisposable)
|
||||
fragment.setNotificationCount()
|
||||
}
|
||||
|
|
@ -176,10 +185,11 @@ class ContributionsFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testInitNotificationViewsCaseEmptyList() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionsFragment::class.java.getDeclaredMethod(
|
||||
"initNotificationViews",
|
||||
List::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsFragment::class.java.getDeclaredMethod(
|
||||
"initNotificationViews",
|
||||
List::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, listOf<Notification>())
|
||||
}
|
||||
|
|
@ -190,10 +200,11 @@ class ContributionsFragmentUnitTests {
|
|||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val list: List<Notification> =
|
||||
listOf(Notification(NotificationType.UNKNOWN, "", "", "", "", ""))
|
||||
val method: Method = ContributionsFragment::class.java.getDeclaredMethod(
|
||||
"initNotificationViews",
|
||||
List::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsFragment::class.java.getDeclaredMethod(
|
||||
"initNotificationViews",
|
||||
List::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, list)
|
||||
}
|
||||
|
|
@ -209,7 +220,7 @@ class ContributionsFragmentUnitTests {
|
|||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testScrollToTop(){
|
||||
fun testScrollToTop() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.scrollToTop()
|
||||
verify(contributionsListFragment).scrollToTop()
|
||||
|
|
@ -348,5 +359,4 @@ class ContributionsFragmentUnitTests {
|
|||
`when`(mediaDetailPagerFragment.isVisible).thenReturn(false)
|
||||
fragment.showDetail(0, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ContributionsListFragmentUnitTests {
|
||||
|
||||
private lateinit var scenario: FragmentScenario<ContributionsListFragment>
|
||||
private lateinit var fragment: ContributionsListFragment
|
||||
|
||||
|
|
@ -43,17 +42,19 @@ class ContributionsListFragmentUnitTests {
|
|||
fun setUp() {
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
|
||||
scenario = launchFragmentInContainer(
|
||||
initialState = Lifecycle.State.RESUMED,
|
||||
themeResId = R.style.LightAppTheme
|
||||
) {
|
||||
ContributionsListFragment().apply {
|
||||
contributionsListPresenter = mock()
|
||||
callback = mock()
|
||||
}.also {
|
||||
fragment = it
|
||||
scenario =
|
||||
launchFragmentInContainer(
|
||||
initialState = Lifecycle.State.RESUMED,
|
||||
themeResId = R.style.LightAppTheme,
|
||||
) {
|
||||
ContributionsListFragment()
|
||||
.apply {
|
||||
contributionsListPresenter = mock()
|
||||
callback = mock()
|
||||
}.also {
|
||||
fragment = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scenario.onFragment {
|
||||
it.adapter = adapter
|
||||
|
|
@ -129,10 +130,11 @@ class ContributionsListFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testShowAddImageToWikipediaInstructions() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"showAddImageToWikipediaInstructions",
|
||||
Contribution::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"showAddImageToWikipediaInstructions",
|
||||
Contribution::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, contribution)
|
||||
}
|
||||
|
|
@ -193,10 +195,11 @@ class ContributionsListFragmentUnitTests {
|
|||
scenario.onFragment {
|
||||
it.requireView().findViewById<FloatingActionButton>(R.id.fab_plus).hide()
|
||||
}
|
||||
val method: Method = ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"animateFAB",
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"animateFAB",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, true)
|
||||
}
|
||||
|
|
@ -208,10 +211,11 @@ class ContributionsListFragmentUnitTests {
|
|||
scenario.onFragment {
|
||||
it.requireView().findViewById<FloatingActionButton>(R.id.fab_plus).show()
|
||||
}
|
||||
val method: Method = ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"animateFAB",
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"animateFAB",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, true)
|
||||
}
|
||||
|
|
@ -223,10 +227,11 @@ class ContributionsListFragmentUnitTests {
|
|||
scenario.onFragment {
|
||||
it.requireView().findViewById<FloatingActionButton>(R.id.fab_plus).show()
|
||||
}
|
||||
val method: Method = ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"animateFAB",
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"animateFAB",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, false)
|
||||
}
|
||||
|
|
@ -235,9 +240,10 @@ class ContributionsListFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testSetListeners() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"setListeners"
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"setListeners",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -246,9 +252,10 @@ class ContributionsListFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testInitializeAnimations() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"initializeAnimations"
|
||||
)
|
||||
val method: Method =
|
||||
ContributionsListFragment::class.java.getDeclaredMethod(
|
||||
"initializeAnimations",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -261,4 +268,4 @@ class ContributionsListFragmentUnitTests {
|
|||
newConfig.orientation = Configuration.ORIENTATION_LANDSCAPE
|
||||
fragment.onConfigurationChanged(newConfig)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,11 @@ package fr.free.nrw.commons.contributions
|
|||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import com.nhaarman.mockitokotlin2.times
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Scheduler
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
/**
|
||||
|
|
@ -50,8 +43,7 @@ class ContributionsListPresenterTest {
|
|||
contributionBoundaryCallback,
|
||||
remoteDataSource,
|
||||
repository,
|
||||
scheduler
|
||||
);
|
||||
scheduler,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,11 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.loader.content.CursorLoader
|
||||
import androidx.loader.content.Loader
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.repository.UploadRepository
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.schedulers.TestScheduler
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
|
@ -72,6 +69,4 @@ class ContributionsPresenterTest {
|
|||
contributionsPresenter.getContributionsWithTitle("ashish")
|
||||
verify(repository).getContributionWithFileName("ashish")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,11 @@ import io.reactivex.Scheduler
|
|||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.*
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
/**
|
||||
* The unit test class for ContributionsRepositoryTest
|
||||
|
|
@ -38,7 +41,7 @@ class ContributionsRepositoryTest {
|
|||
whenever(localDataSource.getContributions())
|
||||
.thenReturn(createMockDataSourceFactory(listOf(contribution)))
|
||||
val contributionsFactory = contributionsRepository.fetchContributions()
|
||||
verify(localDataSource, times(1)).getContributions();
|
||||
verify(localDataSource, times(1)).getContributions()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -46,8 +49,9 @@ class ContributionsRepositoryTest {
|
|||
val contributions = listOf(mock(Contribution::class.java))
|
||||
whenever(localDataSource.saveContributions(ArgumentMatchers.anyList()))
|
||||
.thenReturn(Single.just(listOf(1L)))
|
||||
val save = contributionsRepository.save(contributions).test().assertValueAt(0) {
|
||||
it.size == 1 && it.get(0) == 1L
|
||||
}
|
||||
val save =
|
||||
contributionsRepository.save(contributions).test().assertValueAt(0) {
|
||||
it.size == 1 && it.get(0) == 1L
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.work.Configuration
|
||||
import androidx.work.testing.WorkManagerTestInitHelper
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.bookmarks.BookmarkFragment
|
||||
import fr.free.nrw.commons.contributions.MainActivity.ActiveFragment
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.explore.ExploreFragment
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.navtab.NavTabLayout
|
||||
|
|
@ -40,12 +39,10 @@ import org.robolectric.fakes.RoboMenuItem
|
|||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class MainActivityUnitTests {
|
||||
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var context: Context
|
||||
private lateinit var menuItem: RoboMenuItem
|
||||
|
|
@ -198,9 +195,10 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetUpPager() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"setUpPager"
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"setUpPager",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -208,9 +206,10 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetUpLoggedOutPager() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"setUpLoggedOutPager"
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"setUpLoggedOutPager",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -218,11 +217,12 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLoadFragmentCaseContributionsFragment() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, contributionsFragment, false)
|
||||
}
|
||||
|
|
@ -232,14 +232,15 @@ class MainActivityUnitTests {
|
|||
fun testLoadFragmentCaseContributionsFragmentCaseTrue() {
|
||||
activeFragment = ActiveFragment.CONTRIBUTIONS
|
||||
activity.activeFragment = activeFragment
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, contributionsFragment, false)
|
||||
verify(contributionsFragment).scrollToTop();
|
||||
verify(contributionsFragment).scrollToTop()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -247,11 +248,12 @@ class MainActivityUnitTests {
|
|||
fun testLoadFragmentCaseNearbyParentFragmentCaseTrue() {
|
||||
activeFragment = ActiveFragment.NEARBY
|
||||
activity.activeFragment = activeFragment
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, nearbyParentFragment, false)
|
||||
}
|
||||
|
|
@ -259,11 +261,12 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLoadFragmentCaseNearbyParentFragment() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, nearbyParentFragment, false)
|
||||
}
|
||||
|
|
@ -273,11 +276,12 @@ class MainActivityUnitTests {
|
|||
fun testLoadFragmentCaseExploreFragmentCaseTrue() {
|
||||
activeFragment = ActiveFragment.EXPLORE
|
||||
activity.activeFragment = activeFragment
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, exploreFragment, false)
|
||||
}
|
||||
|
|
@ -285,11 +289,12 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLoadFragmentCaseExploreFragment() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, exploreFragment, false)
|
||||
}
|
||||
|
|
@ -299,11 +304,12 @@ class MainActivityUnitTests {
|
|||
fun testLoadFragmentCaseBookmarkFragmentCaseTrue() {
|
||||
activeFragment = ActiveFragment.BOOKMARK
|
||||
activity.activeFragment = activeFragment
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bookmarkFrament, false)
|
||||
}
|
||||
|
|
@ -311,11 +317,12 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLoadFragmentCaseBookmarkFragment() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bookmarkFrament, false)
|
||||
}
|
||||
|
|
@ -323,11 +330,12 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLoadFragmentCaseNull() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"loadFragment",
|
||||
Fragment::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, null, true)
|
||||
}
|
||||
|
|
@ -335,12 +343,13 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnActivityResult() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onActivityResult",
|
||||
Int::class.java,
|
||||
Int::class.java,
|
||||
Intent::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onActivityResult",
|
||||
Int::class.java,
|
||||
Int::class.java,
|
||||
Intent::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, 0, 0, null)
|
||||
}
|
||||
|
|
@ -348,9 +357,10 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnResume() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onResume"
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onResume",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -358,9 +368,10 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnDestroy() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy"
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -368,10 +379,11 @@ class MainActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPostCreate() {
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onPostCreate",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onPostCreate",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, null)
|
||||
}
|
||||
|
|
@ -380,10 +392,11 @@ class MainActivityUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testOnSaveInstanceState() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onSaveInstanceState",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onSaveInstanceState",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
|
@ -393,10 +406,11 @@ class MainActivityUnitTests {
|
|||
fun testOnRestoreInstanceStateCaseContributions() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(bundle.getString("activeFragment")).thenReturn(ActiveFragment.CONTRIBUTIONS.name)
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
|
@ -406,10 +420,11 @@ class MainActivityUnitTests {
|
|||
fun testOnRestoreInstanceStateCaseNearby() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(bundle.getString("activeFragment")).thenReturn(ActiveFragment.NEARBY.name)
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
|
@ -419,10 +434,11 @@ class MainActivityUnitTests {
|
|||
fun testOnRestoreInstanceStateCaseExplore() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(bundle.getString("activeFragment")).thenReturn(ActiveFragment.EXPLORE.name)
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
|
@ -432,34 +448,34 @@ class MainActivityUnitTests {
|
|||
fun testOnRestoreInstanceStateCaseBookmark() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(bundle.getString("activeFragment")).thenReturn(ActiveFragment.BOOKMARK.name)
|
||||
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MainActivity::class.java.getDeclaredMethod(
|
||||
"onRestoreInstanceState",
|
||||
Bundle::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, bundle)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSetUpPagerNearBy(){
|
||||
fun testOnSetUpPagerNearBy() {
|
||||
val item = Mockito.mock(MenuItem::class.java)
|
||||
`when`(item.title).thenReturn(activity.getString(R.string.nearby_fragment))
|
||||
activity.navListener.onNavigationItemSelected(item)
|
||||
verify(item, Mockito.times(3)).title
|
||||
verify(applicationKvStore,Mockito.times(1))
|
||||
.putBoolean("last_opened_nearby",true)
|
||||
verify(applicationKvStore, Mockito.times(1))
|
||||
.putBoolean("last_opened_nearby", true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSetUpPagerOtherThanNearBy(){
|
||||
fun testOnSetUpPagerOtherThanNearBy() {
|
||||
val item = Mockito.mock(MenuItem::class.java)
|
||||
`when`(item.title).thenReturn(activity.getString(R.string.bookmarks))
|
||||
activity.navListener.onNavigationItemSelected(item)
|
||||
verify(item, Mockito.times(3)).title
|
||||
verify(applicationKvStore,Mockito.times(1))
|
||||
.putBoolean("last_opened_nearby",false)
|
||||
verify(applicationKvStore, Mockito.times(1))
|
||||
.putBoolean("last_opened_nearby", false)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ import org.junit.jupiter.api.Assertions.assertEquals
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
|
@ -28,7 +30,6 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class CoordinateEditHelperUnitTest {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var helper: CoordinateEditHelper
|
||||
|
||||
|
|
@ -55,8 +56,8 @@ class CoordinateEditHelperUnitTest {
|
|||
pageEditClient.edit(
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyString()
|
||||
)
|
||||
anyString(),
|
||||
),
|
||||
).thenReturn(Observable.just(true))
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ class CoordinateEditHelperUnitTest {
|
|||
helper.makeCoordinatesEdit(context, media, "0.0", "0.0", "0.0F")
|
||||
verify(viewUtilWrapper, times(1)).showShortToast(
|
||||
context,
|
||||
context.getString(R.string.coordinates_edit_helper_make_edit_toast)
|
||||
context.getString(R.string.coordinates_edit_helper_make_edit_toast),
|
||||
)
|
||||
verify(pageEditClient, times(1)).getCurrentWikiText(anyString())
|
||||
verify(pageEditClient, times(1)).edit(anyString(), anyString(), anyString())
|
||||
|
|
@ -81,94 +82,118 @@ class CoordinateEditHelperUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFormattedWikiTextCaseNewLineContainsLocation() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText", String::class.java, String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(
|
||||
method.invoke(
|
||||
helper,
|
||||
"== {{int:filedesc}} == {{user|Test}} == \n{{Location|0.0|0.0|0.0F}}",
|
||||
"{{Location|0.1|0.1|0.1F}}"
|
||||
), "== {{int:filedesc}} == {{user|Test}} == \n" +
|
||||
"{Location|0.1|0.1|0.1F}}\n"
|
||||
"{{Location|0.1|0.1|0.1F}}",
|
||||
),
|
||||
"== {{int:filedesc}} == {{user|Test}} == \n" +
|
||||
"{Location|0.1|0.1|0.1F}}\n",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFormattedWikiTextCaseContainsLocation() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText", String::class.java, String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(
|
||||
method.invoke(
|
||||
helper,
|
||||
"== {{int:filedesc}} == {{Location|0.0|0.0|0.0F}}",
|
||||
"{{Location|0.1|0.1|0.1F}}"
|
||||
), "== {{int:filedesc}} == {{Location|0.1|0.1|0.1F}}"
|
||||
"{{Location|0.1|0.1|0.1F}}",
|
||||
),
|
||||
"== {{int:filedesc}} == {{Location|0.1|0.1|0.1F}}",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFormattedWikiTextCaseDoesContainsLocationHasSubString() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText", String::class.java, String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(
|
||||
method.invoke(
|
||||
helper,
|
||||
"== {{int:filedesc}} == {{user|Test}} == {{int:license-header}} ==",
|
||||
"{{Location|0.1|0.1|0.1F}}"
|
||||
"{{Location|0.1|0.1|0.1F}}",
|
||||
),
|
||||
"== {{int:filedesc}} == {{user|Test}} {Location|0.1|0.1|0.1F}}\n" +
|
||||
"== {{int:license-header}} =="
|
||||
"== {{int:license-header}} ==",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFormattedWikiTextCaseDoesContainsLocationDoesNotHaveSubString() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText", String::class.java, String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(
|
||||
method.invoke(
|
||||
helper,
|
||||
"== {{int:filedesc}} {{int:license-header}} ==",
|
||||
"{{Location|0.1|0.1|0.1F}}"
|
||||
"{{Location|0.1|0.1|0.1F}}",
|
||||
),
|
||||
"== {{int:filedesc}} {{int:license-header}} =={{Location|0.1|0.1|0.1F}}"
|
||||
"== {{int:filedesc}} {{int:license-header}} =={{Location|0.1|0.1|0.1F}}",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFormattedWikiTextCaseDoesNotContainFileDesc() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText", String::class.java, String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"getFormattedWikiText",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(
|
||||
method.invoke(
|
||||
helper,
|
||||
"{{Location|0.0|0.0|0.0F}}",
|
||||
"{{Location|0.1|0.1|0.1F}}"
|
||||
), "== {{int:filedesc}} =={{Location|0.1|0.1|0.1F}}{{Location|0.0|0.0|0.0F}}"
|
||||
"{{Location|0.1|0.1|0.1F}}",
|
||||
),
|
||||
"== {{int:filedesc}} =={{Location|0.1|0.1|0.1F}}{{Location|0.0|0.0|0.0F}}",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowCoordinatesEditNotificationCaseTrue() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"showCoordinatesEditNotification", Context::class.java, Media::class.java,
|
||||
String::class.java, String::class.java, String::class.java, Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"showCoordinatesEditNotification",
|
||||
Context::class.java,
|
||||
Media::class.java,
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(method.invoke(helper, context, media, "0.0", "0.0", "0.0F", true), true)
|
||||
}
|
||||
|
|
@ -176,12 +201,17 @@ class CoordinateEditHelperUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowCoordinatesEditNotificationCaseFalse() {
|
||||
val method: Method = CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"showCoordinatesEditNotification", Context::class.java, Media::class.java,
|
||||
String::class.java, String::class.java, String::class.java, Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
CoordinateEditHelper::class.java.getDeclaredMethod(
|
||||
"showCoordinatesEditNotification",
|
||||
Context::class.java,
|
||||
Media::class.java,
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(method.invoke(helper, context, media, "0.0", "0.0", "0.0F", false), false)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,14 @@ package fr.free.nrw.commons.customselector.helper
|
|||
import android.net.Uri
|
||||
import fr.free.nrw.commons.customselector.model.Folder
|
||||
import fr.free.nrw.commons.customselector.model.Image
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.mockito.Mockito.mock
|
||||
|
||||
/**
|
||||
* Custom Selector Image Helper Test
|
||||
*/
|
||||
internal class ImageHelperTest {
|
||||
|
||||
var uri: Uri = mock(Uri::class.java)
|
||||
private val folderImage1 = Image(1, "image1", uri, "abc/abc", 1, "bucket1")
|
||||
private val folderImage2 = Image(2, "image1", uri, "xyz/xyz", 2, "bucket2")
|
||||
|
|
@ -42,7 +40,7 @@ internal class ImageHelperTest {
|
|||
*/
|
||||
@Test
|
||||
fun getIndex() {
|
||||
assertEquals(1,ImageHelper.getIndex(mockImageList, folderImage2))
|
||||
assertEquals(1, ImageHelper.getIndex(mockImageList, folderImage2))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,4 +50,4 @@ internal class ImageHelperTest {
|
|||
fun getIndexList() {
|
||||
assertEquals(ArrayList<Int>(listOf(0)), ImageHelper.getIndexList(mockImageList, folderImageList2))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.TestUtility.setFinalStatic
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -23,7 +23,6 @@ import org.robolectric.annotation.Config
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@PrepareForTest(OnSwipeTouchListener::class)
|
||||
internal class OnSwipeTouchListenerTest {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var onSwipeTouchListener: OnSwipeTouchListener
|
||||
private lateinit var gesListener: OnSwipeTouchListener.GestureListener
|
||||
|
|
@ -49,8 +48,9 @@ internal class OnSwipeTouchListenerTest {
|
|||
onSwipeTouchListener = OnSwipeTouchListener(context)
|
||||
gesListener = OnSwipeTouchListener(context).GestureListener()
|
||||
setFinalStatic(
|
||||
OnSwipeTouchListener::class.java.getDeclaredField("gestureDetector"),
|
||||
gestureDetector)
|
||||
OnSwipeTouchListener::class.java.getDeclaredField("gestureDetector"),
|
||||
gestureDetector,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -58,13 +58,12 @@ internal class OnSwipeTouchListenerTest {
|
|||
*/
|
||||
@Test
|
||||
fun onTouch() {
|
||||
val motionEvent = MotionEvent.obtain(200, 300, MotionEvent.ACTION_MOVE, 15.0f, 10.0f, 0);
|
||||
val motionEvent = MotionEvent.obtain(200, 300, MotionEvent.ACTION_MOVE, 15.0f, 10.0f, 0)
|
||||
val func = onSwipeTouchListener.javaClass.getDeclaredMethod("onTouch", View::class.java, MotionEvent::class.java)
|
||||
func.isAccessible = true
|
||||
func.invoke(onSwipeTouchListener, view, motionEvent)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test onSwipeRight
|
||||
*/
|
||||
|
|
@ -144,4 +143,4 @@ internal class OnSwipeTouchListenerTest {
|
|||
whenever(motionEvent2.y).thenReturn(1f)
|
||||
gesListener.onFling(motionEvent1, motionEvent2, 0f, 2000f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package fr.free.nrw.commons.customselector.ui.adapter
|
||||
|
||||
import android.content.ContentResolver
|
||||
import fr.free.nrw.commons.R
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
|
|
@ -9,8 +8,8 @@ import android.view.View
|
|||
import android.widget.GridLayout
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.TestUtility.setFinalStatic
|
||||
import fr.free.nrw.commons.customselector.listeners.FolderClickListener
|
||||
import fr.free.nrw.commons.customselector.model.Folder
|
||||
import fr.free.nrw.commons.customselector.model.Image
|
||||
|
|
@ -22,12 +21,9 @@ import org.junit.runner.RunWith
|
|||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
/**
|
||||
* Custom Selector Folder Adapter Test.
|
||||
|
|
@ -35,7 +31,6 @@ import java.lang.reflect.Modifier
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class FolderAdapterTest {
|
||||
|
||||
private var uri: Uri = Mockito.mock(Uri::class.java)
|
||||
private lateinit var activity: CustomSelectorActivity
|
||||
private lateinit var folderAdapter: FolderAdapter
|
||||
|
|
@ -98,4 +93,4 @@ class FolderAdapterTest {
|
|||
fun getItemCount() {
|
||||
assertEquals(0, folderAdapter.itemCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.widget.GridLayout
|
|||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.TestUtility.setFinalStatic
|
||||
import fr.free.nrw.commons.customselector.listeners.ImageSelectListener
|
||||
import fr.free.nrw.commons.customselector.model.Image
|
||||
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorActivity
|
||||
|
|
@ -34,8 +33,7 @@ import org.robolectric.Robolectric
|
|||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
import java.util.*
|
||||
import java.util.TreeMap
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
|
|
@ -47,25 +45,28 @@ import kotlin.collections.ArrayList
|
|||
class ImageAdapterTest {
|
||||
@Mock
|
||||
private lateinit var imageLoader: ImageLoader
|
||||
|
||||
@Mock
|
||||
private lateinit var imageSelectListener: ImageSelectListener
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var mockContentResolver: ContentResolver
|
||||
|
||||
@Mock
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
|
||||
private lateinit var activity: CustomSelectorActivity
|
||||
private lateinit var imageAdapter: ImageAdapter
|
||||
private lateinit var images : ArrayList<Image>
|
||||
private lateinit var images: ArrayList<Image>
|
||||
private lateinit var holder: ImageAdapter.ImageViewHolder
|
||||
private lateinit var selectedImageField: Field
|
||||
private var uri: Uri = Mockito.mock(Uri::class.java)
|
||||
private lateinit var image: Image
|
||||
private val testDispatcher = TestCoroutineDispatcher()
|
||||
|
||||
|
||||
/**
|
||||
* Set up variables.
|
||||
*/
|
||||
|
|
@ -106,7 +107,6 @@ class ImageAdapterTest {
|
|||
*/
|
||||
@Test
|
||||
fun onBindViewHolder() {
|
||||
|
||||
whenever(context.contentResolver).thenReturn(mockContentResolver)
|
||||
whenever(mockContentResolver.getType(uri)).thenReturn("jpg")
|
||||
// Parameters.
|
||||
|
|
@ -125,22 +125,38 @@ class ImageAdapterTest {
|
|||
* Test processThumbnailForActionedImage
|
||||
*/
|
||||
@Test
|
||||
fun processThumbnailForActionedImage() = runBlocking {
|
||||
Whitebox.setInternalState(imageAdapter, "allImages", listOf(image))
|
||||
whenever(imageLoader.nextActionableImage(listOf(image), Dispatchers.IO, Dispatchers.Default,
|
||||
0, emptyList())).thenReturn(0)
|
||||
imageAdapter.processThumbnailForActionedImage(holder, 0, emptyList())
|
||||
}
|
||||
fun processThumbnailForActionedImage() =
|
||||
runBlocking {
|
||||
Whitebox.setInternalState(imageAdapter, "allImages", listOf(image))
|
||||
whenever(
|
||||
imageLoader.nextActionableImage(
|
||||
listOf(image),
|
||||
Dispatchers.IO,
|
||||
Dispatchers.Default,
|
||||
0,
|
||||
emptyList(),
|
||||
),
|
||||
).thenReturn(0)
|
||||
imageAdapter.processThumbnailForActionedImage(holder, 0, emptyList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processThumbnailForActionedImage
|
||||
*/
|
||||
@Test
|
||||
fun `processThumbnailForActionedImage when reached end of the folder`() = runBlocking {
|
||||
whenever(imageLoader.nextActionableImage(ArrayList(), Dispatchers.IO, Dispatchers.Default,
|
||||
0, emptyList())).thenReturn(-1)
|
||||
imageAdapter.processThumbnailForActionedImage(holder, 0, emptyList())
|
||||
}
|
||||
fun `processThumbnailForActionedImage when reached end of the folder`() =
|
||||
runBlocking {
|
||||
whenever(
|
||||
imageLoader.nextActionableImage(
|
||||
ArrayList(),
|
||||
Dispatchers.IO,
|
||||
Dispatchers.Default,
|
||||
0,
|
||||
emptyList(),
|
||||
),
|
||||
).thenReturn(-1)
|
||||
imageAdapter.processThumbnailForActionedImage(holder, 0, emptyList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Test init.
|
||||
|
|
@ -156,7 +172,12 @@ class ImageAdapterTest {
|
|||
@Test
|
||||
fun selectOrRemoveImage() {
|
||||
// Access function
|
||||
val func = imageAdapter.javaClass.getDeclaredMethod("selectOrRemoveImage", ImageAdapter.ImageViewHolder::class.java, Int::class.java)
|
||||
val func =
|
||||
imageAdapter.javaClass.getDeclaredMethod(
|
||||
"selectOrRemoveImage",
|
||||
ImageAdapter.ImageViewHolder::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
func.isAccessible = true
|
||||
|
||||
// Parameters
|
||||
|
|
@ -183,11 +204,12 @@ class ImageAdapterTest {
|
|||
images.add(image)
|
||||
Whitebox.setInternalState(imageAdapter, "images", images)
|
||||
// Access function
|
||||
val func = imageAdapter.javaClass.getDeclaredMethod(
|
||||
"onThumbnailClicked",
|
||||
Int::class.java,
|
||||
ImageAdapter.ImageViewHolder::class.java
|
||||
)
|
||||
val func =
|
||||
imageAdapter.javaClass.getDeclaredMethod(
|
||||
"onThumbnailClicked",
|
||||
Int::class.java,
|
||||
ImageAdapter.ImageViewHolder::class.java,
|
||||
)
|
||||
func.isAccessible = true
|
||||
func.invoke(imageAdapter, 0, holder)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,11 @@ import java.lang.reflect.Method
|
|||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class CustomSelectorActivityTest {
|
||||
|
||||
private lateinit var activity: CustomSelectorActivity
|
||||
|
||||
private lateinit var imageFragment: ImageFragment
|
||||
|
||||
private lateinit var images : java.util.ArrayList<Image>
|
||||
private lateinit var images: java.util.ArrayList<Image>
|
||||
|
||||
private var uri: Uri = Mockito.mock(Uri::class.java)
|
||||
|
||||
|
|
@ -52,18 +51,20 @@ class CustomSelectorActivityTest {
|
|||
MockitoAnnotations.openMocks(this)
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
|
||||
activity = Robolectric.buildActivity(CustomSelectorActivity::class.java)
|
||||
.get()
|
||||
activity =
|
||||
Robolectric
|
||||
.buildActivity(CustomSelectorActivity::class.java)
|
||||
.get()
|
||||
val onCreate = activity.javaClass.getDeclaredMethod("onCreate", Bundle::class.java)
|
||||
onCreate.isAccessible = true
|
||||
onCreate.invoke(activity, null)
|
||||
imageFragment = ImageFragment.newInstance(1,0)
|
||||
imageFragment = ImageFragment.newInstance(1, 0)
|
||||
image = Image(1, "image", uri, "abc/abc", 1, "bucket1")
|
||||
images = ArrayList()
|
||||
|
||||
Whitebox.setInternalState(activity, "imageFragment", imageFragment)
|
||||
Whitebox.setInternalState(imageFragment, "imageAdapter", Mockito.mock(ImageAdapter::class.java))
|
||||
Whitebox.setInternalState(imageFragment,"contributionDao",contributionDao)
|
||||
Whitebox.setInternalState(imageFragment, "contributionDao", contributionDao)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -93,7 +94,7 @@ class CustomSelectorActivityTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnFolderClick() {
|
||||
activity.onFolderClick(1, "test", 0);
|
||||
activity.onFolderClick(1, "test", 0)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,12 +103,13 @@ class CustomSelectorActivityTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnActivityResult() {
|
||||
val func = activity.javaClass.getDeclaredMethod(
|
||||
"onActivityResult",
|
||||
Int::class.java,
|
||||
Int::class.java,
|
||||
Intent::class.java
|
||||
)
|
||||
val func =
|
||||
activity.javaClass.getDeclaredMethod(
|
||||
"onActivityResult",
|
||||
Int::class.java,
|
||||
Int::class.java,
|
||||
Intent::class.java,
|
||||
)
|
||||
func.isAccessible = true
|
||||
func.invoke(activity, 512, -1, Mockito.mock(Intent::class.java))
|
||||
}
|
||||
|
|
@ -118,26 +120,27 @@ class CustomSelectorActivityTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowWelcomeDialog() {
|
||||
val func = activity.javaClass.getDeclaredMethod(
|
||||
"showWelcomeDialog"
|
||||
)
|
||||
val func =
|
||||
activity.javaClass.getDeclaredMethod(
|
||||
"showWelcomeDialog",
|
||||
)
|
||||
func.isAccessible = true
|
||||
func.invoke(activity)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test onLongPress function.
|
||||
*/
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnLongPress() {
|
||||
val func = activity.javaClass.getDeclaredMethod(
|
||||
"onLongPress",
|
||||
Int::class.java,
|
||||
ArrayList::class.java,
|
||||
ArrayList::class.java
|
||||
)
|
||||
val func =
|
||||
activity.javaClass.getDeclaredMethod(
|
||||
"onLongPress",
|
||||
Int::class.java,
|
||||
ArrayList::class.java,
|
||||
ArrayList::class.java,
|
||||
)
|
||||
images.add(image)
|
||||
|
||||
func.isAccessible = true
|
||||
|
|
@ -164,7 +167,7 @@ class CustomSelectorActivityTest {
|
|||
activity.onFolderClick(1, "test", 0)
|
||||
activity.onSelectedImagesChanged(
|
||||
ArrayList(arrayListOf(Image(1, "test", Uri.parse("test"), "test", 1))),
|
||||
1
|
||||
1,
|
||||
)
|
||||
activity.onDone()
|
||||
}
|
||||
|
|
@ -176,14 +179,15 @@ class CustomSelectorActivityTest {
|
|||
@Throws(Exception::class)
|
||||
fun testOnClickNotForUpload() {
|
||||
activity.onFolderClick(1, "test", 0)
|
||||
val method: Method = CustomSelectorActivity::class.java.getDeclaredMethod(
|
||||
"onClickNotForUpload"
|
||||
)
|
||||
val method: Method =
|
||||
CustomSelectorActivity::class.java.getDeclaredMethod(
|
||||
"onClickNotForUpload",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
activity.onSelectedImagesChanged(
|
||||
ArrayList(arrayListOf(Image(1, "test", Uri.parse("test"), "test", 1))),
|
||||
0
|
||||
0,
|
||||
)
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -212,9 +216,10 @@ class CustomSelectorActivityTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnDestroy() {
|
||||
val method: Method = CustomSelectorActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy"
|
||||
)
|
||||
val method: Method =
|
||||
CustomSelectorActivity::class.java.getDeclaredMethod(
|
||||
"onDestroy",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -225,9 +230,10 @@ class CustomSelectorActivityTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testDisplayUploadLimitWarning() {
|
||||
val method: Method = CustomSelectorActivity::class.java.getDeclaredMethod(
|
||||
"displayUploadLimitWarning"
|
||||
)
|
||||
val method: Method =
|
||||
CustomSelectorActivity::class.java.getDeclaredMethod(
|
||||
"displayUploadLimitWarning",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -252,11 +258,19 @@ class CustomSelectorActivityTest {
|
|||
|
||||
// test with list size limit
|
||||
for (i in 1..limit.getInt(activity)) {
|
||||
images.add(Image(i.toLong(), i.toString(), uri,
|
||||
"abc/abc", 1, "bucket1"))
|
||||
images.add(
|
||||
Image(
|
||||
i.toLong(),
|
||||
i.toString(),
|
||||
uri,
|
||||
"abc/abc",
|
||||
1,
|
||||
"bucket1",
|
||||
),
|
||||
)
|
||||
}
|
||||
activity.onFolderClick(1, "test", 0)
|
||||
activity.onSelectedImagesChanged(images,0)
|
||||
activity.onSelectedImagesChanged(images, 0)
|
||||
assertEquals(false, overLimit.getBoolean(activity))
|
||||
assertEquals(0, exceededBy.getInt(activity))
|
||||
activity.onSelectedImagesChanged(images, 1)
|
||||
|
|
@ -265,20 +279,20 @@ class CustomSelectorActivityTest {
|
|||
|
||||
// test with list size limit+1
|
||||
images.add(image)
|
||||
activity.onSelectedImagesChanged(images,0)
|
||||
activity.onSelectedImagesChanged(images, 0)
|
||||
assertEquals(true, overLimit.getBoolean(activity))
|
||||
assertEquals(1, exceededBy.getInt(activity))
|
||||
activity.onSelectedImagesChanged(images,1)
|
||||
activity.onSelectedImagesChanged(images, 1)
|
||||
assertEquals(true, overLimit.getBoolean(activity))
|
||||
assertEquals(1, exceededBy.getInt(activity))
|
||||
|
||||
//test with list size 1
|
||||
// test with list size 1
|
||||
images.clear()
|
||||
images.add(image)
|
||||
activity.onSelectedImagesChanged(images,0)
|
||||
activity.onSelectedImagesChanged(images, 0)
|
||||
assertEquals(false, overLimit.getBoolean(activity))
|
||||
assertEquals(0, exceededBy.getInt(activity))
|
||||
activity.onSelectedImagesChanged(images,1)
|
||||
activity.onSelectedImagesChanged(images, 1)
|
||||
assertEquals(false, overLimit.getBoolean(activity))
|
||||
assertEquals(0, exceededBy.getInt(activity))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import org.mockito.MockitoAnnotations
|
|||
* Custom Selector View Model test.
|
||||
*/
|
||||
class CustomSelectorViewModelTest {
|
||||
|
||||
private lateinit var viewModel: CustomSelectorViewModel
|
||||
|
||||
@Mock
|
||||
|
|
@ -23,19 +22,18 @@ class CustomSelectorViewModelTest {
|
|||
* Set up the test.
|
||||
*/
|
||||
@Before
|
||||
fun setUp(){
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
viewModel = CustomSelectorViewModel(context, imageFileLoader);
|
||||
viewModel = CustomSelectorViewModel(context, imageFileLoader)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test onCleared();
|
||||
*/
|
||||
@Test
|
||||
fun testOnCleared(){
|
||||
fun testOnCleared() {
|
||||
val func = viewModel.javaClass.getDeclaredMethod("onCleared")
|
||||
func.isAccessible = true
|
||||
func.invoke(viewModel);
|
||||
func.invoke(viewModel)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,14 +40,13 @@ import java.lang.reflect.Field
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class FolderFragmentTest {
|
||||
|
||||
private lateinit var fragment: FolderFragment
|
||||
private lateinit var view: View
|
||||
private lateinit var selectorRV : RecyclerView
|
||||
private lateinit var loader : ProgressBar
|
||||
private lateinit var selectorRV: RecyclerView
|
||||
private lateinit var loader: ProgressBar
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
private lateinit var context: Context
|
||||
private lateinit var viewModelField:Field
|
||||
private lateinit var viewModelField: Field
|
||||
|
||||
@Mock
|
||||
private lateinit var adapter: FolderAdapter
|
||||
|
|
@ -80,7 +79,7 @@ class FolderFragmentTest {
|
|||
loader = view.findViewById(R.id.loader)
|
||||
|
||||
Whitebox.setInternalState(fragment, "folderAdapter", adapter)
|
||||
Whitebox.setInternalState(fragment, "selectorRV", selectorRV )
|
||||
Whitebox.setInternalState(fragment, "selectorRV", selectorRV)
|
||||
Whitebox.setInternalState(fragment, "loader", loader)
|
||||
|
||||
viewModelField = fragment.javaClass.getDeclaredField("viewModel")
|
||||
|
|
@ -137,5 +136,4 @@ class FolderFragmentTest {
|
|||
func.isAccessible = true
|
||||
func.invoke(fragment)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,14 +18,11 @@ import org.junit.runner.RunWith
|
|||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import org.robolectric.fakes.RoboCursor
|
||||
import java.io.File
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
|
|
@ -35,12 +32,11 @@ import kotlin.coroutines.CoroutineContext
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ImageFileLoaderTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var mockContentResolver: ContentResolver
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context;
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var imageLoaderListener: ImageLoaderListener
|
||||
|
|
@ -62,17 +58,19 @@ class ImageFileLoaderTest {
|
|||
coroutineContext = Dispatchers.Main
|
||||
imageCursor = RoboCursor()
|
||||
imageFileLoader = ImageFileLoader(context)
|
||||
projection = listOf(
|
||||
MediaStore.Images.Media._ID,
|
||||
MediaStore.Images.Media.DISPLAY_NAME,
|
||||
MediaStore.Images.Media.DATA,
|
||||
MediaStore.Images.Media.BUCKET_ID,
|
||||
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
|
||||
MediaStore.Images.Media.DATE_ADDED
|
||||
)
|
||||
projection =
|
||||
listOf(
|
||||
MediaStore.Images.Media._ID,
|
||||
MediaStore.Images.Media.DISPLAY_NAME,
|
||||
MediaStore.Images.Media.DATA,
|
||||
MediaStore.Images.Media.BUCKET_ID,
|
||||
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
|
||||
MediaStore.Images.Media.DATE_ADDED,
|
||||
)
|
||||
setFinalStatic(
|
||||
ImageFileLoader::class.java.getDeclaredField("coroutineContext"),
|
||||
coroutineContext)
|
||||
ImageFileLoader::class.java.getDeclaredField("coroutineContext"),
|
||||
coroutineContext,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -88,10 +86,11 @@ class ImageFileLoaderTest {
|
|||
*/
|
||||
@Test
|
||||
fun testGetImages() {
|
||||
val func = imageFileLoader.javaClass.getDeclaredMethod(
|
||||
"getImages",
|
||||
ImageLoaderListener::class.java
|
||||
)
|
||||
val func =
|
||||
imageFileLoader.javaClass.getDeclaredMethod(
|
||||
"getImages",
|
||||
ImageLoaderListener::class.java,
|
||||
)
|
||||
func.isAccessible = true
|
||||
|
||||
val image1 = arrayOf(1, "imageLoaderTestFile", "src/test/resources/imageLoaderTestFile", 1, "downloads")
|
||||
|
|
@ -99,31 +98,32 @@ class ImageFileLoaderTest {
|
|||
File("src/test/resources/imageLoaderTestFile").createNewFile()
|
||||
|
||||
imageCursor.setColumnNames(projection)
|
||||
imageCursor.setResults(arrayOf(image1, image2));
|
||||
imageCursor.setResults(arrayOf(image1, image2))
|
||||
|
||||
val contentResolver: ContentResolver = mock {
|
||||
on {
|
||||
query(
|
||||
same(MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
anyOrNull()
|
||||
)
|
||||
} doReturn imageCursor;
|
||||
}
|
||||
val contentResolver: ContentResolver =
|
||||
mock {
|
||||
on {
|
||||
query(
|
||||
same(MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
anyOrNull(),
|
||||
)
|
||||
} doReturn imageCursor
|
||||
}
|
||||
|
||||
// test null cursor.
|
||||
`when`(
|
||||
context.contentResolver
|
||||
context.contentResolver,
|
||||
).thenReturn(mockContentResolver)
|
||||
func.invoke(imageFileLoader, imageLoaderListener);
|
||||
func.invoke(imageFileLoader, imageLoaderListener)
|
||||
|
||||
// test demo cursor.
|
||||
`when`(
|
||||
context.contentResolver
|
||||
context.contentResolver,
|
||||
).thenReturn(contentResolver)
|
||||
func.invoke(imageFileLoader, imageLoaderListener);
|
||||
func.invoke(imageFileLoader, imageLoaderListener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,11 @@ import java.lang.reflect.Field
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ImageFragmentTest {
|
||||
|
||||
private lateinit var fragment: ImageFragment
|
||||
private lateinit var activity: CustomSelectorActivity
|
||||
private lateinit var view: View
|
||||
private lateinit var selectorRV : RecyclerView
|
||||
private lateinit var loader : ProgressBar
|
||||
private lateinit var selectorRV: RecyclerView
|
||||
private lateinit var loader: ProgressBar
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
private lateinit var context: Context
|
||||
private lateinit var viewModelField: Field
|
||||
|
|
@ -75,7 +74,7 @@ class ImageFragmentTest {
|
|||
* Setup the image fragment.
|
||||
*/
|
||||
@Before
|
||||
fun setUp(){
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
|
|
@ -83,7 +82,7 @@ class ImageFragmentTest {
|
|||
Fresco.initialize(context)
|
||||
activity = Robolectric.buildActivity(CustomSelectorActivity::class.java).create().get()
|
||||
|
||||
fragment = ImageFragment.newInstance(1,0)
|
||||
fragment = ImageFragment.newInstance(1, 0)
|
||||
val fragmentManager: FragmentManager = activity.supportFragmentManager
|
||||
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.add(fragment, null)
|
||||
|
|
@ -95,9 +94,9 @@ class ImageFragmentTest {
|
|||
loader = view.findViewById(R.id.loader)
|
||||
|
||||
Whitebox.setInternalState(fragment, "imageAdapter", adapter)
|
||||
Whitebox.setInternalState(fragment, "selectorRV", selectorRV )
|
||||
Whitebox.setInternalState(fragment, "selectorRV", selectorRV)
|
||||
Whitebox.setInternalState(fragment, "loader", loader)
|
||||
Whitebox.setInternalState(fragment, "filteredImages", arrayListOf(image,image))
|
||||
Whitebox.setInternalState(fragment, "filteredImages", arrayListOf(image, image))
|
||||
Whitebox.setInternalState(fragment, "contributionDao", contributionDao)
|
||||
|
||||
viewModelField = fragment.javaClass.getDeclaredField("viewModel")
|
||||
|
|
@ -109,9 +108,9 @@ class ImageFragmentTest {
|
|||
*/
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreate(){
|
||||
fun testOnCreate() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onCreate(savedInstanceState);
|
||||
fragment.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -129,11 +128,11 @@ class ImageFragmentTest {
|
|||
* Test handleResult.
|
||||
*/
|
||||
@Test
|
||||
fun testHandleResult(){
|
||||
fun testHandleResult() {
|
||||
val func = fragment.javaClass.getDeclaredMethod("handleResult", Result::class.java)
|
||||
func.isAccessible = true
|
||||
func.invoke(fragment, Result(CallbackStatus.SUCCESS, arrayListOf()))
|
||||
func.invoke(fragment, Result(CallbackStatus.SUCCESS, arrayListOf(image,image)))
|
||||
func.invoke(fragment, Result(CallbackStatus.SUCCESS, arrayListOf(image, image)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,5 +183,4 @@ class ImageFragmentTest {
|
|||
func.isAccessible = true
|
||||
func.invoke(fragment)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import android.content.ContentResolver
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.TestUtility.setFinalStatic
|
||||
import fr.free.nrw.commons.customselector.database.NotForUploadStatusDao
|
||||
|
|
@ -18,29 +19,32 @@ import fr.free.nrw.commons.media.MediaClient
|
|||
import fr.free.nrw.commons.upload.FileProcessor
|
||||
import fr.free.nrw.commons.upload.FileUtilsWrapper
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.*
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.*
|
||||
import org.mockito.BDDMockito
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockedStatic
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.mockStatic
|
||||
import org.powermock.api.mockito.PowerMockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
import java.util.*
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
/**
|
||||
|
|
@ -51,9 +55,8 @@ import kotlin.collections.HashMap
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@ExperimentalCoroutinesApi
|
||||
class ImageLoaderTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var uri:Uri
|
||||
private lateinit var uri: Uri
|
||||
|
||||
@Mock
|
||||
private lateinit var mediaClient: MediaClient
|
||||
|
|
@ -91,9 +94,9 @@ class ImageLoaderTest {
|
|||
@ExperimentalCoroutinesApi
|
||||
private val testDispacher = TestCoroutineDispatcher()
|
||||
|
||||
private lateinit var imageLoader: ImageLoader;
|
||||
private lateinit var imageLoader: ImageLoader
|
||||
private var mapImageSHA1: HashMap<Uri, String> = HashMap()
|
||||
private var mapHolderImage : HashMap<ImageAdapter.ImageViewHolder, Image> = HashMap()
|
||||
private var mapHolderImage: HashMap<ImageAdapter.ImageViewHolder, Image> = HashMap()
|
||||
private var mapResult: HashMap<String, ImageLoader.Result> = HashMap()
|
||||
private var mapModifiedImageSHA1: HashMap<Image, String> = HashMap()
|
||||
private lateinit var image: Image
|
||||
|
|
@ -111,24 +114,32 @@ class ImageLoaderTest {
|
|||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
imageLoader =
|
||||
ImageLoader(mediaClient, fileProcessor, fileUtilsWrapper, uploadedStatusDao,
|
||||
notForUploadStatusDao, context)
|
||||
uploadedStatus= UploadedStatus(
|
||||
"testSha1",
|
||||
"testSha1",
|
||||
false,
|
||||
false,
|
||||
Calendar.getInstance().time
|
||||
)
|
||||
ImageLoader(
|
||||
mediaClient,
|
||||
fileProcessor,
|
||||
fileUtilsWrapper,
|
||||
uploadedStatusDao,
|
||||
notForUploadStatusDao,
|
||||
context,
|
||||
)
|
||||
uploadedStatus =
|
||||
UploadedStatus(
|
||||
"testSha1",
|
||||
"testSha1",
|
||||
false,
|
||||
false,
|
||||
Calendar.getInstance().time,
|
||||
)
|
||||
image = Image(1, "test", uri, "test", 0, "test")
|
||||
|
||||
Whitebox.setInternalState(imageLoader, "mapImageSHA1", mapImageSHA1);
|
||||
Whitebox.setInternalState(imageLoader, "mapHolderImage", mapHolderImage);
|
||||
Whitebox.setInternalState(imageLoader, "mapModifiedImageSHA1", mapModifiedImageSHA1);
|
||||
Whitebox.setInternalState(imageLoader, "mapResult", mapResult);
|
||||
Whitebox.setInternalState(imageLoader, "mapImageSHA1", mapImageSHA1)
|
||||
Whitebox.setInternalState(imageLoader, "mapHolderImage", mapHolderImage)
|
||||
Whitebox.setInternalState(imageLoader, "mapModifiedImageSHA1", mapModifiedImageSHA1)
|
||||
Whitebox.setInternalState(imageLoader, "mapResult", mapResult)
|
||||
setFinalStatic(
|
||||
ImageLoader::class.java.getDeclaredField("context"),
|
||||
context)
|
||||
ImageLoader::class.java.getDeclaredField("context"),
|
||||
context,
|
||||
)
|
||||
whenever(contentResolver.openInputStream(uri)).thenReturn(inputStream)
|
||||
whenever(context.contentResolver).thenReturn(contentResolver)
|
||||
whenever(fileUtilsWrapper.getSHA1(inputStream)).thenReturn("testSha1")
|
||||
|
|
@ -143,110 +154,119 @@ class ImageLoaderTest {
|
|||
fun tearDown() {
|
||||
Dispatchers.resetMain()
|
||||
testDispacher.cleanupTestCoroutines()
|
||||
mockedPickedFiles.close();
|
||||
mockedPickedFiles.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* Test queryAndSetView with upload Status as null.
|
||||
*/
|
||||
@Test
|
||||
fun testQueryAndSetViewUploadedStatusNull() = testDispacher.runBlockingTest {
|
||||
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(null)
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
mapModifiedImageSHA1[image] = "testSha1"
|
||||
mapImageSHA1[uri] = "testSha1"
|
||||
whenever(context.getSharedPreferences("custom_selector", 0))
|
||||
.thenReturn(Mockito.mock(SharedPreferences::class.java))
|
||||
fun testQueryAndSetViewUploadedStatusNull() =
|
||||
testDispacher.runBlockingTest {
|
||||
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(null)
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
mapModifiedImageSHA1[image] = "testSha1"
|
||||
mapImageSHA1[uri] = "testSha1"
|
||||
whenever(context.getSharedPreferences("custom_selector", 0))
|
||||
.thenReturn(Mockito.mock(SharedPreferences::class.java))
|
||||
|
||||
mapResult["testSha1"] = ImageLoader.Result.TRUE
|
||||
imageLoader.queryAndSetView(holder, image, testDispacher, testDispacher, ArrayList())
|
||||
mapResult["testSha1"] = ImageLoader.Result.TRUE
|
||||
imageLoader.queryAndSetView(holder, image, testDispacher, testDispacher, ArrayList())
|
||||
|
||||
mapResult["testSha1"] = ImageLoader.Result.FALSE
|
||||
imageLoader.queryAndSetView(holder, image, testDispacher, testDispacher, ArrayList())
|
||||
}
|
||||
mapResult["testSha1"] = ImageLoader.Result.FALSE
|
||||
imageLoader.queryAndSetView(holder, image, testDispacher, testDispacher, ArrayList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Test queryAndSetView with upload Status not null (ie retrieved from table)
|
||||
*/
|
||||
@Test
|
||||
fun testQueryAndSetViewUploadedStatusNotNull() = testDispacher.runBlockingTest {
|
||||
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(uploadedStatus)
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
whenever(context.getSharedPreferences("custom_selector", 0))
|
||||
.thenReturn(Mockito.mock(SharedPreferences::class.java))
|
||||
imageLoader.queryAndSetView(holder, image, testDispacher, testDispacher, ArrayList())
|
||||
}
|
||||
fun testQueryAndSetViewUploadedStatusNotNull() =
|
||||
testDispacher.runBlockingTest {
|
||||
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(uploadedStatus)
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
whenever(context.getSharedPreferences("custom_selector", 0))
|
||||
.thenReturn(Mockito.mock(SharedPreferences::class.java))
|
||||
imageLoader.queryAndSetView(holder, image, testDispacher, testDispacher, ArrayList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Test nextActionableImage
|
||||
*/
|
||||
@Test
|
||||
fun testNextActionableImage() = testDispacher.runBlockingTest {
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(0)
|
||||
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(0)
|
||||
fun testNextActionableImage() =
|
||||
testDispacher.runBlockingTest {
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
|
||||
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(0)
|
||||
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(0)
|
||||
// mockStatic(PickedFiles::class.java)
|
||||
BDDMockito.given(PickedFiles.pickedExistingPicture(context, image.uri))
|
||||
.willReturn(UploadableFile(uri, File("ABC")))
|
||||
whenever(fileUtilsWrapper.getFileInputStream("ABC")).thenReturn(inputStream)
|
||||
whenever(fileUtilsWrapper.getSHA1(inputStream)).thenReturn("testSha1")
|
||||
whenever(PickedFiles.pickedExistingPicture(context, Uri.parse("test"))).thenReturn(
|
||||
uploadableFile
|
||||
)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
BDDMockito
|
||||
.given(PickedFiles.pickedExistingPicture(context, image.uri))
|
||||
.willReturn(UploadableFile(uri, File("ABC")))
|
||||
whenever(fileUtilsWrapper.getFileInputStream("ABC")).thenReturn(inputStream)
|
||||
whenever(fileUtilsWrapper.getSHA1(inputStream)).thenReturn("testSha1")
|
||||
whenever(PickedFiles.pickedExistingPicture(context, Uri.parse("test"))).thenReturn(
|
||||
uploadableFile,
|
||||
)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(1)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
whenever(notForUploadStatusDao.find(any())).thenReturn(1)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
|
||||
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(2)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(2)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
|
||||
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(2)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
}
|
||||
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(2)
|
||||
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getSha1
|
||||
*/
|
||||
@Test
|
||||
@ExperimentalCoroutinesApi
|
||||
fun testGetSha1() = testDispacher.runBlockingTest {
|
||||
fun testGetSha1() =
|
||||
testDispacher.runBlockingTest {
|
||||
BDDMockito
|
||||
.given(PickedFiles.pickedExistingPicture(context, image.uri))
|
||||
.willReturn(UploadableFile(uri, File("ABC")))
|
||||
|
||||
BDDMockito.given(PickedFiles.pickedExistingPicture(context, image.uri))
|
||||
.willReturn(UploadableFile(uri, File("ABC")))
|
||||
whenever(fileUtilsWrapper.getFileInputStream("ABC")).thenReturn(inputStream)
|
||||
whenever(fileUtilsWrapper.getSHA1(inputStream)).thenReturn("testSha1")
|
||||
|
||||
Assert.assertEquals("testSha1", imageLoader.getSHA1(image, testDispacher))
|
||||
whenever(PickedFiles.pickedExistingPicture(context, Uri.parse("test"))).thenReturn(
|
||||
uploadableFile,
|
||||
)
|
||||
|
||||
whenever(fileUtilsWrapper.getFileInputStream("ABC")).thenReturn(inputStream)
|
||||
whenever(fileUtilsWrapper.getSHA1(inputStream)).thenReturn("testSha1")
|
||||
|
||||
Assert.assertEquals("testSha1", imageLoader.getSHA1(image, testDispacher));
|
||||
whenever(PickedFiles.pickedExistingPicture(context, Uri.parse("test"))).thenReturn(
|
||||
uploadableFile
|
||||
)
|
||||
|
||||
mapModifiedImageSHA1[image] = "testSha2"
|
||||
Assert.assertEquals("testSha2", imageLoader.getSHA1(image, testDispacher));
|
||||
}
|
||||
mapModifiedImageSHA1[image] = "testSha2"
|
||||
Assert.assertEquals("testSha2", imageLoader.getSHA1(image, testDispacher))
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getResultFromUploadedStatus.
|
||||
*/
|
||||
@Test
|
||||
fun testGetResultFromUploadedStatus() {
|
||||
val func = imageLoader.javaClass.getDeclaredMethod(
|
||||
"getResultFromUploadedStatus",
|
||||
UploadedStatus::class.java)
|
||||
val func =
|
||||
imageLoader.javaClass.getDeclaredMethod(
|
||||
"getResultFromUploadedStatus",
|
||||
UploadedStatus::class.java,
|
||||
)
|
||||
func.isAccessible = true
|
||||
|
||||
// test Result.INVALID
|
||||
uploadedStatus.lastUpdated = Date(0);
|
||||
Assert.assertEquals(ImageLoader.Result.INVALID,
|
||||
imageLoader.getResultFromUploadedStatus(uploadedStatus))
|
||||
uploadedStatus.lastUpdated = Date(0)
|
||||
Assert.assertEquals(
|
||||
ImageLoader.Result.INVALID,
|
||||
imageLoader.getResultFromUploadedStatus(uploadedStatus),
|
||||
)
|
||||
|
||||
// test Result.TRUE
|
||||
uploadedStatus.imageResult = true;
|
||||
Assert.assertEquals(ImageLoader.Result.TRUE,
|
||||
imageLoader.getResultFromUploadedStatus(uploadedStatus))
|
||||
uploadedStatus.imageResult = true
|
||||
Assert.assertEquals(
|
||||
ImageLoader.Result.TRUE,
|
||||
imageLoader.getResultFromUploadedStatus(uploadedStatus),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,24 +6,19 @@ import com.nhaarman.mockitokotlin2.eq
|
|||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.FakeContextWrapper
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.actions.PageEditClient
|
||||
import fr.free.nrw.commons.contributions.ContributionsListFragment
|
||||
import fr.free.nrw.commons.review.ReviewController
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runner.Runner
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
|
|
@ -37,18 +32,17 @@ import org.robolectric.annotation.LooperMode
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class DeleteHelperTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var callback: ReviewController.ReviewCallback
|
||||
|
||||
@Mock
|
||||
internal lateinit var pageEditClient: PageEditClient
|
||||
internal lateinit var pageEditClient: PageEditClient
|
||||
|
||||
@Mock
|
||||
internal lateinit var context: Context
|
||||
internal lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
internal lateinit var media: Media
|
||||
internal lateinit var media: Media
|
||||
|
||||
lateinit var deleteHelper: DeleteHelper
|
||||
|
||||
|
|
@ -67,11 +61,11 @@ class DeleteHelperTest {
|
|||
@Test
|
||||
fun makeDeletion() {
|
||||
whenever(pageEditClient.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(pageEditClient.appendEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(pageEditClient.edit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
|
||||
whenever(media.displayTitle).thenReturn("Test file")
|
||||
|
||||
|
|
@ -90,11 +84,11 @@ class DeleteHelperTest {
|
|||
@Test(expected = RuntimeException::class)
|
||||
fun makeDeletionForPrependEditFailure() {
|
||||
whenever(pageEditClient.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(false))
|
||||
.thenReturn(Observable.just(false))
|
||||
whenever(pageEditClient.appendEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(pageEditClient.edit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(media.displayTitle).thenReturn("Test file")
|
||||
whenever(media.filename).thenReturn("Test file.jpg")
|
||||
whenever(media.author).thenReturn("Creator (page does not exist)")
|
||||
|
|
@ -105,11 +99,11 @@ class DeleteHelperTest {
|
|||
@Test(expected = RuntimeException::class)
|
||||
fun makeDeletionForEditFailure() {
|
||||
whenever(pageEditClient.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(pageEditClient.appendEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(pageEditClient.edit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(false))
|
||||
.thenReturn(Observable.just(false))
|
||||
whenever(media.displayTitle).thenReturn("Test file")
|
||||
whenever(media.filename).thenReturn("Test file.jpg")
|
||||
whenever(media.author).thenReturn("Creator (page does not exist)")
|
||||
|
|
@ -120,11 +114,11 @@ class DeleteHelperTest {
|
|||
@Test(expected = RuntimeException::class)
|
||||
fun makeDeletionForAppendEditFailure() {
|
||||
whenever(pageEditClient.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(pageEditClient.appendEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(false))
|
||||
.thenReturn(Observable.just(false))
|
||||
whenever(pageEditClient.edit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(true))
|
||||
.thenReturn(Observable.just(true))
|
||||
whenever(media.displayTitle).thenReturn("Test file")
|
||||
whenever(media.filename).thenReturn("Test file.jpg")
|
||||
whenever(media.author).thenReturn("Creator (page does not exist)")
|
||||
|
|
@ -141,21 +135,21 @@ class DeleteHelperTest {
|
|||
@Test
|
||||
fun askReasonAndExecuteCopyrightViolationTest() {
|
||||
val mContext = RuntimeEnvironment.getApplication().applicationContext
|
||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun alertDialogPositiveButtonDisableTest() {
|
||||
val mContext = RuntimeEnvironment.getApplication().applicationContext
|
||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback)
|
||||
assertEquals(false, deleteHelper.dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
fun alertDialogPositiveButtonEnableTest() {
|
||||
val mContext = RuntimeEnvironment.getApplication().applicationContext
|
||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
||||
deleteHelper.listener.onClick(deleteHelper.dialog,1,true);
|
||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback)
|
||||
deleteHelper.listener.onClick(deleteHelper.dialog, 1, true)
|
||||
assertEquals(true, deleteHelper.dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,19 +17,25 @@ import org.junit.Test
|
|||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.anyString
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.util.*
|
||||
|
||||
import java.util.Date
|
||||
|
||||
class ReasonBuilderTest {
|
||||
|
||||
@Mock
|
||||
internal var sessionManager: SessionManager? = null
|
||||
|
||||
@Mock
|
||||
internal var okHttpJsonApiClient: OkHttpJsonApiClient? = null
|
||||
|
||||
@Mock
|
||||
internal var context: Context? = null
|
||||
|
||||
@Mock
|
||||
internal var viewUtilWrapper: ViewUtilWrapper? = null
|
||||
|
||||
|
|
@ -56,13 +62,13 @@ class ReasonBuilderTest {
|
|||
`when`(sessionManager?.userName).thenReturn("Testuser")
|
||||
`when`(sessionManager?.doesAccountExist()).thenReturn(true)
|
||||
`when`(okHttpJsonApiClient!!.getAchievements(anyString()))
|
||||
.thenReturn(Single.just(mock(FeedbackResponse::class.java)))
|
||||
.thenReturn(Single.just(mock(FeedbackResponse::class.java)))
|
||||
`when`(okHttpJsonApiClient!!.getLeaderboard(anyString(), anyString(), anyString(), anyString(), anyString()))
|
||||
.thenReturn(Observable.just(mock(LeaderboardResponse::class.java)))
|
||||
`when`(okHttpJsonApiClient!!.setAvatar(anyString(), anyString()))
|
||||
.thenReturn(Single.just(mock(UpdateAvatarResponse::class.java)))
|
||||
|
||||
val media = media(filename="test_file", dateUploaded = Date())
|
||||
val media = media(filename = "test_file", dateUploaded = Date())
|
||||
|
||||
reasonBuilder!!.getReason(media, "test")
|
||||
verify(sessionManager, times(0))!!.forceLogin(any(Context::class.java))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.os.Looper
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
|
|
@ -26,7 +25,6 @@ import org.junit.Before
|
|||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
|
|
@ -39,13 +37,12 @@ import org.robolectric.annotation.LooperMode
|
|||
import org.robolectric.shadows.ShadowAlertDialog
|
||||
import org.robolectric.shadows.ShadowProgressDialog
|
||||
import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class DescriptionEditActivityUnitTest {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var activity: Activity
|
||||
private lateinit var uploadMediaDetails: ArrayList<UploadMediaDetail>
|
||||
|
|
@ -64,10 +61,19 @@ class DescriptionEditActivityUnitTest {
|
|||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = RuntimeEnvironment.getApplication().applicationContext
|
||||
uploadMediaDetails = mutableListOf(UploadMediaDetail("en", "desc"))
|
||||
uploadMediaDetails =
|
||||
mutableListOf(UploadMediaDetail("en", "desc"))
|
||||
as ArrayList<UploadMediaDetail>
|
||||
media = Media("filename", "creator", "url", "thumburl",
|
||||
"localpath", Date(197000), "extmetadata")
|
||||
media =
|
||||
Media(
|
||||
"filename",
|
||||
"creator",
|
||||
"url",
|
||||
"thumburl",
|
||||
"localpath",
|
||||
Date(197000),
|
||||
"extmetadata",
|
||||
)
|
||||
|
||||
val intent = Intent().putExtra("title", "read")
|
||||
val bundle = Bundle()
|
||||
|
|
@ -87,7 +93,7 @@ class DescriptionEditActivityUnitTest {
|
|||
Whitebox.setInternalState(activity, "binding", binding)
|
||||
Whitebox.setInternalState(activity, "savedLanguageValue", "bn")
|
||||
Whitebox.setInternalState(activity, "media", media)
|
||||
Whitebox.setInternalState(activity,"descriptionAndCaptions",uploadMediaDetails)
|
||||
Whitebox.setInternalState(activity, "descriptionAndCaptions", uploadMediaDetails)
|
||||
`when`(uploadMediaDetailAdapter.items).thenReturn(uploadMediaDetails)
|
||||
}
|
||||
|
||||
|
|
@ -101,9 +107,10 @@ class DescriptionEditActivityUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testShowLoggingProgressBar() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"showLoggingProgressBar"
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"showLoggingProgressBar",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
val dialog: ProgressDialog = ShadowProgressDialog.getLatestDialog() as ProgressDialog
|
||||
|
|
@ -114,9 +121,11 @@ class DescriptionEditActivityUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testUpdateDescription() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"updateDescription", List::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"updateDescription",
|
||||
List::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, mutableListOf(UploadMediaDetail("en", "desc")))
|
||||
assertEquals(activity.isFinishing, true)
|
||||
|
|
@ -126,9 +135,11 @@ class DescriptionEditActivityUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testOnSubmitButtonClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"onSubmitButtonClicked", View::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"onSubmitButtonClicked",
|
||||
View::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, null)
|
||||
assertEquals(activity.isFinishing, true)
|
||||
|
|
@ -138,9 +149,11 @@ class DescriptionEditActivityUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testOnBackButtonClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"onBackButtonClicked", View::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"onBackButtonClicked",
|
||||
View::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, null)
|
||||
assertEquals(activity.isFinishing, true)
|
||||
|
|
@ -150,9 +163,11 @@ class DescriptionEditActivityUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testOnPrimaryCaptionTextChange() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"onPrimaryCaptionTextChange", Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"onPrimaryCaptionTextChange",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, true)
|
||||
}
|
||||
|
|
@ -161,17 +176,19 @@ class DescriptionEditActivityUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testShowInfoAlert() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"showInfoAlert", Int::class.java, Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditActivity::class.java.getDeclaredMethod(
|
||||
"showInfoAlert",
|
||||
Int::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(
|
||||
activity,
|
||||
android.R.string.ok,
|
||||
android.R.string.ok
|
||||
android.R.string.ok,
|
||||
)
|
||||
val dialog: AlertDialog = ShadowAlertDialog.getLatestDialog() as AlertDialog
|
||||
assertEquals(dialog.isShowing, true)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,13 @@ import org.junit.Test
|
|||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class DescriptionEditHelperUnitTest {
|
||||
|
||||
private lateinit var helper: DescriptionEditHelper
|
||||
|
||||
@Mock
|
||||
|
|
@ -43,8 +44,8 @@ class DescriptionEditHelperUnitTest {
|
|||
pageEditClient.edit(
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyString()
|
||||
)
|
||||
anyString(),
|
||||
),
|
||||
).thenReturn(Observable.just(true))
|
||||
helper.addDescription(context, media, "test")
|
||||
verify(pageEditClient, times(1)).edit(anyString(), anyString(), anyString())
|
||||
|
|
@ -58,56 +59,67 @@ class DescriptionEditHelperUnitTest {
|
|||
anyString(),
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyString()
|
||||
)
|
||||
anyString(),
|
||||
),
|
||||
).thenReturn(Observable.just(0))
|
||||
helper.addCaption(context, media, "test", "test")
|
||||
verify(pageEditClient, times(1)).setCaptions(
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyString()
|
||||
anyString(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShowCaptionEditNotificationCaseFalse() {
|
||||
val method: Method = DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showCaptionEditNotification", Context::class.java, Media::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showCaptionEditNotification",
|
||||
Context::class.java,
|
||||
Media::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(method.invoke(helper, context, media, 0), false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShowCaptionEditNotificationCaseTrue() {
|
||||
val method: Method = DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showCaptionEditNotification", Context::class.java, Media::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showCaptionEditNotification",
|
||||
Context::class.java,
|
||||
Media::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(method.invoke(helper, context, media, 1), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShowDescriptionEditNotificationCaseFalse() {
|
||||
val method: Method = DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showDescriptionEditNotification", Context::class.java, Media::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showDescriptionEditNotification",
|
||||
Context::class.java,
|
||||
Media::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(method.invoke(helper, context, media, false), false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShowDescriptionEditNotificationCaseTrue() {
|
||||
val method: Method = DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showDescriptionEditNotification", Context::class.java, Media::class.java,
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DescriptionEditHelper::class.java.getDeclaredMethod(
|
||||
"showDescriptionEditNotification",
|
||||
Context::class.java,
|
||||
Media::class.java,
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
assertEquals(method.invoke(helper, context, media, true), true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import com.jraska.livedata.test
|
|||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.explore.paging.*
|
||||
import fr.free.nrw.commons.explore.paging.BasePagingPresenter
|
||||
import fr.free.nrw.commons.explore.paging.FooterItem
|
||||
import fr.free.nrw.commons.explore.paging.LoadingState
|
||||
import fr.free.nrw.commons.explore.paging.PageableBaseDataSource
|
||||
import fr.free.nrw.commons.explore.paging.PagingContract
|
||||
import io.reactivex.processors.PublishProcessor
|
||||
import io.reactivex.schedulers.TestScheduler
|
||||
import org.junit.Before
|
||||
|
|
@ -17,7 +21,6 @@ import org.mockito.Mock
|
|||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class BasePagingPresenterTest {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
|
|
@ -45,7 +48,7 @@ class BasePagingPresenterTest {
|
|||
MockitoAnnotations.openMocks(this)
|
||||
whenever(pageableBaseDataSource.pagingResults).thenReturn(searchResults)
|
||||
whenever(pageableBaseDataSource.loadingStates).thenReturn(loadingStates)
|
||||
whenever(pageableBaseDataSource.noItemsLoadedQueries)
|
||||
whenever(pageableBaseDataSource.noItemsLoadedEvent)
|
||||
.thenReturn(noItemLoadedQueries)
|
||||
testScheduler = TestScheduler()
|
||||
basePagingPresenter =
|
||||
|
|
@ -70,7 +73,8 @@ class BasePagingPresenterTest {
|
|||
@Test
|
||||
fun `Complete offers an empty list item and hides initial loader`() {
|
||||
onLoadingState(LoadingState.Complete)
|
||||
basePagingPresenter.listFooterData.test()
|
||||
basePagingPresenter.listFooterData
|
||||
.test()
|
||||
.assertValue(emptyList())
|
||||
verify(view).hideInitialLoadProgress()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ package fr.free.nrw.commons.explore
|
|||
|
||||
import android.content.Context
|
||||
import android.os.Looper.getMainLooper
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
|
|
@ -10,8 +14,8 @@ import com.google.android.material.tabs.TabLayout
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
|
|
@ -34,7 +38,6 @@ import org.robolectric.fakes.RoboMenuItem
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ExploreFragmentUnitTest {
|
||||
|
||||
private lateinit var fragment: ExploreFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var context: Context
|
||||
|
|
@ -69,7 +72,6 @@ class ExploreFragmentUnitTest {
|
|||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = fragment.onCreateView(layoutInflater, null, null) as View
|
||||
viewPager = view.findViewById(R.id.viewPager)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -101,7 +103,8 @@ class ExploreFragmentUnitTest {
|
|||
Assert.assertEquals(fragment.onBackPressed(), true)
|
||||
}
|
||||
|
||||
@Test @Ignore("TODO fix this test")
|
||||
@Test
|
||||
@Ignore("TODO fix this test")
|
||||
@Throws(Exception::class)
|
||||
fun testOnBackPressedCaseTrueSelectedTabNonZero() {
|
||||
Whitebox.setInternalState(fragment, "mobileRootFragment", exploreRootFragment)
|
||||
|
|
@ -150,5 +153,4 @@ class ExploreFragmentUnitTest {
|
|||
fragment.onCreateOptionsMenu(menu, inflater)
|
||||
verify(inflater).inflate(R.menu.menu_search, menu)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import fr.free.nrw.commons.Media
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentFeaturedRootBinding
|
||||
import fr.free.nrw.commons.explore.categories.media.CategoriesMediaFragment
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||
|
|
@ -36,7 +36,6 @@ import java.lang.reflect.Field
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ExploreListRootFragmentUnitTest {
|
||||
|
||||
private lateinit var fragment: ExploreListRootFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var context: Context
|
||||
|
|
@ -83,7 +82,6 @@ class ExploreListRootFragmentUnitTest {
|
|||
Whitebox.setInternalState(fragment, "mediaDetails", mediaDetails)
|
||||
Whitebox.setInternalState(fragment, "listFragment", listFragment)
|
||||
|
||||
|
||||
`when`(childFragmentManager.beginTransaction()).thenReturn(childFragmentTransaction)
|
||||
`when`(childFragmentTransaction.hide(any())).thenReturn(childFragmentTransaction)
|
||||
`when`(childFragmentTransaction.add(anyInt(), any())).thenReturn(childFragmentTransaction)
|
||||
|
|
@ -249,5 +247,4 @@ class ExploreListRootFragmentUnitTest {
|
|||
fun `testBackPressed_Case null != mediaDetails && mediaDetails_isNotVisible`() {
|
||||
Assert.assertEquals(fragment.backPressed(), false)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,12 @@ package fr.free.nrw.commons.explore
|
|||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.paging.PagedList
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.KArgumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.argumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.spy
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.explore.depictions.search.LoadFunction
|
||||
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||
import fr.free.nrw.commons.explore.paging.PageableBaseDataSource
|
||||
|
|
@ -14,7 +19,6 @@ import org.mockito.Mock
|
|||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class PageableBaseDataSourceTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var liveDataConverter: LiveDataConverter
|
||||
|
||||
|
|
@ -23,17 +27,18 @@ class PageableBaseDataSourceTest {
|
|||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
pageableBaseDataSource = object: PageableBaseDataSource<String>(liveDataConverter){
|
||||
override val loadFunction: LoadFunction<String>
|
||||
get() = mock()
|
||||
|
||||
}
|
||||
pageableBaseDataSource =
|
||||
object : PageableBaseDataSource<String>(liveDataConverter) {
|
||||
override val loadFunction: LoadFunction<String>
|
||||
get() = mock()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `onQueryUpdated emits new liveData`() {
|
||||
val (_, liveData) = expectNewLiveData()
|
||||
pageableBaseDataSource.pagingResults.test()
|
||||
pageableBaseDataSource.pagingResults
|
||||
.test()
|
||||
.also { pageableBaseDataSource.onQueryUpdated("test") }
|
||||
.assertValue(liveData)
|
||||
}
|
||||
|
|
@ -42,14 +47,15 @@ class PageableBaseDataSourceTest {
|
|||
fun `onQueryUpdated invokes livedatconverter with no items emitter`() {
|
||||
val (zeroItemsFuncCaptor, _) = expectNewLiveData()
|
||||
pageableBaseDataSource.onQueryUpdated("test")
|
||||
pageableBaseDataSource.noItemsLoadedQueries.test()
|
||||
pageableBaseDataSource.noItemsLoadedEvent
|
||||
.test()
|
||||
.also { zeroItemsFuncCaptor.firstValue.invoke() }
|
||||
.assertValue("test")
|
||||
}
|
||||
|
||||
/*
|
||||
* Just for coverage, no way to really assert this
|
||||
* */
|
||||
* Just for coverage, no way to really assert this
|
||||
* */
|
||||
@Test
|
||||
fun `retryFailedRequest does nothing without a factory`() {
|
||||
pageableBaseDataSource.retryFailedRequest()
|
||||
|
|
@ -65,7 +71,11 @@ class PageableBaseDataSourceTest {
|
|||
verify(dataSourceFactory).retryFailedRequest()
|
||||
}
|
||||
|
||||
private fun expectNewLiveData(): Triple<KArgumentCaptor<() -> Unit>, LiveData<PagedList<String>>, KArgumentCaptor<PagingDataSourceFactory<String>>> {
|
||||
private fun expectNewLiveData(): Triple<
|
||||
KArgumentCaptor<() -> Unit>,
|
||||
LiveData<PagedList<String>>,
|
||||
KArgumentCaptor<PagingDataSourceFactory<String>>,
|
||||
> {
|
||||
val captor = argumentCaptor<() -> Unit>()
|
||||
val dataSourceFactoryCaptor = argumentCaptor<PagingDataSourceFactory<String>>()
|
||||
val liveData: LiveData<PagedList<String>> = mock()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import fr.free.nrw.commons.explore.paging.PagingDataSourceFactory
|
|||
import io.reactivex.processors.PublishProcessor
|
||||
import org.hamcrest.CoreMatchers.instanceOf
|
||||
import org.hamcrest.MatcherAssert
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
|
|
@ -19,7 +18,6 @@ import org.mockito.Mockito
|
|||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class PagingDataSourceFactoryTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var depictsClient: DepictsClient
|
||||
|
||||
|
|
@ -32,16 +30,17 @@ class PagingDataSourceFactoryTest {
|
|||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
factory = object : PagingDataSourceFactory<String>(loadingStates) {
|
||||
override val loadFunction get() = function
|
||||
}
|
||||
factory =
|
||||
object : PagingDataSourceFactory<String>(loadingStates) {
|
||||
override val loadFunction get() = function
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `create returns a dataSource`() {
|
||||
MatcherAssert.assertThat(
|
||||
factory.create(),
|
||||
instanceOf(PagingDataSource::class.java)
|
||||
instanceOf(PagingDataSource::class.java),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package fr.free.nrw.commons.explore
|
||||
|
||||
import androidx.paging.PositionalDataSource
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.never
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.explore.depictions.search.LoadingStates
|
||||
import fr.free.nrw.commons.explore.paging.LoadingState
|
||||
import fr.free.nrw.commons.explore.paging.PagingDataSource
|
||||
|
|
@ -16,7 +20,6 @@ import org.mockito.Mockito.verifyNoInteractions
|
|||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class PagingDataSourceTest {
|
||||
|
||||
private lateinit var loadingStates: PublishProcessor<LoadingState>
|
||||
private lateinit var searchDepictionsDataSource: TestPagingDataSource
|
||||
|
||||
|
|
@ -31,7 +34,7 @@ class PagingDataSourceTest {
|
|||
searchDepictionsDataSource =
|
||||
TestPagingDataSource(
|
||||
loadingStates,
|
||||
mockGetItems
|
||||
mockGetItems,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +100,8 @@ class PagingDataSourceTest {
|
|||
val callback: PositionalDataSource.LoadRangeCallback<String> = mock()
|
||||
val params = PositionalDataSource.LoadRangeParams(0, 1)
|
||||
whenever(mockGetItems.getItems(params.loadSize, params.startPosition))
|
||||
.thenThrow(RuntimeException()).thenReturn(emptyList())
|
||||
.thenThrow(RuntimeException())
|
||||
.thenReturn(emptyList())
|
||||
val testSubscriber = loadingStates.test()
|
||||
searchDepictionsDataSource.loadRange(params, callback)
|
||||
verify(callback, never()).onResult(any())
|
||||
|
|
@ -107,17 +111,24 @@ class PagingDataSourceTest {
|
|||
LoadingState.Loading,
|
||||
LoadingState.Error,
|
||||
LoadingState.Loading,
|
||||
LoadingState.Complete
|
||||
LoadingState.Complete,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class TestPagingDataSource(loadingStates: LoadingStates, val mockGetItems: MockGetItems) :
|
||||
PagingDataSource<String>(loadingStates) {
|
||||
override fun getItems(loadSize: Int, startPosition: Int): List<String> =
|
||||
mockGetItems.getItems(loadSize, startPosition)
|
||||
class TestPagingDataSource(
|
||||
loadingStates: LoadingStates,
|
||||
val mockGetItems: MockGetItems,
|
||||
) : PagingDataSource<String>(loadingStates) {
|
||||
override fun getItems(
|
||||
loadSize: Int,
|
||||
startPosition: Int,
|
||||
): List<String> = mockGetItems.getItems(loadSize, startPosition)
|
||||
}
|
||||
|
||||
interface MockGetItems {
|
||||
fun getItems(loadSize: Int, startPosition: Int): List<String>
|
||||
fun getItems(
|
||||
loadSize: Int,
|
||||
startPosition: Int,
|
||||
): List<String>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ import org.junit.Test
|
|||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class PageableParentCategoriesDataSourceTest{
|
||||
class PageableParentCategoriesDataSourceTest {
|
||||
@Mock
|
||||
lateinit var categoryClient: CategoryClient
|
||||
|
||||
@Mock
|
||||
lateinit var liveDataConverter: LiveDataConverter
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ import org.junit.Test
|
|||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class PageableSubCategoriesDataSourceTest{
|
||||
class PageableSubCategoriesDataSourceTest {
|
||||
@Mock
|
||||
lateinit var categoryClient: CategoryClient
|
||||
|
||||
@Mock
|
||||
lateinit var liveDataConverter: LiveDataConverter
|
||||
|
||||
|
|
|
|||
|
|
@ -9,17 +9,20 @@ import fr.free.nrw.commons.mwapi.Result
|
|||
import fr.free.nrw.commons.mwapi.SparqlResponse
|
||||
import fr.free.nrw.commons.upload.depicts.DepictsInterface
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
import fr.free.nrw.commons.wikidata.model.DataValue
|
||||
import fr.free.nrw.commons.wikidata.model.DepictSearchResponse
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
import fr.free.nrw.commons.wikidata.model.SnakPartial
|
||||
import fr.free.nrw.commons.wikidata.model.StatementPartial
|
||||
import fr.free.nrw.commons.wikidata.model.WikiBaseEntityValue
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import fr.free.nrw.commons.wikidata.model.*
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class DepictsClientTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var depictsInterface: DepictsInterface
|
||||
private lateinit var depictsClient: DepictsClient
|
||||
|
|
@ -35,16 +38,16 @@ class DepictsClientTest {
|
|||
val depictSearchResponse = mock<DepictSearchResponse>()
|
||||
whenever(depictsInterface.searchForDepicts("query", "1", "en", "en", "0"))
|
||||
.thenReturn(Single.just(depictSearchResponse))
|
||||
whenever(depictSearchResponse.search).thenReturn(listOf(depictSearchItem("1"),depictSearchItem("2")))
|
||||
whenever(depictSearchResponse.search).thenReturn(listOf(depictSearchItem("1"), depictSearchItem("2")))
|
||||
val entities = mock<Entities>()
|
||||
whenever(depictsInterface.getEntities("1|2")).thenReturn(Single.just(entities))
|
||||
whenever(entities.entities()).thenReturn(emptyMap())
|
||||
depictsClient.searchForDepictions("query", 1, 0)
|
||||
depictsClient
|
||||
.searchForDepictions("query", 1, 0)
|
||||
.test()
|
||||
.assertValue(emptyList())
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun getEntities() {
|
||||
val entities = mock<Entities>()
|
||||
|
|
@ -64,25 +67,37 @@ class DepictsClientTest {
|
|||
whenever(binding2.id).thenReturn("2")
|
||||
val entities = mock<Entities>()
|
||||
val entity = mock<Entities.Entity>()
|
||||
val statementPartial = mock<Statement_partial>()
|
||||
val statementPartial = mock<StatementPartial>()
|
||||
whenever(depictsInterface.getEntities("1|2")).thenReturn(Single.just(entities))
|
||||
whenever(entities.entities()).thenReturn(mapOf("en" to entity))
|
||||
whenever(entity.statements).thenReturn(mapOf("P31" to listOf(statementPartial)))
|
||||
whenever(statementPartial.mainSnak).thenReturn(
|
||||
Snak_partial("test", "P31",
|
||||
SnakPartial(
|
||||
"test",
|
||||
"P31",
|
||||
DataValue.EntityId(
|
||||
WikiBaseEntityValue("wikibase-entityid", "Q10", 10L)
|
||||
)
|
||||
)
|
||||
WikiBaseEntityValue("wikibase-entityid", "Q10", 10L),
|
||||
),
|
||||
),
|
||||
)
|
||||
whenever(depictsInterface.getEntities("Q10")).thenReturn(Single.just(entities))
|
||||
whenever(entity.id()).thenReturn("Q10")
|
||||
depictsClient.toDepictions(Single.just(sparqlResponse))
|
||||
depictsClient
|
||||
.toDepictions(Single.just(sparqlResponse))
|
||||
.test()
|
||||
.assertValue(listOf(
|
||||
DepictedItem("", "", null,
|
||||
listOf("Q10"), emptyList(), false, "Q10")
|
||||
))
|
||||
.assertValue(
|
||||
listOf(
|
||||
DepictedItem(
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
listOf("Q10"),
|
||||
emptyList(),
|
||||
false,
|
||||
"Q10",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -99,34 +114,49 @@ class DepictsClientTest {
|
|||
val entity = mock<Entities.Entity>()
|
||||
whenever(depictsInterface.getEntities("1|2")).thenReturn(Single.just(entities))
|
||||
whenever(entities.entities()).thenReturn(mapOf("en" to entity))
|
||||
whenever(entity.descriptions()).thenReturn(mapOf("en" to
|
||||
Entities.Label("en", "Test description")
|
||||
))
|
||||
whenever(entity.descriptions()).thenReturn(
|
||||
mapOf(
|
||||
"en" to
|
||||
Entities.Label("en", "Test description"),
|
||||
),
|
||||
)
|
||||
whenever(entity.id()).thenReturn("Q10")
|
||||
depictsClient.toDepictions(Single.just(sparqlResponse))
|
||||
depictsClient
|
||||
.toDepictions(Single.just(sparqlResponse))
|
||||
.test()
|
||||
.assertValue(listOf(
|
||||
DepictedItem("", "", null, listOf("Q10"),
|
||||
emptyList(), false, "Q10")
|
||||
))
|
||||
.assertValue(
|
||||
listOf(
|
||||
DepictedItem(
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
listOf("Q10"),
|
||||
emptyList(),
|
||||
false,
|
||||
"Q10",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test mapToDepictItem when description is not empty`() {
|
||||
val method: Method = DepictsClient::class.java.getDeclaredMethod(
|
||||
"mapToDepictItem",
|
||||
Entities.Entity::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DepictsClient::class.java.getDeclaredMethod(
|
||||
"mapToDepictItem",
|
||||
Entities.Entity::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(depictsClient, entity(descriptions = mapOf("en" to "Test")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test mapToDepictItem when description is empty and P31 doesn't exists`() {
|
||||
val method: Method = DepictsClient::class.java.getDeclaredMethod(
|
||||
"mapToDepictItem",
|
||||
Entities.Entity::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DepictsClient::class.java.getDeclaredMethod(
|
||||
"mapToDepictItem",
|
||||
Entities.Entity::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(depictsClient, entity())
|
||||
}
|
||||
|
|
@ -135,23 +165,26 @@ class DepictsClientTest {
|
|||
fun `Test mapToDepictItem when description is empty and P31 exists`() {
|
||||
val entities = mock<Entities>()
|
||||
val entity = mock<Entities.Entity>()
|
||||
val statementPartial = mock<Statement_partial>()
|
||||
val statementPartial = mock<StatementPartial>()
|
||||
whenever(entity.statements).thenReturn(mapOf("P31" to listOf(statementPartial)))
|
||||
whenever(statementPartial.mainSnak).thenReturn(
|
||||
Snak_partial("test", "P31",
|
||||
SnakPartial(
|
||||
"test",
|
||||
"P31",
|
||||
DataValue.EntityId(
|
||||
WikiBaseEntityValue("wikibase-entityid", "Q10", 10L)
|
||||
)
|
||||
)
|
||||
WikiBaseEntityValue("wikibase-entityid", "Q10", 10L),
|
||||
),
|
||||
),
|
||||
)
|
||||
whenever(depictsInterface.getEntities("Q10")).thenReturn(Single.just(entities))
|
||||
whenever(entities.entities())
|
||||
.thenReturn(mapOf("test" to entity))
|
||||
whenever(entity.id()).thenReturn("Q10")
|
||||
val method: Method = DepictsClient::class.java.getDeclaredMethod(
|
||||
"mapToDepictItem",
|
||||
Entities.Entity::class.java
|
||||
)
|
||||
val method: Method =
|
||||
DepictsClient::class.java.getDeclaredMethod(
|
||||
"mapToDepictItem",
|
||||
Entities.Entity::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(depictsClient, entity)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import org.junit.Assert
|
|||
import org.junit.Test
|
||||
|
||||
class PageableDepictionsDataSourceTest {
|
||||
|
||||
@Test
|
||||
fun `loadFunction loads depictions`() {
|
||||
val depictsClient: DepictsClient = mock()
|
||||
|
|
@ -18,8 +17,7 @@ class PageableDepictionsDataSourceTest {
|
|||
pageableDepictionsDataSource.onQueryUpdated("test")
|
||||
Assert.assertEquals(
|
||||
pageableDepictionsDataSource.loadFunction.invoke(0, 1),
|
||||
emptyList<String>()
|
||||
emptyList<String>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,12 @@
|
|||
package fr.free.nrw.commons.explore.depictions
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.ActivityWikidataItemDetailsBinding
|
||||
import fr.free.nrw.commons.explore.depictions.media.DepictedImagesFragment
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
|
|
@ -35,7 +29,6 @@ import org.robolectric.fakes.RoboMenuItem
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class WikidataItemDetailsActivityUnitTests {
|
||||
|
||||
private lateinit var activity: WikidataItemDetailsActivity
|
||||
|
||||
@Mock
|
||||
|
|
@ -53,32 +46,31 @@ class WikidataItemDetailsActivityUnitTests {
|
|||
@Mock
|
||||
private lateinit var wikidataItem: DepictedItem
|
||||
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
val intent = Intent(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
WikidataItemDetailsActivity::class.java
|
||||
)
|
||||
val intent =
|
||||
Intent(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
WikidataItemDetailsActivity::class.java,
|
||||
)
|
||||
intent.putExtra("wikidataItemName", "depictionName")
|
||||
intent.putExtra("entityId", 0)
|
||||
activity =
|
||||
Robolectric.buildActivity(WikidataItemDetailsActivity::class.java, intent).create()
|
||||
Robolectric
|
||||
.buildActivity(WikidataItemDetailsActivity::class.java, intent)
|
||||
.create()
|
||||
.get()
|
||||
Whitebox.setInternalState(activity, "mediaDetailPagerFragment", mediaDetailPagerFragment)
|
||||
Whitebox.setInternalState(
|
||||
activity,
|
||||
"depictionImagesListFragment",
|
||||
depictionImagesListFragment
|
||||
depictionImagesListFragment,
|
||||
)
|
||||
Whitebox.setInternalState(activity, "supportFragmentManager", supportFragmentManager)
|
||||
|
||||
|
||||
Whitebox.setInternalState(activity, "wikidataItem", wikidataItem)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -142,7 +134,7 @@ class WikidataItemDetailsActivityUnitTests {
|
|||
fun testOnOptionsItemSelectedCaseOne() {
|
||||
Assert.assertEquals(
|
||||
activity.onOptionsItemSelected(RoboMenuItem(R.id.browser_actions_menu_items)),
|
||||
true
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -169,5 +161,4 @@ class WikidataItemDetailsActivityUnitTests {
|
|||
fun testOnMediaClicked() {
|
||||
activity.onMediaClicked(0)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import org.mockito.MockitoAnnotations
|
|||
class PageableChildDepictionsDataSourceTest {
|
||||
@Mock
|
||||
lateinit var okHttpJsonApiClient: OkHttpJsonApiClient
|
||||
|
||||
@Mock
|
||||
lateinit var liveDataConverter: LiveDataConverter
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,19 @@ package fr.free.nrw.commons.explore.depictions.media
|
|||
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import fr.free.nrw.commons.media.WikidataMediaClient
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PageableDepictedMediaDataSourceTest{
|
||||
class PageableDepictedMediaDataSourceTest {
|
||||
@Test
|
||||
fun `loadFunction loads Media`() {
|
||||
val mediaClient = mock<WikidataMediaClient>()
|
||||
whenever(mediaClient.fetchImagesForDepictedItem("test",0,1))
|
||||
whenever(mediaClient.fetchImagesForDepictedItem("test", 0, 1))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
val pageableDepictedMediaDataSource = PageableDepictedMediaDataSource(mock(), mediaClient)
|
||||
pageableDepictedMediaDataSource.onQueryUpdated("test")
|
||||
Assert.assertEquals(pageableDepictedMediaDataSource.loadFunction(0,1), emptyList<String>())
|
||||
Assert.assertEquals(pageableDepictedMediaDataSource.loadFunction(0, 1), emptyList<String>())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,3 @@ class PageableParentDepictionsDataSourceTest {
|
|||
Assert.assertEquals(dataSource.loadFunction(1, 0), listOf(depictedItem()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,36 +1,34 @@
|
|||
package fr.free.nrw.commons.explore.media
|
||||
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.notNull
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
import fr.free.nrw.commons.wikidata.model.gallery.ExtMetadata
|
||||
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||
import fr.free.nrw.commons.wikidata.model.gallery.ExtMetadata
|
||||
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
class MediaConverterTest {
|
||||
@Mock
|
||||
lateinit var page: MwQueryPage
|
||||
|
||||
@Mock
|
||||
lateinit var entity: Entities.Entity
|
||||
|
||||
@Mock
|
||||
lateinit var imageInfo: ImageInfo
|
||||
|
||||
@Mock
|
||||
lateinit var metadata: ExtMetadata
|
||||
|
||||
lateinit var mediaConverter: MediaConverter
|
||||
lateinit var media: Media
|
||||
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
|
@ -63,4 +61,4 @@ class MediaConverterTest {
|
|||
media = mediaConverter.convert(page, entity, imageInfo)
|
||||
assertEquals(media.thumbUrl, "thumbUrl")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import org.mockito.MockitoAnnotations
|
|||
class PageableMediaDataSourceTest {
|
||||
@Mock
|
||||
lateinit var mediaConverter: MediaConverter
|
||||
|
||||
@Mock
|
||||
lateinit var mediaClient: MediaClient
|
||||
|
||||
|
|
@ -27,6 +28,6 @@ class PageableMediaDataSourceTest {
|
|||
.thenReturn(Single.just(emptyList()))
|
||||
val pageableMediaDataSource = PageableMediaDataSource(mock(), mediaClient)
|
||||
pageableMediaDataSource.onQueryUpdated("test")
|
||||
Assert.assertEquals(pageableMediaDataSource.loadFunction(0,1), emptyList<String>())
|
||||
Assert.assertEquals(pageableMediaDataSource.loadFunction(0, 1), emptyList<String>())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,43 @@ import android.database.Cursor
|
|||
import android.database.MatrixCursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.os.RemoteException
|
||||
import com.nhaarman.mockitokotlin2.*
|
||||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.anyOrNull
|
||||
import com.nhaarman.mockitokotlin2.argumentCaptor
|
||||
import com.nhaarman.mockitokotlin2.eq
|
||||
import com.nhaarman.mockitokotlin2.inOrder
|
||||
import com.nhaarman.mockitokotlin2.isA
|
||||
import com.nhaarman.mockitokotlin2.isNull
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.explore.models.RecentSearch
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesContentProvider.BASE_URI
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesContentProvider.uriForId
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.*
|
||||
import org.junit.Assert.*
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.ALL_FIELDS
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.COLUMN_ID
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.COLUMN_LAST_USED
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.COLUMN_NAME
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.CREATE_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.DROP_TABLE_STATEMENT
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.onCreate
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.onDelete
|
||||
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao.Table.onUpdate
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.verifyNoInteractions
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class RecentSearchesDaoTest {
|
||||
|
||||
private val columns = arrayOf(COLUMN_ID, COLUMN_NAME, COLUMN_LAST_USED)
|
||||
private val client: ContentProviderClient = mock()
|
||||
private val database: SQLiteDatabase = mock()
|
||||
|
|
@ -238,11 +256,11 @@ class RecentSearchesDaoTest {
|
|||
assertEquals(123L, recentSearch?.lastSearched?.time)
|
||||
|
||||
verify(client).query(
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
eq("$COLUMN_NAME=?"),
|
||||
queryCaptor.capture(),
|
||||
isNull()
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
eq("$COLUMN_NAME=?"),
|
||||
queryCaptor.capture(),
|
||||
isNull(),
|
||||
)
|
||||
assertEquals("butterfly", queryCaptor.firstValue[0])
|
||||
}
|
||||
|
|
@ -274,11 +292,11 @@ class RecentSearchesDaoTest {
|
|||
assertEquals("butterfly", result[0])
|
||||
|
||||
verify(client).query(
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
isNull(),
|
||||
queryCaptor.capture(),
|
||||
eq("$COLUMN_LAST_USED DESC")
|
||||
eq(BASE_URI),
|
||||
eq(ALL_FIELDS),
|
||||
isNull(),
|
||||
queryCaptor.capture(),
|
||||
eq("$COLUMN_LAST_USED DESC"),
|
||||
)
|
||||
assertEquals(0, queryCaptor.firstValue.size)
|
||||
}
|
||||
|
|
@ -299,10 +317,10 @@ class RecentSearchesDaoTest {
|
|||
* Unit Test for creating entries in recent searches database.
|
||||
* @param rowCount No of rows
|
||||
*/
|
||||
private fun createCursor(rowCount: Int) = MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("1", "butterfly", "123"))
|
||||
private fun createCursor(rowCount: Int) =
|
||||
MatrixCursor(columns, rowCount).apply {
|
||||
for (i in 0 until rowCount) {
|
||||
addRow(listOf("1", "butterfly", "123"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,12 @@ package fr.free.nrw.commons.explore.recentsearches
|
|||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.ListView
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
|
|
@ -34,7 +29,6 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class RecentSearchesFragmentUnitTest {
|
||||
|
||||
private lateinit var fragment: RecentSearchesFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var context: Context
|
||||
|
|
@ -43,7 +37,6 @@ class RecentSearchesFragmentUnitTest {
|
|||
@Mock
|
||||
private lateinit var recentSearchesDao: RecentSearchesDao
|
||||
|
||||
|
||||
@Mock
|
||||
private lateinit var adapter: ArrayAdapter<*>
|
||||
|
||||
|
|
@ -96,10 +89,11 @@ class RecentSearchesFragmentUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowDeleteRecentAlertDialog() {
|
||||
val method: Method = RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"showDeleteRecentAlertDialog",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"showDeleteRecentAlertDialog",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, context)
|
||||
}
|
||||
|
|
@ -107,11 +101,12 @@ class RecentSearchesFragmentUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetDeleteRecentPositiveButton() {
|
||||
val method: Method = RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"setDeleteRecentPositiveButton",
|
||||
Context::class.java,
|
||||
DialogInterface::class.java
|
||||
)
|
||||
val method: Method =
|
||||
RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"setDeleteRecentPositiveButton",
|
||||
Context::class.java,
|
||||
DialogInterface::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, context, dialog)
|
||||
}
|
||||
|
|
@ -119,11 +114,12 @@ class RecentSearchesFragmentUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowDeleteAlertDialog() {
|
||||
val method: Method = RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"showDeleteAlertDialog",
|
||||
Context::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"showDeleteAlertDialog",
|
||||
Context::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, context, 0)
|
||||
}
|
||||
|
|
@ -131,14 +127,14 @@ class RecentSearchesFragmentUnitTest {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetDeletePositiveButton() {
|
||||
val method: Method = RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"setDeletePositiveButton",
|
||||
Context::class.java,
|
||||
DialogInterface::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
RecentSearchesFragment::class.java.getDeclaredMethod(
|
||||
"setDeletePositiveButton",
|
||||
Context::class.java,
|
||||
DialogInterface::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, context, dialog, 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
package fr.free.nrw.commons.explore.search
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.SearchView
|
||||
import androidx.fragment.app.FragmentController
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.ViewPagerAdapter
|
||||
import fr.free.nrw.commons.databinding.ActivitySearchBinding
|
||||
import fr.free.nrw.commons.explore.SearchActivity
|
||||
import fr.free.nrw.commons.explore.categories.search.SearchCategoryFragment
|
||||
import fr.free.nrw.commons.explore.depictions.search.SearchDepictionsFragment
|
||||
|
|
@ -37,12 +33,10 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.annotation.LooperMode
|
||||
import java.lang.reflect.Method
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class SearchActivityUnitTests {
|
||||
|
||||
@Mock
|
||||
private lateinit var activity: SearchActivity
|
||||
|
||||
|
|
@ -175,10 +169,11 @@ class SearchActivityUnitTests {
|
|||
fun testHandleSearchCaseEmpty() {
|
||||
Whitebox.setInternalState(activity, "recentSearchesFragment", recentSearchesFragment)
|
||||
val query = ""
|
||||
val method: Method = SearchActivity::class.java.getDeclaredMethod(
|
||||
"handleSearch",
|
||||
CharSequence::class.java
|
||||
)
|
||||
val method: Method =
|
||||
SearchActivity::class.java.getDeclaredMethod(
|
||||
"handleSearch",
|
||||
CharSequence::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, query)
|
||||
verify(recentSearchesFragment).updateRecentSearches()
|
||||
|
|
@ -209,10 +204,11 @@ class SearchActivityUnitTests {
|
|||
`when`(searchMediaFragment.isRemoving).thenReturn(false)
|
||||
`when`(searchCategoryFragment.isRemoving).thenReturn(false)
|
||||
|
||||
val method: Method = SearchActivity::class.java.getDeclaredMethod(
|
||||
"handleSearch",
|
||||
CharSequence::class.java
|
||||
)
|
||||
val method: Method =
|
||||
SearchActivity::class.java.getDeclaredMethod(
|
||||
"handleSearch",
|
||||
CharSequence::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, query)
|
||||
verify(recentSearchesDao).find(query)
|
||||
|
|
@ -220,5 +216,4 @@ class SearchActivityUnitTests {
|
|||
verify(searchMediaFragment).onQueryUpdated(query)
|
||||
verify(searchCategoryFragment).onQueryUpdated(query)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class FeedbackContentCreatorUnitTests {
|
|||
private lateinit var feedback: Feedback
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
|
@ -37,5 +37,4 @@ class FeedbackContentCreatorUnitTests {
|
|||
Assert.assertNotNull(creator.getSectionText())
|
||||
Assert.assertNotNull(creator.getSectionTitle())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.TestUtility.setFinalStatic
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.DialogFeedbackBinding
|
||||
import fr.free.nrw.commons.ui.PasteSensitiveTextInputEditText
|
||||
import org.junit.Assert
|
||||
|
|
@ -66,8 +66,9 @@ class FeedbackDialogTests {
|
|||
val editable = mock(Editable::class.java)
|
||||
val ed = mock(PasteSensitiveTextInputEditText::class.java)
|
||||
setFinalStatic(
|
||||
DialogFeedbackBinding::class.java.getDeclaredField("feedbackItemEditText"),
|
||||
ed)
|
||||
DialogFeedbackBinding::class.java.getDeclaredField("feedbackItemEditText"),
|
||||
ed,
|
||||
)
|
||||
`when`(ed?.text).thenReturn(editable)
|
||||
doReturn(editable).`when`(ed)?.text
|
||||
doReturn("").`when`(editable).toString()
|
||||
|
|
@ -80,13 +81,13 @@ class FeedbackDialogTests {
|
|||
val editable: Editable = mock(Editable::class.java)
|
||||
val ed = mock(PasteSensitiveTextInputEditText::class.java)
|
||||
setFinalStatic(
|
||||
DialogFeedbackBinding::class.java.getDeclaredField("feedbackItemEditText"),
|
||||
ed)
|
||||
DialogFeedbackBinding::class.java.getDeclaredField("feedbackItemEditText"),
|
||||
ed,
|
||||
)
|
||||
`when`(ed?.text).thenReturn(editable)
|
||||
`when`(editable.toString()).thenReturn("1234")
|
||||
|
||||
Assert.assertEquals(ed.text.toString(), "1234")
|
||||
dialog.submitFeedback()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,5 +61,4 @@ class FeedbackUnitTests {
|
|||
feedback.networkType = "network"
|
||||
Assert.assertEquals(feedback.networkType, "network")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,13 @@ import org.junit.Assert.assertEquals
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.*
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.ArgumentCaptor
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Captor
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
|
@ -28,11 +32,10 @@ import kotlin.random.Random.Default.nextBoolean
|
|||
@Config(
|
||||
sdk = [21],
|
||||
application = TestCommonsApplication::class,
|
||||
shadows = [ShadowFileProvider::class]
|
||||
shadows = [ShadowFileProvider::class],
|
||||
)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class FilePickerTest {
|
||||
|
||||
@Mock
|
||||
internal lateinit var activity: Activity
|
||||
|
||||
|
|
@ -64,7 +67,7 @@ class FilePickerTest {
|
|||
FilePicker.openGallery(activity, 0, nextBoolean())
|
||||
verify(activity).startActivityForResult(
|
||||
ArgumentMatchers.any(),
|
||||
requestCodeCaptor?.capture()?.toInt()!!
|
||||
requestCodeCaptor?.capture()?.toInt()!!,
|
||||
)
|
||||
assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_GALLERY)
|
||||
}
|
||||
|
|
@ -79,7 +82,7 @@ class FilePickerTest {
|
|||
FilePicker.openCameraForImage(activity, 0)
|
||||
verify(activity).startActivityForResult(
|
||||
ArgumentMatchers.any(),
|
||||
requestCodeCaptor?.capture()?.toInt()!!
|
||||
requestCodeCaptor?.capture()?.toInt()!!,
|
||||
)
|
||||
assertEquals(requestCodeCaptor?.value, RequestCodes.TAKE_PICTURE)
|
||||
}
|
||||
|
|
@ -87,10 +90,11 @@ class FilePickerTest {
|
|||
@Test
|
||||
fun testCreateCameraPictureFile() {
|
||||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"createCameraPictureFile",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"createCameraPictureFile",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, context)
|
||||
}
|
||||
|
|
@ -98,11 +102,12 @@ class FilePickerTest {
|
|||
@Test
|
||||
fun testCreateCameraForImageIntent() {
|
||||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"createCameraForImageIntent",
|
||||
Context::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"createCameraForImageIntent",
|
||||
Context::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, context, 0)
|
||||
}
|
||||
|
|
@ -112,11 +117,12 @@ class FilePickerTest {
|
|||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val mockUri = mock(Uri::class.java)
|
||||
val mockContext = mock(Context::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"revokeWritePermission",
|
||||
Context::class.java,
|
||||
Uri::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"revokeWritePermission",
|
||||
Context::class.java,
|
||||
Uri::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, mockContext, mockUri)
|
||||
}
|
||||
|
|
@ -124,10 +130,11 @@ class FilePickerTest {
|
|||
@Test
|
||||
fun testRestoreType() {
|
||||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"restoreType",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"restoreType",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, context)
|
||||
}
|
||||
|
|
@ -135,10 +142,11 @@ class FilePickerTest {
|
|||
@Test
|
||||
fun testTakenCameraPicture() {
|
||||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraPicture",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraPicture",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, context)
|
||||
}
|
||||
|
|
@ -148,10 +156,11 @@ class FilePickerTest {
|
|||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
`when`(PreferenceManager.getDefaultSharedPreferences(activity)).thenReturn(sharedPref)
|
||||
`when`(sharedPref.getString("last_photo", null)).thenReturn("")
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraPicture",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraPicture",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, activity)
|
||||
}
|
||||
|
|
@ -159,10 +168,11 @@ class FilePickerTest {
|
|||
@Test
|
||||
fun testTakenCameraVideo() {
|
||||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraVideo",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraVideo",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, context)
|
||||
}
|
||||
|
|
@ -172,10 +182,11 @@ class FilePickerTest {
|
|||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
`when`(PreferenceManager.getDefaultSharedPreferences(activity)).thenReturn(sharedPref)
|
||||
`when`(sharedPref.getString("last_video", null)).thenReturn("")
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraVideo",
|
||||
Context::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"takenCameraVideo",
|
||||
Context::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, activity)
|
||||
}
|
||||
|
|
@ -184,10 +195,11 @@ class FilePickerTest {
|
|||
fun testIsPhoto() {
|
||||
val mockFilePicker = mock(FilePicker::class.java)
|
||||
val mockIntent = mock(Intent::class.java)
|
||||
val method: Method = FilePicker::class.java.getDeclaredMethod(
|
||||
"isPhoto",
|
||||
Intent::class.java
|
||||
)
|
||||
val method: Method =
|
||||
FilePicker::class.java.getDeclaredMethod(
|
||||
"isPhoto",
|
||||
Intent::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(mockFilePicker, mockIntent)
|
||||
}
|
||||
|
|
@ -201,24 +213,28 @@ class FilePickerTest {
|
|||
mockIntent,
|
||||
activity,
|
||||
object : DefaultCallback() {
|
||||
override fun onCanceled(source: FilePicker.ImageSource, type: Int) {
|
||||
override fun onCanceled(
|
||||
source: FilePicker.ImageSource,
|
||||
type: Int,
|
||||
) {
|
||||
super.onCanceled(source, type)
|
||||
}
|
||||
|
||||
override fun onImagePickerError(
|
||||
e: Exception,
|
||||
source: FilePicker.ImageSource,
|
||||
type: Int
|
||||
type: Int,
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onImagesPicked(
|
||||
imagesFiles: List<UploadableFile>,
|
||||
source: FilePicker.ImageSource,
|
||||
type: Int
|
||||
type: Int,
|
||||
) {
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -230,4 +246,4 @@ class FilePickerTest {
|
|||
verify(activity).startActivityForResult(ArgumentMatchers.any(), requestCodeCaptor?.capture()?.toInt()!!)
|
||||
assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,20 +4,15 @@ import android.accounts.Account
|
|||
import android.content.Context
|
||||
import android.os.Looper.getMainLooper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.Spinner
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentLeaderboardBinding
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment
|
||||
|
|
@ -44,13 +39,11 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class LeaderboardFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: LeaderboardFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var context: Context
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
|
||||
|
||||
@Mock
|
||||
private lateinit var viewModel: LeaderboardListViewModel
|
||||
|
||||
|
|
@ -104,9 +97,10 @@ class LeaderboardFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testRefreshLeaderboard() {
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"refreshLeaderboard"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"refreshLeaderboard",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -114,9 +108,10 @@ class LeaderboardFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testScrollToUserRank() {
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -126,9 +121,10 @@ class LeaderboardFragmentUnitTests {
|
|||
fun testScrollToUserRankCaseNonZeroTrue() {
|
||||
Whitebox.setInternalState(fragment, "userRank", 1)
|
||||
`when`(adapter.itemCount).thenReturn(3)
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -138,26 +134,27 @@ class LeaderboardFragmentUnitTests {
|
|||
fun testScrollToUserRankCaseNonZeroFalse() {
|
||||
Whitebox.setInternalState(fragment, "userRank", 1)
|
||||
`when`(adapter.itemCount).thenReturn(1)
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetLeaderboard() {
|
||||
Whitebox.setInternalState(fragment, "sessionManager", sessionManager)
|
||||
`when`(sessionManager.currentAccount).thenReturn(account)
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"setLeaderboard",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
Int::class.java,
|
||||
Int::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"setLeaderboard",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
Int::class.java,
|
||||
Int::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "", "", 0, 0)
|
||||
}
|
||||
|
|
@ -165,9 +162,10 @@ class LeaderboardFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHideProgressBar() {
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"hideProgressBar"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"hideProgressBar",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -175,9 +173,10 @@ class LeaderboardFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowProgressBar() {
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"showProgressBar"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"showProgressBar",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -185,9 +184,10 @@ class LeaderboardFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnError() {
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"onError"
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"onError",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -195,10 +195,11 @@ class LeaderboardFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testMenuVisibilityOverrideNotVisible() {
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"setMenuVisibility",
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"setMenuVisibility",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, false)
|
||||
Assert.assertNull(ShadowToast.getLatestToast())
|
||||
|
|
@ -209,23 +210,22 @@ class LeaderboardFragmentUnitTests {
|
|||
fun testMenuVisibilityOverrideVisibleWithContext() {
|
||||
shadowOf(getMainLooper()).idle()
|
||||
`when`(parentView.context).thenReturn(context)
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"setMenuVisibility",
|
||||
Boolean::class.java
|
||||
)
|
||||
val method: Method =
|
||||
LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"setMenuVisibility",
|
||||
Boolean::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, true)
|
||||
if(isBetaFlavour) {
|
||||
if (isBetaFlavour) {
|
||||
Assert.assertEquals(
|
||||
ShadowToast.getTextOfLatestToast().toString(),
|
||||
context.getString(R.string.leaderboard_unavailable_beta)
|
||||
context.getString(R.string.leaderboard_unavailable_beta),
|
||||
)
|
||||
} else {
|
||||
Assert.assertNull(
|
||||
ShadowToast.getTextOfLatestToast()
|
||||
ShadowToast.getTextOfLatestToast(),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.lang.reflect.Field
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class LeaderboardListAdapterUnitTests {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var adapter: LeaderboardListAdapter
|
||||
|
||||
|
|
@ -97,5 +96,4 @@ class LeaderboardListAdapterUnitTests {
|
|||
`when`(pagedList.size).thenReturn(list.size)
|
||||
return pagedList
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ class LatLngTest {
|
|||
|
||||
@Before
|
||||
fun setup() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -40,14 +39,14 @@ class LatLngTest {
|
|||
fun testHashCodeDiffersWenLngZero() {
|
||||
latLng1 = LatLng(2.0, 0.0, 0.0f)
|
||||
latLng2 = LatLng(1.0, 0.0, 0.0f)
|
||||
assert(latLng1.hashCode()!=latLng2.hashCode())
|
||||
assert(latLng1.hashCode() != latLng2.hashCode())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashCodeDiffersWenLatZero() {
|
||||
latLng1 = LatLng(0.0, 1.0, 0.0f)
|
||||
latLng2 = LatLng(0.0, 2.0, 0.0f)
|
||||
assert(latLng1.hashCode()!=latLng2.hashCode())
|
||||
assert(latLng1.hashCode() != latLng2.hashCode())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -62,4 +61,4 @@ class LatLngTest {
|
|||
latLng1 = LatLng(1.0, 2.0, 5.0f)
|
||||
assert(latLng1.toString().equals("lat/lng: (1.0,2.0)"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.LAST_ZO
|
|||
import io.reactivex.android.plugins.RxAndroidPlugins
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.powermock.reflect.Whitebox
|
||||
|
|
@ -40,7 +40,6 @@ import java.lang.reflect.Method
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class LocationPickerActivityUnitTests {
|
||||
|
||||
private lateinit var activity: LocationPickerActivity
|
||||
private lateinit var context: Context
|
||||
|
||||
|
|
@ -114,9 +113,10 @@ class LocationPickerActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAddCredits() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"addCredits"
|
||||
)
|
||||
val method: Method =
|
||||
LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"addCredits",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(tvAttribution).text = any()
|
||||
|
|
@ -126,9 +126,10 @@ class LocationPickerActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnClickModifyLocation() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onClickModifyLocation"
|
||||
)
|
||||
val method: Method =
|
||||
LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onClickModifyLocation",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(placeSelectedButton, times(1)).visibility = View.VISIBLE
|
||||
|
|
@ -145,9 +146,10 @@ class LocationPickerActivityUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnClickRemoveLocation() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onClickRemoveLocation"
|
||||
)
|
||||
val method: Method =
|
||||
LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onClickRemoveLocation",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
|
@ -156,22 +158,20 @@ class LocationPickerActivityUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPlaceSelected() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
Whitebox.setInternalState(activity,"activity", "NoLocationUploadActivity")
|
||||
Whitebox.setInternalState(activity, "activity", "NoLocationUploadActivity")
|
||||
val position = GeoPoint(51.50550, -0.07520)
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"placeSelected"
|
||||
)
|
||||
val method: Method =
|
||||
LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"placeSelected",
|
||||
)
|
||||
`when`(mapView.mapCenter).thenReturn(position)
|
||||
`when`(mapView.zoomLevel).thenReturn(15)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(applicationKvStore, times(1)).putString(
|
||||
LAST_LOCATION,
|
||||
position.latitude.toString() + "," + position.longitude.toString()
|
||||
position.latitude.toString() + "," + position.longitude.toString(),
|
||||
)
|
||||
verify(applicationKvStore, times(1)).putString(LAST_ZOOM, mapView.zoomLevel.toString())
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import retrofit2.Call
|
|||
import retrofit2.Response
|
||||
|
||||
class LocationPickerViewModelUnitTests {
|
||||
|
||||
private lateinit var viewModel: LocationPickerViewModel
|
||||
|
||||
@Mock
|
||||
|
|
@ -68,5 +67,4 @@ class LocationPickerViewModelUnitTests {
|
|||
fun testGetResult() {
|
||||
viewModel.result
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.auth.LoginActivity
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
|
@ -23,11 +23,9 @@ import org.robolectric.annotation.Config
|
|||
import org.robolectric.fakes.RoboMenuItem
|
||||
import java.lang.reflect.Field
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class LoginActivityUnitTests {
|
||||
|
||||
@Mock
|
||||
private lateinit var activity: LoginActivity
|
||||
|
||||
|
|
@ -46,7 +44,6 @@ class LoginActivityUnitTests {
|
|||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
|
|
@ -116,5 +113,4 @@ class LoginActivityUnitTests {
|
|||
fun testSetContentView() {
|
||||
activity.setContentView(view, params)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,13 @@ import com.nhaarman.mockitokotlin2.verify
|
|||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import okhttp3.*
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.Call
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
|
@ -24,7 +30,6 @@ import java.lang.reflect.Method
|
|||
import java.util.concurrent.Executor
|
||||
|
||||
class CustomOkHttpNetworkFetcherUnitTest {
|
||||
|
||||
private lateinit var fetcher: CustomOkHttpNetworkFetcher
|
||||
private lateinit var okHttpClient: OkHttpClient
|
||||
private lateinit var state: CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState
|
||||
|
|
@ -91,8 +96,8 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
whenever(
|
||||
defaultKvStore.getBoolean(
|
||||
CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED,
|
||||
false
|
||||
)
|
||||
false,
|
||||
),
|
||||
).thenReturn(true)
|
||||
fetcher.fetch(state, callback)
|
||||
verify(callback).onFailure(any())
|
||||
|
|
@ -105,8 +110,8 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
whenever(
|
||||
defaultKvStore.getBoolean(
|
||||
CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED,
|
||||
false
|
||||
)
|
||||
false,
|
||||
),
|
||||
).thenReturn(false)
|
||||
fetcher.fetch(state, callback)
|
||||
fetcher.onFetchCompletion(state, 0)
|
||||
|
|
@ -120,8 +125,8 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
whenever(
|
||||
defaultKvStore.getBoolean(
|
||||
CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED,
|
||||
false
|
||||
)
|
||||
false,
|
||||
),
|
||||
).thenReturn(false)
|
||||
fetcher.fetch(state, callback)
|
||||
verify(callback).onFailure(any())
|
||||
|
|
@ -138,9 +143,11 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testOnFetchCancellationRequested() {
|
||||
Whitebox.setInternalState(fetcher, "mCancellationExecutor", executor)
|
||||
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchCancellationRequested", Call::class.java,
|
||||
)
|
||||
val method: Method =
|
||||
CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchCancellationRequested",
|
||||
Call::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fetcher, call)
|
||||
verify(executor).execute(any())
|
||||
|
|
@ -152,13 +159,14 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
whenever(response.body).thenReturn(body)
|
||||
whenever(response.isSuccessful).thenReturn(false)
|
||||
whenever(call.isCanceled()).thenReturn(true)
|
||||
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchResponse",
|
||||
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
|
||||
Call::class.java,
|
||||
Response::class.java,
|
||||
NetworkFetcher.Callback::class.java,
|
||||
)
|
||||
val method: Method =
|
||||
CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchResponse",
|
||||
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
|
||||
Call::class.java,
|
||||
Response::class.java,
|
||||
NetworkFetcher.Callback::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fetcher, state, call, response, callback)
|
||||
verify(callback).onCancellation()
|
||||
|
|
@ -174,22 +182,25 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
whenever(body.contentLength()).thenReturn(-1)
|
||||
|
||||
// Build Response object with Content-Range header
|
||||
val responseBuilder = Response.Builder()
|
||||
.request(Request.Builder().url("http://example.com").build())
|
||||
.protocol(Protocol.HTTP_1_1)
|
||||
.code(200)
|
||||
.message("OK")
|
||||
.header("Content-Range", "bytes 200-1000/67589")
|
||||
.body(body)
|
||||
val responseBuilder =
|
||||
Response
|
||||
.Builder()
|
||||
.request(Request.Builder().url("http://example.com").build())
|
||||
.protocol(Protocol.HTTP_1_1)
|
||||
.code(200)
|
||||
.message("OK")
|
||||
.header("Content-Range", "bytes 200-1000/67589")
|
||||
.body(body)
|
||||
whenever(call.execute()).thenReturn(responseBuilder.build())
|
||||
|
||||
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchResponse",
|
||||
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
|
||||
Call::class.java,
|
||||
Response::class.java,
|
||||
NetworkFetcher.Callback::class.java,
|
||||
)
|
||||
val method: Method =
|
||||
CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchResponse",
|
||||
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
|
||||
Call::class.java,
|
||||
Response::class.java,
|
||||
NetworkFetcher.Callback::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fetcher, state, call, responseBuilder.build(), callback)
|
||||
verify(callback).onResponse(null, 0)
|
||||
|
|
@ -205,25 +216,27 @@ class CustomOkHttpNetworkFetcherUnitTest {
|
|||
whenever(body.contentLength()).thenReturn(-1)
|
||||
|
||||
// Build Response object with Content-Range header
|
||||
val responseBuilder = Response.Builder()
|
||||
.request(Request.Builder().url("http://example.com").build())
|
||||
.protocol(Protocol.HTTP_1_1)
|
||||
.code(200)
|
||||
.message("OK")
|
||||
.header("Content-Range", "Test")
|
||||
.body(body)
|
||||
val responseBuilder =
|
||||
Response
|
||||
.Builder()
|
||||
.request(Request.Builder().url("http://example.com").build())
|
||||
.protocol(Protocol.HTTP_1_1)
|
||||
.code(200)
|
||||
.message("OK")
|
||||
.header("Content-Range", "Test")
|
||||
.body(body)
|
||||
whenever(call.execute()).thenReturn(responseBuilder.build())
|
||||
|
||||
val method: Method = CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchResponse",
|
||||
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
|
||||
Call::class.java,
|
||||
Response::class.java,
|
||||
NetworkFetcher.Callback::class.java,
|
||||
)
|
||||
val method: Method =
|
||||
CustomOkHttpNetworkFetcher::class.java.getDeclaredMethod(
|
||||
"onFetchResponse",
|
||||
CustomOkHttpNetworkFetcher.OkHttpNetworkFetchState::class.java,
|
||||
Call::class.java,
|
||||
Response::class.java,
|
||||
NetworkFetcher.Callback::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fetcher, state, call, responseBuilder.build(), callback)
|
||||
verify(callback).onFailure(any())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ import fr.free.nrw.commons.BuildConfig
|
|||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.explore.media.MediaConverter
|
||||
import fr.free.nrw.commons.media.model.PageMediaListResponse
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResult
|
||||
import io.reactivex.Single
|
||||
import media
|
||||
import org.junit.Before
|
||||
|
|
@ -13,15 +18,8 @@ import org.junit.Test
|
|||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResult
|
||||
import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
|
||||
|
||||
class MediaClientTest {
|
||||
|
||||
@Mock
|
||||
internal lateinit var mediaInterface: MediaInterface
|
||||
|
||||
|
|
@ -71,9 +69,10 @@ class MediaClientTest {
|
|||
|
||||
@Test
|
||||
fun `checkFileExistsUsingSha returns false with no Images`() {
|
||||
val mwQueryResponse = mockQuery {
|
||||
whenever(allImages()).thenReturn(listOf())
|
||||
}
|
||||
val mwQueryResponse =
|
||||
mockQuery {
|
||||
whenever(allImages()).thenReturn(listOf())
|
||||
}
|
||||
whenever(mediaInterface.checkFileExistsUsingSha(""))
|
||||
.thenReturn(Single.just(mwQueryResponse))
|
||||
mediaClient.checkFileExistsUsingSha("").test().assertValue(false)
|
||||
|
|
@ -81,9 +80,10 @@ class MediaClientTest {
|
|||
|
||||
@Test
|
||||
fun `checkFileExistsUsingSha returns true with Images`() {
|
||||
val mwQueryResponse = mockQuery {
|
||||
whenever(allImages()).thenReturn(listOf(mock()))
|
||||
}
|
||||
val mwQueryResponse =
|
||||
mockQuery {
|
||||
whenever(allImages()).thenReturn(listOf(mock()))
|
||||
}
|
||||
whenever(mediaInterface.checkFileExistsUsingSha(""))
|
||||
.thenReturn(Single.just(mwQueryResponse))
|
||||
mediaClient.checkFileExistsUsingSha("").test().assertValue(true)
|
||||
|
|
@ -101,7 +101,7 @@ class MediaClientTest {
|
|||
mediaClient.getMediaListFromCategory("").test().assertError { true }
|
||||
|
||||
mediaClient.resetCategoryContinuation("")
|
||||
val (resetMwQueryResponse, resetMedia)=expectSuccessfulMapping()
|
||||
val (resetMwQueryResponse, resetMedia) = expectSuccessfulMapping()
|
||||
whenever(mediaInterface.getMediaListFromCategory("", 10, emptyMap()))
|
||||
.thenReturn(Single.just(resetMwQueryResponse))
|
||||
mediaClient.getMediaListFromCategory("").test().assertValues(listOf(resetMedia))
|
||||
|
|
@ -121,7 +121,8 @@ class MediaClientTest {
|
|||
val (mwQueryResponse, media) = expectSuccessfulMapping()
|
||||
whenever(mediaInterface.getMediaListFromSearch("", 0, 1))
|
||||
.thenReturn(Single.just(mwQueryResponse))
|
||||
mediaClient.getMediaListFromSearch("", 0, 1)
|
||||
mediaClient
|
||||
.getMediaListFromSearch("", 0, 1)
|
||||
.test()
|
||||
.assertValues(listOf(media))
|
||||
}
|
||||
|
|
@ -131,7 +132,8 @@ class MediaClientTest {
|
|||
val (mwQueryResponse, media) = expectSuccessfulMapping()
|
||||
whenever(mediaInterface.fetchImagesForDepictedItem("haswbstatement:${BuildConfig.DEPICTS_PROPERTY}=", "0", "1"))
|
||||
.thenReturn(Single.just(mwQueryResponse))
|
||||
mediaClient.fetchImagesForDepictedItem("", 0, 1)
|
||||
mediaClient
|
||||
.fetchImagesForDepictedItem("", 0, 1)
|
||||
.test()
|
||||
.assertValues(listOf(media))
|
||||
}
|
||||
|
|
@ -178,7 +180,7 @@ class MediaClientTest {
|
|||
fun `getEntities invokes interface with non empty ids`() {
|
||||
val entities = mock<Entities>()
|
||||
whenever(mediaDetailInterface.getEntity("1|2")).thenReturn(Single.just(entities))
|
||||
mediaClient.getEntities(listOf("1","2")).test().assertValue(entities)
|
||||
mediaClient.getEntities(listOf("1", "2")).test().assertValue(entities)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -213,21 +215,21 @@ class MediaClientTest {
|
|||
return mwQueryResponse
|
||||
}
|
||||
|
||||
private fun expectResponseWithPageId(expectedId: Int): MwQueryResponse {
|
||||
return mockQuery {
|
||||
private fun expectResponseWithPageId(expectedId: Int): MwQueryResponse =
|
||||
mockQuery {
|
||||
val mwQueryPage = mock<MwQueryPage>()
|
||||
whenever(firstPage()).thenReturn(mwQueryPage)
|
||||
whenever(mwQueryPage.pageId()).thenReturn(expectedId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun expectSuccessfulMapping(continuationMap: Map<String, String>? = emptyMap()): Pair<MwQueryResponse, Media> {
|
||||
val media = media()
|
||||
val mwQueryPage = mock<MwQueryPage>()
|
||||
val mwQueryResponse = mockQuery {
|
||||
whenever(pages()).thenReturn(listOf(mwQueryPage, mwQueryPage))
|
||||
whenever(mwQueryPage.pageId()).thenReturn(1, 2)
|
||||
}
|
||||
val mwQueryResponse =
|
||||
mockQuery {
|
||||
whenever(pages()).thenReturn(listOf(mwQueryPage, mwQueryPage))
|
||||
whenever(mwQueryPage.pageId()).thenReturn(1, 2)
|
||||
}
|
||||
whenever(mwQueryResponse.continuation()).thenReturn(continuationMap)
|
||||
val entities = mock<Entities>()
|
||||
whenever(mediaDetailInterface.getEntity("M1|M2")).thenReturn(Single.just(entities))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,13 @@ import android.view.View
|
|||
import android.view.View.GONE
|
||||
import android.view.ViewTreeObserver
|
||||
import android.webkit.WebView
|
||||
import android.widget.*
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ListView
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.ScrollView
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
|
|
@ -25,7 +31,6 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||
import fr.free.nrw.commons.LocationPicker.LocationPickerActivity
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentMediaDetailBinding
|
||||
|
|
@ -41,8 +46,18 @@ import org.junit.Assert
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.*
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.anyInt
|
||||
import org.mockito.Mockito.anyString
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.spy
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
|
@ -54,15 +69,15 @@ import org.robolectric.shadows.ShadowActivity
|
|||
import org.robolectric.shadows.ShadowIntent
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class MediaDetailFragmentUnitTests {
|
||||
|
||||
private val REQUEST_CODE = 1001
|
||||
private val LAST_LOCATION = "last_location_while_uploading"
|
||||
private val requestCode = 1001
|
||||
private val lastLocation = "last_location_while_uploading"
|
||||
private lateinit var fragment: MediaDetailFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
|
|
@ -80,7 +95,6 @@ class MediaDetailFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var delete: Button
|
||||
|
||||
|
||||
private var isDeleted = true
|
||||
|
||||
@Mock
|
||||
|
|
@ -138,21 +152,20 @@ class MediaDetailFragmentUnitTests {
|
|||
private lateinit var intent: Intent
|
||||
|
||||
private lateinit var activity: SearchActivity
|
||||
|
||||
|
||||
@Mock
|
||||
private lateinit var mockContext: Context
|
||||
|
||||
|
||||
@Mock
|
||||
private lateinit var mockSharedPreferences: SharedPreferences
|
||||
|
||||
|
||||
@Mock
|
||||
private lateinit var mockSharedPreferencesEditor: SharedPreferences.Editor
|
||||
private lateinit var mockSharedPreferencesEditor: SharedPreferences.Editor
|
||||
|
||||
private lateinit var binding: FragmentMediaDetailBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
|
|
@ -221,19 +234,19 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnActivityResultLocationPickerActivity() {
|
||||
fragment.onActivityResult(REQUEST_CODE, Activity.RESULT_CANCELED, intent)
|
||||
fragment.onActivityResult(requestCode, Activity.RESULT_CANCELED, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `test OnActivity Result Cancelled LocationPickerActivity`() {
|
||||
fragment.onActivityResult(REQUEST_CODE, Activity.RESULT_CANCELED, intent)
|
||||
fragment.onActivityResult(requestCode, Activity.RESULT_CANCELED, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun `test OnActivity Result Cancelled DescriptionEditActivity`() {
|
||||
fragment.onActivityResult(REQUEST_CODE, Activity.RESULT_OK, intent)
|
||||
fragment.onActivityResult(requestCode, Activity.RESULT_OK, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -254,7 +267,7 @@ class MediaDetailFragmentUnitTests {
|
|||
fun testOnUpdateCoordinatesClickedCurrentLocationNull() {
|
||||
`when`(media.coordinates).thenReturn(null)
|
||||
`when`(locationManager.lastLocation).thenReturn(null)
|
||||
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
|
||||
`when`(applicationKvStore.getString(lastLocation)).thenReturn("37.773972,-122.431297")
|
||||
fragment.onUpdateCoordinatesClicked()
|
||||
Mockito.verify(media, Mockito.times(1)).coordinates
|
||||
Mockito.verify(locationManager, Mockito.times(1)).lastLocation
|
||||
|
|
@ -268,7 +281,7 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testOnUpdateCoordinatesClickedNotNullValue() {
|
||||
`when`(media.coordinates).thenReturn(LatLng(-0.000001, -0.999999, 0f))
|
||||
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
|
||||
`when`(applicationKvStore.getString(lastLocation)).thenReturn("37.773972,-122.431297")
|
||||
fragment.onUpdateCoordinatesClicked()
|
||||
Mockito.verify(media, Mockito.times(3)).coordinates
|
||||
val shadowActivity: ShadowActivity = shadowOf(activity)
|
||||
|
|
@ -282,7 +295,7 @@ class MediaDetailFragmentUnitTests {
|
|||
fun testOnUpdateCoordinatesClickedCurrentLocationNotNull() {
|
||||
`when`(media.coordinates).thenReturn(null)
|
||||
`when`(locationManager.lastLocation).thenReturn(LatLng(-0.000001, -0.999999, 0f))
|
||||
`when`(applicationKvStore.getString(LAST_LOCATION)).thenReturn("37.773972,-122.431297")
|
||||
`when`(applicationKvStore.getString(lastLocation)).thenReturn("37.773972,-122.431297")
|
||||
|
||||
fragment.onUpdateCoordinatesClicked()
|
||||
Mockito.verify(locationManager, Mockito.times(3)).lastLocation
|
||||
|
|
@ -327,10 +340,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testExtractDescription() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"extractDescription",
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"extractDescription",
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "")
|
||||
}
|
||||
|
|
@ -339,9 +353,10 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testGetDescription() {
|
||||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescription"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescription",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -352,7 +367,8 @@ class MediaDetailFragmentUnitTests {
|
|||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod("getDescriptions", String::class.java)
|
||||
method.isAccessible = true
|
||||
val s = "=={{int:filedesc}}==\n" +
|
||||
val s =
|
||||
"=={{int:filedesc}}==\n" +
|
||||
"{{Information\n" +
|
||||
"|description={{en|1=Antique cash register in a cafe, Darjeeling}}\n" +
|
||||
"|date=2017-05-17 17:07:26\n" +
|
||||
|
|
@ -373,7 +389,8 @@ class MediaDetailFragmentUnitTests {
|
|||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod("getDescriptions", String::class.java)
|
||||
method.isAccessible = true
|
||||
val s = "=={{int:filedesc}}==\n" +
|
||||
val s =
|
||||
"=={{int:filedesc}}==\n" +
|
||||
"{{Information\n" +
|
||||
"|description={{en|1=[[:en:Fitzrovia Chapel|Fitzrovia Chapel]] ceiling<br/>\n" +
|
||||
"{{On Wikidata|Q17549757}}}}\n" +
|
||||
|
|
@ -396,7 +413,8 @@ class MediaDetailFragmentUnitTests {
|
|||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod("getDescriptions", String::class.java)
|
||||
method.isAccessible = true
|
||||
val s = "=={{int:filedesc}}==\n" +
|
||||
val s =
|
||||
"=={{int:filedesc}}==\n" +
|
||||
"{{Information\n" +
|
||||
"|description={{en|1=[[:en:Fitzrovia Chapel|Fitzrovia Chapel]] ceiling<br/>\n" +
|
||||
"}}{{Listed building England|1223496}}\n" +
|
||||
|
|
@ -419,13 +437,18 @@ class MediaDetailFragmentUnitTests {
|
|||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod("getDescriptions", String::class.java)
|
||||
method.isAccessible = true
|
||||
val s = "=={{int:filedesc}}==\n" +
|
||||
val s =
|
||||
"=={{int:filedesc}}==\n" +
|
||||
"{{Artwork\n" +
|
||||
" |artist = {{Creator:Filippo Peroni}} Restored by {{Creator:Adam Cuerden}}\n" +
|
||||
" |author = \n" +
|
||||
" |title = Ricchi giardini nel Palazzo di Monforte a Palermo\n" +
|
||||
" |description = {{en|''Ricchi giardini nel Palazzo di Monforte a Palermo'', set design for ''I Vespri siciliani'' act 5 (undated).}} {{it|''Ricchi giardini nel Palazzo di Monforte a Palermo'', bozzetto per ''I Vespri siciliani'' atto 5 (s.d.).}}\n" +
|
||||
" |date = {{between|1855|1878}} (Premiére of the opera and death of the artist, respectively)\n" +
|
||||
" |description = {{en|''Ricchi giardini nel Palazzo di Monforte a Palermo''," +
|
||||
" set design for ''I Vespri siciliani'' act 5 (undated).}} {{it|''Ricchi" +
|
||||
" giardini nel Palazzo di Monforte a Palermo'', bozzetto per ''I Vespri" +
|
||||
" siciliani'' atto 5 (s.d.).}}\n" +
|
||||
" |date = {{between|1855|1878}} (Premiére of the opera and death of the artist, " +
|
||||
"respectively)\n" +
|
||||
" |medium = {{technique|watercolor|and=tempera|and2=|over=paper}}\n" +
|
||||
" |dimensions = {{Size|unit=mm|height=210|width=270}}\n" +
|
||||
" |institution = {{Institution:Archivio Storico Ricordi}}\n" +
|
||||
|
|
@ -438,17 +461,28 @@ class MediaDetailFragmentUnitTests {
|
|||
" |notes = \n" +
|
||||
" |accession number = ICON000132\n" +
|
||||
" |place of creation = \n" +
|
||||
" |source = [https://www.archivioricordi.com/chi-siamo/glam-archivio-ricordi/#/ Archivio Storico Ricordi], [https://www.digitalarchivioricordi.com/it/works/display/108/Vespri_Siciliani__I Collezione Digitale Ricordi]\n" +
|
||||
" |source = [https://www.archivioricordi.com/chi-siamo/glam-archivio-ricordi/#/" +
|
||||
" Archivio Storico Ricordi], [https://www.digitalarchivioricordi.com/it/" +
|
||||
"works/display/108/Vespri_Siciliani__I Collezione Digitale Ricordi]\n" +
|
||||
" |permission={{PermissionTicket|id=2022031410007974|user=Ruthven}} \n" +
|
||||
" |other_versions = \n" +
|
||||
"* [[:File:Ricchi giardini nel Palazzo di Monforte a Palermo, bozzetto di Filippo Peroni per I Vespri siciliani (s.d.) - Archivio Storico Ricordi ICON000132 - Restoration.jpg]] - Restoration (JPEG)\n" +
|
||||
"* [[:File:Ricchi giardini nel Palazzo di Monforte a Palermo, bozzetto di Filippo Peroni per I Vespri siciliani (s.d.) - Archivio Storico Ricordi ICON000132 - Restoration.png]] - Restoration (PNG)\n" +
|
||||
"* [[:File:Ricchi giardini nel Palazzo di Monforte a Palermo, bozzetto di Filippo Peroni per I Vespri siciliani (s.d.) - Archivio Storico Ricordi ICON000132.jpg]] - Original (JPEG)\n" +
|
||||
"* [[:File:Ricchi giardini nel Palazzo di Monforte a Palermo, bozzetto di" +
|
||||
" Filippo Peroni per I Vespri siciliani (s.d.) - Archivio Storico Ricordi" +
|
||||
" ICON000132 - Restoration.jpg]] - Restoration (JPEG)\n" +
|
||||
"* [[:File:Ricchi giardini nel Palazzo di Monforte a Palermo, bozzetto di" +
|
||||
" Filippo Peroni per I Vespri siciliani (s.d.) - Archivio Storico Ricordi" +
|
||||
" ICON000132 - Restoration.png]] - Restoration (PNG)\n" +
|
||||
"* [[:File:Ricchi giardini nel Palazzo di Monforte a Palermo, bozzetto di" +
|
||||
" Filippo Peroni per I Vespri siciliani (s.d.) - Archivio Storico Ricordi" +
|
||||
" ICON000132.jpg]] - Original (JPEG)\n" +
|
||||
" |references = \n" +
|
||||
" |wikidata = \n" +
|
||||
"}}"
|
||||
val map = linkedMapOf("en" to "''Ricchi giardini nel Palazzo di Monforte a Palermo'', set design for ''I Vespri siciliani'' act 5 (undated).",
|
||||
"it" to "''Ricchi giardini nel Palazzo di Monforte a Palermo'', bozzetto per ''I Vespri siciliani'' atto 5 (s.d.).")
|
||||
val map =
|
||||
linkedMapOf(
|
||||
"en" to "''Ricchi giardini nel Palazzo di Monforte a Palermo'', set design for ''I Vespri siciliani'' act 5 (undated).",
|
||||
"it" to "''Ricchi giardini nel Palazzo di Monforte a Palermo'', bozzetto per ''I Vespri siciliani'' atto 5 (s.d.).",
|
||||
)
|
||||
Assert.assertEquals(map, method.invoke(fragment, s))
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +492,8 @@ class MediaDetailFragmentUnitTests {
|
|||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod("getDescriptions", String::class.java)
|
||||
method.isAccessible = true
|
||||
val s = "=={{int:filedesc}}==\n" +
|
||||
val s =
|
||||
"=={{int:filedesc}}==\n" +
|
||||
"{{Information\n" +
|
||||
"|Description ={{en|1=The interior of Sacred Heart RC Church, Wimbledon, London.}}\n" +
|
||||
"|Source ={{own}}\n" +
|
||||
|
|
@ -475,9 +510,10 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testGetDescriptionList() {
|
||||
`when`(media.filename).thenReturn("")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescriptionList"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescriptionList",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -486,9 +522,10 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testGetCaptions() {
|
||||
`when`(media.captions).thenReturn(mapOf(Pair("a", "b")))
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getCaptions"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getCaptions",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -497,9 +534,10 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testGetCaptionsCaseEmpty() {
|
||||
`when`(media.captions).thenReturn(mapOf())
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getCaptions"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getCaptions",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -512,9 +550,10 @@ class MediaDetailFragmentUnitTests {
|
|||
MediaDetailFragment::class.java.getDeclaredField("descriptionHtmlCode")
|
||||
field.isAccessible = true
|
||||
field.set(fragment, null)
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"setUpCaptionAndDescriptionLayout"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"setUpCaptionAndDescriptionLayout",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -557,10 +596,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testPrettyCoordinatesCaseNull() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCoordinates",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCoordinates",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -569,10 +609,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyCoordinates() {
|
||||
`when`(media.coordinates).thenReturn(LatLng(-0.000001, -0.999999, 0f))
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCoordinates",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCoordinates",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -581,10 +622,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyUploadedDateCaseNull() {
|
||||
`when`(media.dateUploaded).thenReturn(null)
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyUploadedDate",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyUploadedDate",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -593,10 +635,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyUploadedDateCaseNonNull() {
|
||||
`when`(media.dateUploaded).thenReturn(Date(2000, 1, 1))
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyUploadedDate",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyUploadedDate",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -605,10 +648,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyLicenseCaseNull() {
|
||||
`when`(media.license).thenReturn(null)
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyLicense",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyLicense",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -617,10 +661,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyLicenseCaseNonNull() {
|
||||
`when`(media.license).thenReturn("licence")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyLicense",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyLicense",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -628,10 +673,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testPrettyDiscussion() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyDiscussion",
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyDiscussion",
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "mock")
|
||||
}
|
||||
|
|
@ -639,10 +685,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testExtractCaptionDescription() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"extractCaptionDescription",
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"extractCaptionDescription",
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "mock")
|
||||
}
|
||||
|
|
@ -650,10 +697,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetDescriptions() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescriptions",
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"getDescriptions",
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "mock")
|
||||
}
|
||||
|
|
@ -662,10 +710,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyCaptionCaseEmpty() {
|
||||
`when`(media.captions).thenReturn(mapOf(Pair("a", "")))
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCaption",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCaption",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -674,10 +723,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyCaptionCaseNonEmpty() {
|
||||
`when`(media.captions).thenReturn(mapOf(Pair("a", "b")))
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCaption",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCaption",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -686,10 +736,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testPrettyCaption() {
|
||||
`when`(media.captions).thenReturn(mapOf())
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCaption",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"prettyCaption",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -697,9 +748,10 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetupImageView() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"setupImageView"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"setupImageView",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
|
|
@ -707,10 +759,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnDiscussionLoaded() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onDiscussionLoaded",
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onDiscussionLoaded",
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "")
|
||||
}
|
||||
|
|
@ -723,16 +776,25 @@ class MediaDetailFragmentUnitTests {
|
|||
`when`(media.imageUrl).thenReturn("test@example.com")
|
||||
`when`(spinner.selectedItemPosition).thenReturn(0)
|
||||
`when`(reasonListEnglishMappings?.get(spinner.selectedItemPosition)).thenReturn("TESTING")
|
||||
`when`(applicationKvStore.getBoolean(String.format(MediaDetailFragment.NOMINATING_FOR_DELETION_MEDIA,media.imageUrl
|
||||
))).thenReturn(true)
|
||||
doReturn(Single.just(true)).`when`(deleteHelper).makeDeletion(ArgumentMatchers.any(),ArgumentMatchers.any(), ArgumentMatchers.any())
|
||||
`when`(
|
||||
applicationKvStore.getBoolean(
|
||||
String.format(
|
||||
MediaDetailFragment.NOMINATING_FOR_DELETION_MEDIA,
|
||||
media.imageUrl,
|
||||
),
|
||||
),
|
||||
).thenReturn(true)
|
||||
doReturn(
|
||||
Single.just(true),
|
||||
).`when`(deleteHelper).makeDeletion(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())
|
||||
|
||||
doReturn(Single.just("")).`when`(reasonBuilder).getReason(ArgumentMatchers.any(), ArgumentMatchers.any())
|
||||
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onDeleteClicked",
|
||||
Spinner::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onDeleteClicked",
|
||||
Spinner::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, spinner)
|
||||
}
|
||||
|
|
@ -769,9 +831,10 @@ class MediaDetailFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testDisplayMediaDetails() {
|
||||
whenever(media.filename).thenReturn("File:Example.jpg")
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"displayMediaDetails"
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"displayMediaDetails",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
verify(media, times(4)).filename
|
||||
|
|
@ -780,10 +843,11 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGotoCategoryEditor() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"gotoCategoryEditor",
|
||||
String::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"gotoCategoryEditor",
|
||||
String::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, "[[Category:Test]]")
|
||||
}
|
||||
|
|
@ -791,14 +855,15 @@ class MediaDetailFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnMediaRefreshed() {
|
||||
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onMediaRefreshed",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailFragment::class.java.getDeclaredMethod(
|
||||
"onMediaRefreshed",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testOnImageBackgroundChangedWithDifferentColor() {
|
||||
val spyFragment = spy(fragment)
|
||||
|
|
@ -808,11 +873,10 @@ class MediaDetailFragmentUnitTests {
|
|||
|
||||
spyFragment.onImageBackgroundChanged(color)
|
||||
|
||||
verify(simpleDraweeView, times(1)).setBackgroundColor(color)
|
||||
verify(simpleDraweeView, times(1)).setBackgroundColor(color)
|
||||
verify(mockSharedPreferencesEditor, times(1)).putInt(anyString(), anyInt())
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testOnImageBackgroundChangedWithSameColor() {
|
||||
val spyFragment = spy(fragment)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import com.nhaarman.mockitokotlin2.verify
|
|||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.databinding.FragmentMediaDetailPagerBinding
|
||||
import fr.free.nrw.commons.explore.SearchActivity
|
||||
import io.reactivex.android.plugins.RxAndroidPlugins
|
||||
|
|
@ -77,9 +77,8 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
fun setUp() {
|
||||
RxAndroidPlugins.setMainThreadSchedulerHandler { Schedulers.trampoline() }
|
||||
RxJavaPlugins.setNewThreadSchedulerHandler { Schedulers.trampoline() }
|
||||
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
|
|
@ -111,7 +110,7 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
doReturn(menuItem).`when`(menuItem).isEnabled = any()
|
||||
doReturn(menuItem).`when`(menuItem).isVisible = any()
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
RxAndroidPlugins.reset()
|
||||
|
|
@ -152,10 +151,11 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetWallpaperCaseNull() {
|
||||
val method: Method = MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setWallpaper",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setWallpaper",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -165,22 +165,23 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
fun testSetWallpaperCaseNonNull() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(media.imageUrl).thenReturn("url")
|
||||
val method: Method = MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setWallpaper",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setWallpaper",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetAvatarCaseNull() {
|
||||
val method: Method = MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setAvatar",
|
||||
Media::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setAvatar",
|
||||
Media::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, media)
|
||||
}
|
||||
|
|
@ -237,11 +238,12 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
}
|
||||
|
||||
private fun invokeHandleBackgroundColorMenuItems(getBitmap: Callable<Bitmap>) {
|
||||
val method: Method = MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"handleBackgroundColorMenuItems",
|
||||
Callable::class.java,
|
||||
Menu::class.java
|
||||
)
|
||||
val method: Method =
|
||||
MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"handleBackgroundColorMenuItems",
|
||||
Callable::class.java,
|
||||
Menu::class.java,
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(fragment, getBitmap, menu)
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue