Skip to content

Commit

Permalink
Fix generating empty String with @SiZe annotation (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Nov 15, 2024
1 parent 75b4772 commit 0f683aa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,12 @@ public Arbitrary<String> strings(
return arbitrary
.filter(it -> {
if (!notBlank) {
if (it == null) {
if (it == null || it.isEmpty()) {
return true;
}
}

if (it == null || it.trim().isEmpty()) {
return false;
}

return true;
return it != null && !it.trim().isEmpty();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.navercorp.fixturemonkey.api.property.PropertyUtils
import com.navercorp.fixturemonkey.api.type.Types
import com.navercorp.fixturemonkey.api.type.Types.GeneratingWildcardType
import com.navercorp.fixturemonkey.customizer.Values
import com.navercorp.fixturemonkey.javax.validation.plugin.JavaxValidationPlugin
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin
import com.navercorp.fixturemonkey.kotlin.expression.root
import com.navercorp.fixturemonkey.kotlin.get
Expand Down Expand Up @@ -79,6 +80,7 @@ import java.time.temporal.ChronoUnit
import java.util.LinkedList
import java.util.TreeSet
import java.util.UUID
import javax.validation.constraints.Size
import kotlin.reflect.jvm.javaMethod

class KotlinTest {
Expand Down Expand Up @@ -971,6 +973,26 @@ class KotlinTest {
then(actual).isInstanceOf(SecondConcreteClass::class.java)
}

@Test
fun sizeZero(){
// given
class StringWithSizeZero(
@field:Size(min = 0, max = 0)
val value: String,
)

val sut = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.plugin(JavaxValidationPlugin())
.build()

// when
val actual = sut.giveMeOne<StringWithSizeZero>().value

// then
then(actual).isEqualTo("")
}

companion object {
private val SUT: FixtureMonkey = FixtureMonkey.builder()
.plugin(KotlinPlugin())
Expand Down

0 comments on commit 0f683aa

Please sign in to comment.