Skip to content

Commit 0c35379

Browse files
committed
Fix empty lists as parameter values
1 parent 5ad8125 commit 0c35379

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

core/src/integration/kotlin/io/github/serpro69/kfaker/provider/AddressIT.kt

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.github.serpro69.kfaker.provider
33
import io.github.serpro69.kfaker.faker
44
import io.kotest.assertions.throwables.shouldNotThrow
55
import io.kotest.core.spec.style.DescribeSpec
6+
import io.kotest.matchers.shouldBe
67
import io.kotest.matchers.shouldNotBe
78
import io.kotest.matchers.string.shouldContain
89
import io.kotest.matchers.string.shouldMatch
@@ -11,6 +12,17 @@ class AddressIT : DescribeSpec({
1112
describe("Address Provider") {
1213
val address: (locale: String) -> Address = { faker { fakerConfig { locale = it } }.address }
1314

15+
context("uk locale") {
16+
context("empty list as a parameter value") {
17+
it("cityPrefix() should return empty string") {
18+
address("uk").cityPrefix() shouldBe ""
19+
}
20+
it("citySuffix() should return empty string") {
21+
address("uk").citySuffix() shouldBe ""
22+
}
23+
}
24+
}
25+
1426
context("nb-NO locale") {
1527
it("city() does NOT throw NoSuchElementException") {
1628
shouldNotThrow<NoSuchElementException> { address("nb-NO").city() }

core/src/main/kotlin/io/github/serpro69/kfaker/FakerService.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import io.github.serpro69.kfaker.provider.FakeDataProvider
1919
import io.github.serpro69.kfaker.provider.Name
2020
import io.github.serpro69.kfaker.provider.Tertiary
2121
import io.github.serpro69.kfaker.provider.YamlFakeDataProvider
22+
import org.w3c.dom.ranges.RangeException
2223
import java.io.InputStream
2324
import java.util.*
2425
import java.util.regex.Matcher
@@ -304,8 +305,10 @@ internal class FakerService {
304305

305306
return when (parameterValue) {
306307
is List<*> -> {
307-
when (val value = randomService.randomValue(parameterValue)) {
308-
is List<*> -> RawExpression(randomService.randomValue(value) as String)
308+
if (parameterValue.isEmpty()) RawExpression("") else when (val value = randomService.randomValue(parameterValue)) {
309+
is List<*> -> {
310+
if (value.isEmpty()) RawExpression("") else RawExpression(randomService.randomValue(value) as String)
311+
}
309312
is String -> RawExpression(value)
310313
is Int -> RawExpression(value.toString())
311314
else -> throw UnsupportedOperationException("Unsupported type of raw value: ${parameterValue::class.simpleName}")

0 commit comments

Comments
 (0)