mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Update Test Dependency version (#4405)
* Update Version and Unit Test * fix failing tests * update robolectric
This commit is contained in:
parent
117a7805ad
commit
2f4c30416d
18 changed files with 122 additions and 82 deletions
|
|
@ -79,18 +79,15 @@ dependencies {
|
|||
//Mocking
|
||||
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
|
||||
testImplementation 'org.mockito:mockito-inline:2.13.0'
|
||||
testImplementation 'org.mockito:mockito-core:2.23.0'
|
||||
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
|
||||
testImplementation 'org.mockito:mockito-core:2.25.1'
|
||||
testImplementation "org.powermock:powermock-module-junit4:2.0.2"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:2.0.2"
|
||||
|
||||
// Unit testing
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
testImplementation 'org.robolectric:robolectric:4.3'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.robolectric:robolectric:4.5.1'
|
||||
testImplementation 'androidx.test:core:1.3.0'
|
||||
testImplementation "com.squareup.okhttp3:mockwebserver:$OKHTTP_VERSION"
|
||||
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
|
||||
testImplementation 'org.mockito:mockito-core:2.23.0'
|
||||
testImplementation "com.jraska.livedata:testing-ktx:1.1.2"
|
||||
testImplementation "androidx.arch.core:core-testing:2.1.0"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons.bookmarks.pictures
|
|||
import android.content.ContentProviderClient
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Looper.getMainLooper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.GridView
|
||||
|
|
@ -28,13 +29,16 @@ import org.powermock.reflect.Whitebox
|
|||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import org.wikipedia.AppAdapter
|
||||
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
|
||||
|
|
@ -134,6 +138,7 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetAdapter() {
|
||||
shadowOf(getMainLooper()).idle()
|
||||
val method: Method =
|
||||
BookmarkPicturesFragment::class.java.getDeclaredMethod("setAdapter", List::class.java)
|
||||
method.isAccessible = true
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import fr.free.nrw.commons.explore.paging.LoadingState
|
|||
import fr.free.nrw.commons.explore.paging.PagingDataSource
|
||||
import fr.free.nrw.commons.explore.paging.PagingDataSourceFactory
|
||||
import io.reactivex.processors.PublishProcessor
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers.instanceOf
|
||||
import org.hamcrest.CoreMatchers.instanceOf
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
|
|
@ -38,7 +38,7 @@ class PagingDataSourceFactoryTest {
|
|||
|
||||
@Test
|
||||
fun `create returns a dataSource`() {
|
||||
assertThat(
|
||||
Assert.assertThat(
|
||||
factory.create(),
|
||||
instanceOf(PagingDataSource::class.java)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
package fr.free.nrw.commons.explore.categroies
|
||||
package fr.free.nrw.commons.explore.categories
|
||||
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.category.CategoryClient
|
||||
import fr.free.nrw.commons.explore.categories.search.PageableSearchCategoriesDataSource
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PageableSearchCategoriesDataSourceTest {
|
||||
|
|
@ -18,6 +17,6 @@ class PageableSearchCategoriesDataSourceTest {
|
|||
val pageableCategoriesDataSource =
|
||||
PageableSearchCategoriesDataSource(mock(), categoryClient)
|
||||
pageableCategoriesDataSource.onQueryUpdated("test")
|
||||
assertThat(pageableCategoriesDataSource.loadFunction(0, 1), Matchers.`is`(emptyList()))
|
||||
Assert.assertEquals(pageableCategoriesDataSource.loadFunction(0, 1), emptyList<String>())
|
||||
}
|
||||
}
|
||||
|
|
@ -6,8 +6,7 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
|
@ -32,7 +31,7 @@ class PageableCategoriesMediaDataSourceTest {
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(mediaClient.getMediaListFromCategory("test"))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
assertThat(dataSource.loadFunction(-1, 0), `is`(emptyList()))
|
||||
Assert.assertEquals(dataSource.loadFunction(-1, 0), emptyList<String>())
|
||||
verify(mediaClient).resetCategoryContinuation("test")
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +42,7 @@ class PageableCategoriesMediaDataSourceTest {
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(mediaClient.getMediaListFromCategory("test"))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
assertThat(dataSource.loadFunction(-1, 1), `is`(emptyList()))
|
||||
Assert.assertEquals(dataSource.loadFunction(-1, 1), emptyList<String>())
|
||||
verify(mediaClient, never()).resetCategoryContinuation("test")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||
import fr.free.nrw.commons.category.CategoryClient
|
||||
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
|
@ -31,7 +30,7 @@ class PageableParentCategoriesDataSourceTest{
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(categoryClient.getParentCategoryList("test"))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
assertThat(dataSource.loadFunction(-1, 0), `is`(emptyList()))
|
||||
Assert.assertEquals(dataSource.loadFunction(-1, 0), emptyList<String>())
|
||||
verify(categoryClient).resetParentCategoryContinuation("test")
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +41,7 @@ class PageableParentCategoriesDataSourceTest{
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(categoryClient.getParentCategoryList("test"))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
assertThat(dataSource.loadFunction(-1, 1), `is`(emptyList()))
|
||||
Assert.assertEquals(dataSource.loadFunction(-1, 1), emptyList<String>())
|
||||
verify(categoryClient, never()).resetParentCategoryContinuation("test")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import com.nhaarman.mockitokotlin2.whenever
|
|||
import fr.free.nrw.commons.category.CategoryClient
|
||||
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
|
@ -31,7 +30,7 @@ class PageableSubCategoriesDataSourceTest{
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(categoryClient.getSubCategoryList("test"))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
assertThat(dataSource.loadFunction(-1, 0), `is`(emptyList()))
|
||||
Assert.assertEquals(dataSource.loadFunction(-1, 0), emptyList<String>())
|
||||
verify(categoryClient).resetSubCategoryContinuation("test")
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +41,7 @@ class PageableSubCategoriesDataSourceTest{
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(categoryClient.getSubCategoryList("test"))
|
||||
.thenReturn(Single.just(emptyList()))
|
||||
assertThat(dataSource.loadFunction(-1, 1), `is`(emptyList()))
|
||||
Assert.assertEquals(dataSource.loadFunction(-1, 1), emptyList<String>())
|
||||
verify(categoryClient, never()).resetSubCategoryContinuation("test")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import com.nhaarman.mockitokotlin2.mock
|
|||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.explore.depictions.search.PageableDepictionsDataSource
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PageableDepictionsDataSourceTest {
|
||||
|
|
@ -17,9 +16,9 @@ class PageableDepictionsDataSourceTest {
|
|||
.thenReturn(Single.just(emptyList()))
|
||||
val pageableDepictionsDataSource = PageableDepictionsDataSource(mock(), depictsClient)
|
||||
pageableDepictionsDataSource.onQueryUpdated("test")
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
pageableDepictionsDataSource.loadFunction.invoke(0, 1),
|
||||
Matchers.`is`(emptyList())
|
||||
emptyList<String>()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ import depictedItem
|
|||
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
|
@ -30,6 +29,6 @@ class PageableChildDepictionsDataSourceTest {
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(okHttpJsonApiClient.getChildDepictions("test", 0, 1))
|
||||
.thenReturn(Single.just(listOf(depictedItem())))
|
||||
assertThat(dataSource.loadFunction(1, 0), `is`(listOf(depictedItem())))
|
||||
Assert.assertEquals(dataSource.loadFunction(1, 0), listOf(depictedItem()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import com.nhaarman.mockitokotlin2.mock
|
|||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers.`is`
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PageableDepictedMediaDataSourceTest{
|
||||
|
|
@ -16,6 +15,6 @@ class PageableDepictedMediaDataSourceTest{
|
|||
.thenReturn(Single.just(emptyList()))
|
||||
val pageableDepictedMediaDataSource = PageableDepictedMediaDataSource(mock(), mediaClient)
|
||||
pageableDepictedMediaDataSource.onQueryUpdated("test")
|
||||
assertThat(pageableDepictedMediaDataSource.loadFunction(0,1), `is`(emptyList()))
|
||||
Assert.assertEquals(pageableDepictedMediaDataSource.loadFunction(0,1), emptyList<String>())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ import depictedItem
|
|||
import fr.free.nrw.commons.explore.paging.LiveDataConverter
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
|
@ -31,7 +30,7 @@ class PageableParentDepictionsDataSourceTest {
|
|||
dataSource.onQueryUpdated("test")
|
||||
whenever(okHttpJsonApiClient.getParentDepictions("test", 0, 1))
|
||||
.thenReturn(Single.just(listOf(depictedItem())))
|
||||
assertThat(dataSource.loadFunction(1, 0), `is`(listOf(depictedItem())))
|
||||
Assert.assertEquals(dataSource.loadFunction(1, 0), listOf(depictedItem()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import com.nhaarman.mockitokotlin2.mock
|
|||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import io.reactivex.Single
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers.`is`
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
|
|
@ -28,6 +27,6 @@ class PageableMediaDataSourceTest {
|
|||
.thenReturn(Single.just(emptyList()))
|
||||
val pageableMediaDataSource = PageableMediaDataSource(mock(), mediaClient)
|
||||
pageableMediaDataSource.onQueryUpdated("test")
|
||||
assertThat(pageableMediaDataSource.loadFunction(0,1), `is`(emptyList()))
|
||||
Assert.assertEquals(pageableMediaDataSource.loadFunction(0,1), emptyList<String>())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.media
|
|||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
|
|
@ -23,13 +24,16 @@ import org.mockito.MockitoAnnotations
|
|||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import org.wikipedia.AppAdapter
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class MediaDetailPagerFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: MediaDetailPagerFragment
|
||||
|
|
@ -98,6 +102,7 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreateSaveInstanceNotNull() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onCreate(outState)
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +126,7 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetWallpaperCaseNonNull() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
`when`(media.imageUrl).thenReturn("url")
|
||||
val method: Method = MediaDetailPagerFragment::class.java.getDeclaredMethod(
|
||||
"setWallpaper",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.navtab
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
|
|
@ -12,10 +13,13 @@ import org.junit.runner.RunWith
|
|||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class MoreBottomSheetFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: MoreBottomSheetFragment
|
||||
|
|
@ -45,48 +49,56 @@ class MoreBottomSheetFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnAttach() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onAttach(context)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnLogoutClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onLogoutClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnFeedbackClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onFeedbackClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnAboutClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onAboutClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnTutorialClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onTutorialClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSettingsClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onSettingsClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnProfileClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onProfileClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnPeerReviewClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onPeerReviewClicked()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.navtab
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
|
|
@ -12,10 +13,13 @@ import org.junit.runner.RunWith
|
|||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class MoreBottomSheetLoggedOutFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: MoreBottomSheetLoggedOutFragment
|
||||
|
|
@ -45,30 +49,35 @@ class MoreBottomSheetLoggedOutFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnTutorialClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onTutorialClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnSettingsClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onSettingsClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnAboutClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onAboutClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnFeedbackClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onFeedbackClicked()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnLogoutClicked() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onLogoutClicked()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.profile.achievements
|
|||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Looper
|
||||
import android.view.MenuItem
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
|
|
@ -22,7 +23,9 @@ import org.powermock.reflect.Whitebox
|
|||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import org.robolectric.fakes.RoboMenuItem
|
||||
import org.wikipedia.AppAdapter
|
||||
import java.lang.reflect.Method
|
||||
|
|
@ -30,6 +33,7 @@ import java.lang.reflect.Method
|
|||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class AchievementsFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: AchievementsFragment
|
||||
|
|
@ -142,6 +146,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowAlert() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showAlert(bitmap)
|
||||
}
|
||||
|
||||
|
|
@ -149,60 +154,70 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowInfoDialog() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showInfoDialog()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowUploadInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showUploadInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowRevertedInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showRevertedInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowUsedByWikiInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showUsedByWikiInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowImagesViaNearbyInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showImagesViaNearbyInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowFeaturedImagesInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showFeaturedImagesInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowThanksReceivedInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showThanksReceivedInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowQualityImagesInfo() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.showQualityImagesInfo()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnOptionsItemSelected() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
fragment.onOptionsItemSelected(menuItem)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchAlert() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"launchAlert",
|
||||
String::class.java,
|
||||
|
|
@ -215,6 +230,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHideProgressBar() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"hideProgressBar",
|
||||
Achievements::class.java
|
||||
|
|
@ -226,6 +242,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetAchievementsUploadCount() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"setAchievementsUploadCount",
|
||||
Achievements::class.java,
|
||||
|
|
@ -238,6 +255,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testCheckAccount() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"checkAccount"
|
||||
)
|
||||
|
|
@ -248,6 +266,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetUploadCount() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"setUploadCount",
|
||||
Achievements::class.java
|
||||
|
|
@ -259,6 +278,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnError() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"onError"
|
||||
)
|
||||
|
|
@ -269,6 +289,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowSnackBarWithRetryTrue() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"showSnackBarWithRetry", Boolean::class.java
|
||||
)
|
||||
|
|
@ -279,6 +300,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowSnackBarWithRetryFalse() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"showSnackBarWithRetry", Boolean::class.java
|
||||
)
|
||||
|
|
@ -289,6 +311,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetWikidataEditCount() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"setWikidataEditCount"
|
||||
)
|
||||
|
|
@ -299,6 +322,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetAchievements() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"setAchievements"
|
||||
)
|
||||
|
|
@ -309,6 +333,7 @@ class AchievementsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShareScreen() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
|
||||
"shareScreen", Bitmap::class.java
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ import depictedItem
|
|||
import entity
|
||||
import entityId
|
||||
import fr.free.nrw.commons.wikidata.WikidataProperties
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.CoreMatchers.not
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers.nullValue
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import place
|
||||
import snak
|
||||
|
|
@ -22,37 +19,37 @@ class DepictedItemTest {
|
|||
fun `name and description get user language label`() {
|
||||
val depictedItem =
|
||||
DepictedItem(entity(mapOf("en" to "label"), mapOf("en" to "description")))
|
||||
assertThat(depictedItem.name, `is`("label"))
|
||||
assertThat(depictedItem.description, `is`("description"))
|
||||
Assert.assertEquals(depictedItem.name, "label")
|
||||
Assert.assertEquals(depictedItem.description, "description")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `name and descriptions get first language label if user language not present`() {
|
||||
val depictedItem = DepictedItem(entity(mapOf("" to "label"), mapOf("" to "description")))
|
||||
assertThat(depictedItem.name, `is`("label"))
|
||||
assertThat(depictedItem.description, `is`("description"))
|
||||
Assert.assertEquals(depictedItem.name, "label")
|
||||
Assert.assertEquals(depictedItem.description, "description")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `name and descriptions get empty if nothing present`() {
|
||||
val depictedItem = DepictedItem(entity())
|
||||
assertThat(depictedItem.name, `is`(""))
|
||||
assertThat(depictedItem.description, `is`(""))
|
||||
Assert.assertEquals(depictedItem.name, "")
|
||||
Assert.assertEquals(depictedItem.description, "")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `image is empty with null statements`() {
|
||||
assertThat(DepictedItem(entity(statements = null)).imageUrl, nullValue())
|
||||
Assert.assertEquals(DepictedItem(entity(statements = null)).imageUrl, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `image is empty with no image statement`() {
|
||||
assertThat(DepictedItem(entity()).imageUrl, nullValue())
|
||||
Assert.assertEquals(DepictedItem(entity()).imageUrl, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `image is empty with dataValue not of ValueString type`() {
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
DepictedItem(
|
||||
entity(
|
||||
statements = mapOf(
|
||||
|
|
@ -60,13 +57,13 @@ class DepictedItemTest {
|
|||
)
|
||||
)
|
||||
).imageUrl,
|
||||
nullValue()
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `image is not empty with dataValue of ValueString type`() {
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
DepictedItem(
|
||||
entity(
|
||||
statements = mapOf(
|
||||
|
|
@ -76,13 +73,12 @@ class DepictedItemTest {
|
|||
)
|
||||
)
|
||||
).imageUrl,
|
||||
`is`("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/_example_/70px-_example_")
|
||||
)
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/_example_/70px-_example_")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `instancesOf maps EntityIds to ids`() {
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
DepictedItem(
|
||||
entity(
|
||||
statements = mapOf(
|
||||
|
|
@ -94,17 +90,17 @@ class DepictedItemTest {
|
|||
)
|
||||
)
|
||||
).instanceOfs,
|
||||
`is`(listOf("1", "2")))
|
||||
listOf("1", "2"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `instancesOf is empty with no values`() {
|
||||
assertThat(DepictedItem(entity()).instanceOfs, `is`(emptyList()))
|
||||
Assert.assertEquals(DepictedItem(entity()).instanceOfs, emptyList<String>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `commonsCategory maps ValueString to strings`() {
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
DepictedItem(
|
||||
entity(
|
||||
statements = mapOf(
|
||||
|
|
@ -115,64 +111,64 @@ class DepictedItemTest {
|
|||
)
|
||||
)
|
||||
).commonsCategories,
|
||||
`is`(listOf("1", "2")))
|
||||
listOf("1", "2"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `commonsCategory is empty with no values`() {
|
||||
assertThat(DepictedItem(entity()).commonsCategories, `is`(emptyList()))
|
||||
Assert.assertEquals(DepictedItem(entity()).commonsCategories, emptyList<String>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isSelected is false at creation`() {
|
||||
assertThat(DepictedItem(entity()).isSelected, `is`(false))
|
||||
Assert.assertEquals(DepictedItem(entity()).isSelected, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `id is entityId`() {
|
||||
assertThat(DepictedItem(entity(id = "1")).id, `is`("1"))
|
||||
Assert.assertEquals(DepictedItem(entity(id = "1")).id, "1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `place constructor uses place name and longDescription`() {
|
||||
val depictedItem = DepictedItem(entity(), place(name = "1", longDescription = "2"))
|
||||
assertThat(depictedItem.name, `is`("1"))
|
||||
assertThat(depictedItem.description, `is`("2"))
|
||||
Assert.assertEquals(depictedItem.name, "1")
|
||||
Assert.assertEquals(depictedItem.description, "2")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `same object is Equal`() {
|
||||
val depictedItem = depictedItem()
|
||||
assertThat(depictedItem == depictedItem, `is`(true))
|
||||
Assert.assertEquals(depictedItem == depictedItem, true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `different type is not Equal`() {
|
||||
assertThat(depictedItem().equals(Unit), `is`(false))
|
||||
Assert.assertEquals(depictedItem().equals(Unit), false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `if names are equal is Equal`() {
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
depictedItem(name="a", id = "0") == depictedItem(name="a", id = "1"),
|
||||
`is`(true))
|
||||
true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `if names are not equal is not Equal`() {
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
depictedItem(name="a") == depictedItem(name="b"),
|
||||
`is`(false))
|
||||
false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hashCode returns same values for objects with same name`() {
|
||||
assertThat(depictedItem(name="a").hashCode(), `is`(depictedItem(name="a").hashCode()))
|
||||
Assert.assertEquals(depictedItem(name="a").hashCode(), depictedItem(name="a").hashCode())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `hashCode returns different values for objects with different name`() {
|
||||
assertThat(depictedItem(name="a").hashCode(), not(depictedItem(name="b").hashCode()))
|
||||
Assert.assertNotEquals(depictedItem(name="a").hashCode(), depictedItem(name="b").hashCode())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import org.hamcrest.core.IsEqual.equalTo
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class CommonsDateUtilTest {
|
||||
|
|
@ -12,9 +11,9 @@ class CommonsDateUtilTest {
|
|||
.getIso8601DateFormatTimestamp()
|
||||
val parsedDate = iso8601DateFormatTimestamp
|
||||
.parse("2020-04-07T14:21:57Z")
|
||||
assertThat(
|
||||
Assert.assertEquals(
|
||||
"2020-04-07T14:21:57Z",
|
||||
equalTo(iso8601DateFormatTimestamp.format(parsedDate))
|
||||
iso8601DateFormatTimestamp.format(parsedDate)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue