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:
tristan 2024-09-19 14:56:45 +10:00 committed by GitHub
parent 950539c55c
commit 2d82a430c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
405 changed files with 11032 additions and 9137 deletions

View file

@ -5,7 +5,6 @@ import android.graphics.Bitmap
import android.os.Looper
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.widget.Toolbar
import androidx.test.core.app.ApplicationProvider
import fr.free.nrw.commons.R
import fr.free.nrw.commons.TestCommonsApplication
@ -23,11 +22,9 @@ import org.robolectric.fakes.RoboMenu
import org.robolectric.fakes.RoboMenuItem
import java.lang.reflect.Method
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class ProfileActivityTest {
@Mock
private lateinit var activity: ProfileActivity
@ -95,9 +92,11 @@ class ProfileActivityTest {
@Throws(Exception::class)
fun testShareScreen() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = ProfileActivity::class.java.getDeclaredMethod(
"shareScreen", Bitmap::class.java
)
val method: Method =
ProfileActivity::class.java.getDeclaredMethod(
"shareScreen",
Bitmap::class.java,
)
method.isAccessible = true
method.invoke(activity, bitmap)
}
@ -107,6 +106,7 @@ class ProfileActivityTest {
fun testOnSupportNavigateUp() {
activity.onSupportNavigateUp()
}
@Test
fun testToolbarNotNull() {
val toolbar = activity.binding.toolbarBinding.toolbar
@ -119,5 +119,4 @@ class ProfileActivityTest {
activity.onCreateOptionsMenu(menu)
Assert.assertEquals(1, menu.size())
}
}

View file

@ -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.SessionManager
import fr.free.nrw.commons.createTestClient
import fr.free.nrw.commons.profile.ProfileActivity
import fr.free.nrw.commons.utils.ConfigUtils
import org.junit.Assert
@ -34,12 +34,10 @@ import org.robolectric.fakes.RoboMenuItem
import org.robolectric.shadows.ShadowToast
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
private lateinit var context: Context
@ -73,7 +71,7 @@ class AchievementsFragmentUnitTests {
context = ApplicationProvider.getApplicationContext()
menuItem = RoboMenuItem(context)
OkHttpConnectionFactory.CLIENT = createTestClient()
val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
val fragmentManager: FragmentManager = activity.supportFragmentManager
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
@ -165,11 +163,12 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testLaunchAlert() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"launchAlert",
String::class.java,
String::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"launchAlert",
String::class.java,
String::class.java,
)
method.isAccessible = true
method.invoke(fragment, "", "")
}
@ -178,10 +177,11 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testHideProgressBar() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"hideProgressBar",
Achievements::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"hideProgressBar",
Achievements::class.java,
)
method.isAccessible = true
method.invoke(fragment, achievements)
}
@ -190,11 +190,12 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testSetAchievementsUploadCount() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"setAchievementsUploadCount",
Achievements::class.java,
Int::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"setAchievementsUploadCount",
Achievements::class.java,
Int::class.java,
)
method.isAccessible = true
method.invoke(fragment, achievements, 0)
}
@ -203,9 +204,10 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testCheckAccount() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"checkAccount"
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"checkAccount",
)
method.isAccessible = true
method.invoke(fragment)
}
@ -214,10 +216,11 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testSetUploadCount() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"setUploadCount",
Achievements::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"setUploadCount",
Achievements::class.java,
)
method.isAccessible = true
method.invoke(fragment, achievements)
}
@ -226,9 +229,10 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testOnError() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"onError"
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"onError",
)
method.isAccessible = true
method.invoke(fragment)
}
@ -237,9 +241,11 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testShowSnackBarWithRetryTrue() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"showSnackBarWithRetry", Boolean::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"showSnackBarWithRetry",
Boolean::class.java,
)
method.isAccessible = true
method.invoke(fragment, true)
}
@ -248,9 +254,11 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testShowSnackBarWithRetryFalse() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"showSnackBarWithRetry", Boolean::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"showSnackBarWithRetry",
Boolean::class.java,
)
method.isAccessible = true
method.invoke(fragment, false)
}
@ -259,9 +267,10 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testSetWikidataEditCount() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"setWikidataEditCount"
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"setWikidataEditCount",
)
method.isAccessible = true
method.invoke(fragment)
}
@ -270,9 +279,10 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testSetAchievements() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"setAchievements"
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"setAchievements",
)
method.isAccessible = true
method.invoke(fragment)
}
@ -281,10 +291,11 @@ class AchievementsFragmentUnitTests {
@Throws(Exception::class)
fun testMenuVisibilityOverrideNotVisible() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"setMenuVisibility",
Boolean::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"setMenuVisibility",
Boolean::class.java,
)
method.isAccessible = true
method.invoke(fragment, false)
assertToast()
@ -295,10 +306,11 @@ class AchievementsFragmentUnitTests {
fun testMenuVisibilityOverrideVisibleWithContext() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
Mockito.`when`(parentView.context).thenReturn(context)
val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
"setMenuVisibility",
Boolean::class.java
)
val method: Method =
AchievementsFragment::class.java.getDeclaredMethod(
"setMenuVisibility",
Boolean::class.java,
)
method.isAccessible = true
method.invoke(fragment, true)
assertToast()
@ -308,14 +320,13 @@ class AchievementsFragmentUnitTests {
if (ConfigUtils.isBetaFlavour) {
Assert.assertEquals(
ShadowToast.getTextOfLatestToast().toString(),
context.getString(R.string.achievements_unavailable_beta)
context.getString(R.string.achievements_unavailable_beta),
)
} else {
Assert.assertEquals(
context.getString(R.string.user_not_logged_in),
ShadowToast.getTextOfLatestToast().toString()
ShadowToast.getTextOfLatestToast().toString(),
)
}
}
}
}

View file

@ -11,15 +11,14 @@ import org.mockito.MockitoAnnotations
* Test for the Level Controller Class for Achievements
*/
class LevelControllerTest {
@Mock
private lateinit var levelController: LevelController
private val IMAGES_UPLOADED_SAMPLE_VALUE = 0
private val imagesUploadedSampleValue = 0
private val UNIQUE_IMAGES_USED_SAMPLE_VALUE = 0
private val uniqueImagesUsedSampleValue = 0
private val NON_REVERT_RATE_SAMPLE_VALUE = 0
private val nonRevertRateSampleValue = 0
private lateinit var levelInfo: LevelController.LevelInfo
@ -30,11 +29,12 @@ class LevelControllerTest {
fun setUp() {
MockitoAnnotations.openMocks(this)
levelController = LevelController()
levelInfo = LevelController.LevelInfo.from(
IMAGES_UPLOADED_SAMPLE_VALUE,
UNIQUE_IMAGES_USED_SAMPLE_VALUE,
NON_REVERT_RATE_SAMPLE_VALUE
)
levelInfo =
LevelController.LevelInfo.from(
imagesUploadedSampleValue,
uniqueImagesUsedSampleValue,
nonRevertRateSampleValue,
)
}
/**
@ -79,4 +79,4 @@ class LevelControllerTest {
fun testMinNonRevertPercentage() {
assertEquals(levelInfo.minNonRevertPercentage, 85)
}
}
}