-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
I know, that due to the currently supported java-version, Fixture cannot natively support records. However, so far it implicitly supports them through constructor-creation in the case that an instance cannot be mutated after creation.
This test is green:
@Test
void canCreateDistinctElementsInCollectionForClasses() {
var actual = fixture().create(ClassWithList.class);
assertThat(actual.getChildren().get(0)).isNotSameAs(actual.getChildren().get(1));
}
public static class ClassWithList {
private final List<Child> children;
public ClassWithList(List<Child> children) {
this.children = children;
}
public List<Child> getChildren() {
return children;
}
public static class Child {
private final String string;
public Child(String string) {
this.string = string;
}
public String getString() {
return string;
}
}
}The test above is green, because Fixture will create distinct instances of classes in a collection.
The test below however is red, because the behaviour above does not seem to apply to records:
@Test
void canCreateDistinctElementsInCollectionForRecords() {
var actual = fixture().create(RecordWithList.class);
assertThat(actual.children().get(0)).isNotSameAs(actual.children().get(1));
}
public record RecordWithList(List<Child> children) {
public record Child(String string) {}
}(Unfortunately, I cannot run the test in Fixture, since its java-version doesn't support records.)