Convert top level "Utils" class to kotlin (#6364)

* Unused class removed

* Convert BasePresenter to kotlin

* Removed redundent class

* Move the Utils class into the utils package

* Inline the creation of a page title object

* Move license utilities into their own file

* Inline app rating since its only ever used in 1 place

* Moved GeoCoordinates utilities into their own class

* Moved Monuments related utils into their own class

* Moved screen capture into its own util class

* Moved handleWebUrl to its own utility class

* Moved fixExtension to its own class

* Moved clipboard copy into its own utility class

* Renames class to match remaining utility method

* Convert UnderlineUtils to kotlin

* Converted the copy-to-clipboard utility to kotlin

* Converted license name and url lookup to kotlin

* Converted fixExtension to kotlin

* Convert handleGeoCoordinates to kotlin

* Monument utils converted to kotlin

* Convert then inline screeen capture in kotlin

* Convert handleWebUrl to kotlin
This commit is contained in:
Paul Hawke 2025-07-04 06:18:52 -05:00 committed by GitHub
parent 4befff8f42
commit 3bd0ec4466
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 387 additions and 519 deletions

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons
import fr.free.nrw.commons.utils.getWikiLovesMonumentsYear
import org.junit.Test
import org.junit.jupiter.api.Assertions
import java.util.Calendar
@ -9,20 +10,20 @@ class UtilsTest {
fun wikiLovesMonumentsYearBeforeSeptember() {
val cal = Calendar.getInstance()
cal.set(2022, Calendar.FEBRUARY, 1)
Assertions.assertEquals(2021, Utils.getWikiLovesMonumentsYear(cal))
Assertions.assertEquals(2021, getWikiLovesMonumentsYear(cal))
}
@Test
fun wikiLovesMonumentsYearInSeptember() {
val cal = Calendar.getInstance()
cal.set(2022, Calendar.SEPTEMBER, 1)
Assertions.assertEquals(2022, Utils.getWikiLovesMonumentsYear(cal))
Assertions.assertEquals(2022, getWikiLovesMonumentsYear(cal))
}
@Test
fun wikiLovesMonumentsYearAfterSeptember() {
val cal = Calendar.getInstance()
cal.set(2022, Calendar.DECEMBER, 1)
Assertions.assertEquals(2022, Utils.getWikiLovesMonumentsYear(cal))
Assertions.assertEquals(2022, getWikiLovesMonumentsYear(cal))
}
}

View file

@ -248,13 +248,6 @@ class ContributionsFragmentUnitTests {
fragment.onDestroyView()
}
@Test
@Throws(Exception::class)
fun testShowMessage() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.showMessage("")
}
@Test
@Throws(Exception::class)
fun testShowCampaigns() {

View file

@ -1,11 +1,12 @@
package fr.free.nrw.commons.upload
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.Utils
import fr.free.nrw.commons.utils.UnderlineUtils
import fr.free.nrw.commons.kvstore.JsonKvStore
import fr.free.nrw.commons.repository.UploadRepository
import fr.free.nrw.commons.upload.license.MediaLicenseContract
import fr.free.nrw.commons.upload.license.MediaLicensePresenter
import fr.free.nrw.commons.utils.toLicenseName
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -25,7 +26,7 @@ import org.robolectric.RobolectricTestRunner
*/
@RunWith(RobolectricTestRunner::class)
@PrepareForTest(Utils::class)
@PrepareForTest(UnderlineUtils::class)
class MediaLicensePresenterTest {
@Mock
internal lateinit var repository: UploadRepository
@ -39,7 +40,7 @@ class MediaLicensePresenterTest {
@InjectMocks
lateinit var mediaLicensePresenter: MediaLicensePresenter
private lateinit var mockedUtil: MockedStatic<Utils>
private lateinit var mockedUtil: MockedStatic<UnderlineUtils>
/**
* initial setup test environemnt
@ -49,8 +50,7 @@ class MediaLicensePresenterTest {
fun setUp() {
MockitoAnnotations.openMocks(this)
mediaLicensePresenter.onAttachView(view)
mockedUtil = Mockito.mockStatic(Utils::class.java)
`when`(Utils.licenseNameFor(ArgumentMatchers.anyString())).thenReturn(1)
mockedUtil = Mockito.mockStatic(UnderlineUtils::class.java)
}
@After

View file

@ -1,6 +1,5 @@
package fr.free.nrw.commons.utils
import fr.free.nrw.commons.Utils.fixExtension
import org.junit.Assert.assertEquals
import org.junit.Test