Skip to content

Commit

Permalink
chore: KotlinCleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
david-allison authored and BrayanDSO committed May 4, 2024
1 parent a74f1a0 commit 905a407
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import org.json.JSONObject
import org.junit.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Assume.*
Expand Down Expand Up @@ -1144,12 +1143,10 @@ class ContentProviderTest : InstrumentedTest() {
val noteId = card.nid
val cardOrd = card.ord

@KotlinCleanup("rename, while valid suspend is a kotlin soft keyword")
val values = ContentValues().apply {
val suspend = 1
put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId)
put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd)
put(FlashCardsContract.ReviewInfo.SUSPEND, suspend)
put(FlashCardsContract.ReviewInfo.SUSPEND, 1)
}
val updateCount = cr.update(reviewInfoUri, values, null, null)
assertEquals("Check if update returns 1", 1, updateCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class NotificationChannelTest : InstrumentedTest() {
private var currentAPI = -1
private var targetAPI = -1

@KotlinCleanup("lateinit")
private var manager: NotificationManager? = null
private lateinit var manager: NotificationManager

@Before
@UiThreadTest
Expand All @@ -55,8 +54,7 @@ class NotificationChannelTest : InstrumentedTest() {
(targetContext.applicationContext as AnkiDroidApp).onCreate()
currentAPI = sdkVersion
targetAPI = targetContext.applicationInfo.targetSdkVersion
manager =
targetContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager = targetContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}

private fun channelsInAPI(): Boolean {
Expand All @@ -68,7 +66,7 @@ class NotificationChannelTest : InstrumentedTest() {
if (!channelsInAPI()) return

// onCreate was called in setUp(), so we should have channels now
val channels = manager!!.notificationChannels
val channels = manager.notificationChannels
for (i in channels.indices) {
Timber.d("Found channel with id %s", channels[i].id)
}
Expand All @@ -92,7 +90,7 @@ class NotificationChannelTest : InstrumentedTest() {
for (channel in Channel.entries) {
assertNotNull(
"There should be a reminder channel",
manager!!.getNotificationChannel(channel.id)
manager.getNotificationChannel(channel.id)
)
}
}
Expand Down
26 changes: 10 additions & 16 deletions AnkiDroid/src/main/java/com/ichi2/utils/JSONArray.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ fun JSONArray.jsonObjectIterable(): Iterable<JSONObject> {
@KotlinCleanup("see if jsonObject/string/longIterator() methods can be combined into one")
fun JSONArray.jsonObjectIterator(): Iterator<JSONObject> {
return object : Iterator<JSONObject> {
private var mIndex = 0
private var index = 0
override fun hasNext(): Boolean {
return mIndex < length()
return index < length()
}

override fun next(): JSONObject {
val `object` = getJSONObject(mIndex)
mIndex++
val `object` = getJSONObject(index)
index++
return `object`
}
}
Expand All @@ -84,14 +84,14 @@ fun JSONArray.stringIterable(): Iterable<String> {

fun JSONArray.stringIterator(): Iterator<String> {
return object : Iterator<String> {
private var mIndex = 0
private var index = 0
override fun hasNext(): Boolean {
return mIndex < length()
return index < length()
}

override fun next(): String {
val string = getString(mIndex)
mIndex++
val string = getString(index)
index++
return string
}
}
Expand All @@ -101,11 +101,5 @@ fun JSONArray.stringIterator(): Iterator<String> {
* @return Given an array of objects, return the array of the value with `key`, assuming that they are String.
* E.g. templates, fields are a JSONArray whose objects have name
*/
@KotlinCleanup("simplify fun with apply and forEach")
fun JSONArray.toStringList(key: String?): List<String> {
val l: MutableList<String> = ArrayList(length())
for (`object` in jsonObjectIterable()) {
l.add(`object`.getString(key!!))
}
return l
}
fun JSONArray.toStringList(key: String): List<String> =
jsonObjectIterable().map { it.getString(key) }
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.ichi2.libanki
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.libanki.sched.Counts
import com.ichi2.testutils.JvmTest
import com.ichi2.utils.KotlinCleanup
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.json.JSONArray
Expand All @@ -27,10 +26,6 @@ import org.junit.runner.RunWith
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

// Note: These tests can't be run individually but can from the class-level
// gradlew AnkiDroid:testDebug --tests "com.ichi2.libanki.AbstractSchedTest.*"
@KotlinCleanup("reduce newlines in asserts")
@KotlinCleanup("improve increaseAndAssertNewCountsIs")
@RunWith(AndroidJUnit4::class)
class AbstractSchedTest : JvmTest() {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class UniqueArrayListTest {
}

@Test
@KotlinCleanup("")
fun test_Sorting() {
val longs = mutableListOf(10, 9, 7, 3, 2, -1, 5, 1, 65, -656)
val uniqueList = UniqueArrayList.from(longs)
Expand Down

0 comments on commit 905a407

Please sign in to comment.