naver / fixture-monkey

Let Fixture Monkey generate test instances including edge cases automatically
https://naver.github.io/fixture-monkey
Apache License 2.0
560 stars 89 forks source link

Optional 값을 set 할 때 #998

Closed morishjs closed 2 months ago

morishjs commented 3 months ago

안녕하세요.

        FixtureMonkey sut = FixtureMonkey.builder()
                .plugin(new JakartaValidationPlugin())
                .objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
                .build();

 SignUpDto.Request sample = sut.giveMeBuilder(SignUpDto.Request.class)
                .set("email", Optional.fromNullable(email))
                .set("password", Optional.fromNullable(password))
                .sample();

이런 식으로 email, password가 Optional 타입일 때 위 코드처럼 그대로 실행하게 되면 에러가 발생하는데 The value is not of the same type as the property.

어떻게 해결할 수 있나요?

seongahjo commented 3 months ago

@morishjs 안녕하세요.

공유 주신 에러 메세지는 설정하는 값과 필드 값이 다를 때 발생하는 메세지입니다. 우선 아래와 같이 확인해보았을 때 이슈가 없는 걸로 확인했는데요, 혹시 자세한 재현 케이스를 공유주실 수 있을까요??

image

기본으로 제공하는 Optional에는 fromNullable 메소드가 없는데, 다른 라이브러리에서 제공하는 타입을 넣으셨을 수도 있겠다고 생각이 듭니다!

감사합니다.