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

1.0.17 버전에서 SimpleValueJqwikPlugin 사용시 Set<Integer> 의 임의값이 생성되지 않습니다. #986

Closed junyoung-kang-kurly closed 3 months ago

junyoung-kang-kurly commented 3 months ago

Describe the bug

SimpleValueJqwikPlugin 사용시 Set 유형에 2개이상 엘리먼트에 할당되도록 했을시, sample 객체 생성이 완료되지 못하고 무한루프 하고 있습니다.

Your environment

Steps to reproduce

public class TestObject {

    private Set<Integer> integers;

    public Collection<Integer> getIntegers() {
        return integers;
    }
}
public class SampleCreatingFailureTest {

    @Property(tries = 10)
    void test() {
        // given
        FixtureMonkey sut = FixtureMonkey.builder()
            .objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
            .plugin(new SimpleValueJqwikPlugin())
            .build();

        // when  - sample 객체가 생성되지 않고 무한루프 합니다.
        TestObject actual = sut.giveMeBuilder(TestObject.class)
            .size("integers", 2)
            .sample();

        // then
        then(actual).isNotNull();
        then(actual.getIntegers()).hasSize(2);
    }
}

Expected behaviour

Set<Integer> integers 필드에 2개의 엘리먼트에 임의 값들이 할당되어야 합니다.

Actual behaviour

하지만 무한루프와 함께 할당이 되지 않고 객체생성이 되지 않아 .sample() 다음 라인으로 진행되지 않습니다.

아래 조치중 하나를 하면 정상 동작하고 있습니다.

  1. 엘리먼트를 1개 이하로 생성되도록 변경 (예: .size("integers", 1) 로 변경)
  2. integers 필드 유형을 Set에서 List로 변경
  3. Set<Integer> 의 제네릭을 Number가 아닌 유형으로 변경. (예: Set<String>)
  4. SimpleValueJqwikPlugin 플러그인을 제거
seongahjo commented 3 months ago

@junyoung-kang-kurly 1.0.18에서 해결됐습니다! 감사합니다~