mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +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
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue