Code cleanups

This commit is contained in:
Goooler
2021-08-19 02:51:52 +08:00
committed by GitHub
parent ce78d34c14
commit 2572c29e42
8 changed files with 15 additions and 26 deletions

View File

@@ -47,7 +47,7 @@ class JsonClassCodegenProcessorTest {
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
class PrivateConstructor private constructor(var a: Int, var b: Int) {
class PrivateConstructor private constructor(val a: Int, val b: Int) {
fun a() = a
fun b() = b
companion object {

View File

@@ -27,7 +27,6 @@ import com.squareup.moshi.internal.Util.resolve
import com.squareup.moshi.rawType
import java.lang.reflect.Modifier
import java.lang.reflect.Type
import java.util.AbstractMap.SimpleEntry
import kotlin.reflect.KFunction
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KParameter

View File

@@ -437,10 +437,7 @@ class GeneratedAdaptersTest {
}
@JsonClass(generateAdapter = true)
class ImmutableProperties(a: Int, b: Int) {
val a = a
val b = b
}
class ImmutableProperties(val a: Int, val b: Int)
@Test fun constructorDefaults() {
val moshi = Moshi.Builder().build()

View File

@@ -115,10 +115,7 @@ class KotlinJsonAdapterTest {
assertThat(decoded.b).isEqualTo(5)
}
class ImmutableProperties(a: Int, b: Int) {
val a = a
val b = b
}
class ImmutableProperties(val a: Int, val b: Int)
@Test fun constructorDefaults() {
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
@@ -432,13 +429,13 @@ class KotlinJsonAdapterTest {
val decoded = jsonAdapter.fromJson("""{"a":4,"buf":[0,0],"size":0}""")!!
assertThat(decoded.a).isEqualTo(4)
assertThat(decoded.buf()).isEqualTo(ByteArray(2, { 0 }))
assertThat(decoded.buf()).isEqualTo(ByteArray(2) { 0 })
assertThat(decoded.count()).isEqualTo(0)
}
internal class ExtendsPlatformClassWithProtectedField(var a: Int) : ByteArrayOutputStream(2) {
fun buf() = buf
fun count() = count
fun buf(): ByteArray = buf
fun count(): Int = count
}
@Test fun platformTypeThrows() {