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

Use the canonical constructor instead of the first one #833

Closed esfomeado closed 10 months ago

esfomeado commented 10 months ago

Describe the feature you request

Fixture Monkey when instantiating a Java Record should use the canonical constructor instead of the first one that it finds.

public record Value(UUID value) {
    public Value(String value) {
        this(UUID.fromString(value));
    }
}

On this scenario Fixture Monkey will try and use the String constructor so it will generate a random String that isn´t a valid UUID so an exception will be thrown. (Some Java Compiler options can change the constructor order also) I can force this Record to be generated with an UUID but on a project with thousands of similar records with the same problem it becomes unmanageable. So I think that by default for the records it should use the canonical constructor. That way the object will be always instantiated.

seongahjo commented 10 months ago

@esfomeado Thank you for the suggestion. This feature is supported since 1.0.4.