From 37bbefe37ae602966f869606fbc49c4eafd092cf Mon Sep 17 00:00:00 2001 From: oboenikui Date: Sat, 29 Jul 2023 21:26:51 +0900 Subject: [PATCH 1/2] fill CharSequence param as String --- .../kotlinfillclass/inspections/BaseFillClassInspection.kt | 4 +++- .../kotlinfillclass/inspections/FillDummyValuesInspection.kt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/BaseFillClassInspection.kt b/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/BaseFillClassInspection.kt index e0ac44c..69d7093 100644 --- a/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/BaseFillClassInspection.kt +++ b/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/BaseFillClassInspection.kt @@ -328,7 +328,9 @@ open class FillClassFix( KotlinBuiltIns.isCollectionOrNullableCollection(type) -> "arrayOf()" KotlinBuiltIns.isNullableAny(type) -> "null" - KotlinBuiltIns.isString(type) -> "\"\"" + KotlinBuiltIns.isCharSequence(type) || + KotlinBuiltIns.isString(type) -> "\"\"" + KotlinBuiltIns.isListOrNullableList(type) -> "listOf()" KotlinBuiltIns.isSetOrNullableSet(type) -> "setOf()" KotlinBuiltIns.isMapOrNullableMap(type) -> "mapOf()" diff --git a/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValuesInspection.kt b/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValuesInspection.kt index 52402df..ded6ff3 100644 --- a/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValuesInspection.kt +++ b/src/main/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValuesInspection.kt @@ -72,7 +72,9 @@ class FillDummyValueFix( KotlinBuiltIns.isLong(type) || KotlinBuiltIns.isShort(type) -> "${ValueGenerator.randomNumFor(paramName)}" - KotlinBuiltIns.isString(type) -> "\"${ValueGenerator.randomStringFor(paramName)}\"" + KotlinBuiltIns.isCharSequence(type) || + KotlinBuiltIns.isString(type) -> "\"${ValueGenerator.randomStringFor(paramName)}\"" + else -> super.fillValue(descriptor) } } From 9468a2ea7148e185c8e1ad00c7f1f05f68938d34 Mon Sep 17 00:00:00 2001 From: oboenikui Date: Sat, 29 Jul 2023 21:50:44 +0900 Subject: [PATCH 2/2] add CharSequence param tests --- .../inspections/FillDummyValueInspectionTest.kt | 7 ++++--- .../inspections/FillEmptyValueInspectionTest.kt | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValueInspectionTest.kt b/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValueInspectionTest.kt index 551d7d8..5030be1 100644 --- a/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValueInspectionTest.kt +++ b/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillDummyValueInspectionTest.kt @@ -24,17 +24,18 @@ class FillDummyValueInspectionTest : BasePlatformTestCase() { fun `test fill class constructor`() { every { ValueGenerator.randomStringFor("name") } returns "John Smith" every { ValueGenerator.randomNumFor("age") } returns 1234 + every { ValueGenerator.randomStringFor("pass") } returns "password" doAvailableTest( """ - class User(val name: String, val age: Int) + class User(val name: String, val age: Int, val pass: CharSequence) fun test() { User() } """, """ - class User(val name: String, val age: Int) + class User(val name: String, val age: Int, val pass: CharSequence) fun test() { - User(name = "John Smith", age = 1234) + User(name = "John Smith", age = 1234, pass = "password") } """, ) diff --git a/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillEmptyValueInspectionTest.kt b/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillEmptyValueInspectionTest.kt index f1651b3..cf89505 100644 --- a/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillEmptyValueInspectionTest.kt +++ b/src/test/kotlin/com/github/suusan2go/kotlinfillclass/inspections/FillEmptyValueInspectionTest.kt @@ -10,15 +10,15 @@ class FillEmptyValueInspectionTest : BasePlatformTestCase() { fun `test fill class constructor`() { doAvailableTest( """ - class User(val name: String, val age: Int) + class User(val name: String, val age: Int, val pass: CharSequence) fun test() { User() } """, """ - class User(val name: String, val age: Int) + class User(val name: String, val age: Int, val pass: CharSequence) fun test() { - User(name = "", age = 0) + User(name = "", age = 0, pass = "") } """, )