diff --git a/src/main/java/com/github/nylle/javafixture/specimen/AbstractSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/AbstractSpecimen.java index 454fb59..6d1cdc7 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/AbstractSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/AbstractSpecimen.java @@ -61,9 +61,9 @@ public T create(final CustomizationContext customizationContext, Annotation[] an Map.>of().getOrDefault( field.getGenericType().getTypeName(), specimenFactory.build(SpecimenType.fromClass(field.getGenericType()))).create(new CustomizationContext(List.of(), Map.of(), false), field.getAnnotations())))); - return result; + return context.remove(type); } catch(SpecimenException ignored) { - return context.cached(type, instanceFactory.manufacture(type, customizationContext)); + return instanceFactory.manufacture(type, customizationContext); } } } diff --git a/src/main/java/com/github/nylle/javafixture/specimen/ArraySpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/ArraySpecimen.java index a8c7455..ea94dae 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/ArraySpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/ArraySpecimen.java @@ -49,6 +49,6 @@ public T create(final CustomizationContext customizationContext, Annotation[] an IntStream.range(0, length).boxed().forEach(i -> Array.set(result, i, specimenFactory.build(SpecimenType.fromClass(type.getComponentType())).create(customizationContext, new Annotation[0]))); - return result; + return context.remove(type); } } diff --git a/src/main/java/com/github/nylle/javafixture/specimen/CollectionSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/CollectionSpecimen.java index d472a55..0a4b890 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/CollectionSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/CollectionSpecimen.java @@ -65,7 +65,7 @@ public T create(final CustomizationContext customizationContext, Annotation[] an .filter(x -> specimen != null) .forEach(x -> collection.add(specimen.create(customizationContext, new Annotation[0]))); - return (T) collection; + return context.remove(type); } private T createEnumSet(CustomizationContext customizationContext) { diff --git a/src/main/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimen.java index 78d8b29..b45b4da 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimen.java @@ -58,11 +58,11 @@ public T create(CustomizationContext customizationContext, Annotation[] annotati return context.cached(type); } - return context.cached(type, shuffledStream(derivedTypes) + return shuffledStream(derivedTypes) .map(derivedType -> specimenFactory.build(derivedType)) .flatMap(derivedSpecimen -> tryCreate(derivedSpecimen, customizationContext, annotations).stream()) .findFirst() - .orElseGet(() -> proxy(customizationContext))); + .orElseGet(() -> proxy(customizationContext)); } private R proxy(CustomizationContext customizationContext) { diff --git a/src/main/java/com/github/nylle/javafixture/specimen/GenericSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/GenericSpecimen.java index f7559e1..86e52f0 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/GenericSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/GenericSpecimen.java @@ -61,11 +61,11 @@ public T create(CustomizationContext customizationContext, Annotation[] annotati } if (type.isInterface()) { - return (T) context.cached(type, instanceFactory.proxy(type, specimens)); + return (T) instanceFactory.proxy(type, specimens); } if (customizationContext.useRandomConstructor()) { - return context.cached(type, instanceFactory.construct(type, customizationContext)); + return instanceFactory.construct(type, customizationContext); } return populate(customizationContext); @@ -85,9 +85,10 @@ private T populate(CustomizationContext customizationContext) { field.getGenericType().getTypeName(), specimenFactory.build(SpecimenType.fromClass(field.getType()))).create(new CustomizationContext(List.of(), Map.of(), false), new Annotation[0])))); } catch (SpecimenException ex) { - return context.overwrite(type, instanceFactory.construct(type, customizationContext)); + context.remove(type); + return instanceFactory.construct(type, customizationContext); } - return result; + return context.remove(type); } } diff --git a/src/main/java/com/github/nylle/javafixture/specimen/InterfaceSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/InterfaceSpecimen.java index 7013c52..bc18ced 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/InterfaceSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/InterfaceSpecimen.java @@ -40,11 +40,7 @@ public InterfaceSpecimen(final SpecimenType type, final Context context, fina @Override public T create(final CustomizationContext customizationContext, Annotation[] annotations) { - if (context.isCached(type)) { - return context.cached(type); - } - - return (T) context.cached(type, instanceFactory.proxy(type)); + return (T) instanceFactory.proxy(type); } } diff --git a/src/main/java/com/github/nylle/javafixture/specimen/MapSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/MapSpecimen.java index 1bcc00c..d3196ed 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/MapSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/MapSpecimen.java @@ -67,7 +67,7 @@ public T create(final CustomizationContext customizationContext, Annotation[] an .filter(x -> keySpecimen != null && valueSpecimen != null) .forEach(x -> map.put(keySpecimen.create(customizationContext, new Annotation[0]), valueSpecimen.create(customizationContext, new Annotation[0]))); - return (T) map; + return context.remove(type); } private Map createFromConcreteType(final SpecimenType type) { diff --git a/src/main/java/com/github/nylle/javafixture/specimen/ObjectSpecimen.java b/src/main/java/com/github/nylle/javafixture/specimen/ObjectSpecimen.java index 8308589..9274ba9 100644 --- a/src/main/java/com/github/nylle/javafixture/specimen/ObjectSpecimen.java +++ b/src/main/java/com/github/nylle/javafixture/specimen/ObjectSpecimen.java @@ -51,7 +51,7 @@ public T create(CustomizationContext customizationContext, Annotation[] annotati } if (customizationContext.useRandomConstructor()) { - return context.cached(type, instanceFactory.construct(type, customizationContext)); + return instanceFactory.construct(type, customizationContext); } return populate(customizationContext); @@ -72,6 +72,6 @@ private T populate(CustomizationContext customizationContext) { } catch (SpecimenException ex) { return context.overwrite(type, instanceFactory.construct(type, customizationContext)); } - return result; + return context.remove(type); } } diff --git a/src/test/java/com/github/nylle/javafixture/InstanceFactoryTest.java b/src/test/java/com/github/nylle/javafixture/InstanceFactoryTest.java index b90b66a..d70e085 100644 --- a/src/test/java/com/github/nylle/javafixture/InstanceFactoryTest.java +++ b/src/test/java/com/github/nylle/javafixture/InstanceFactoryTest.java @@ -134,15 +134,15 @@ void argumentsCanBeCustomized() { @Test @DisplayName("constructor arguments are cached") - void constructorArgumentsAreCached() { + void constructorArgumentsAreNotCached() { var sut = new InstanceFactory(new SpecimenFactory(new Context(Configuration.configure()))); var customizationContext = new CustomizationContext(List.of(), Map.of(), true); TestObject first = sut.construct(fromClass(TestObject.class), customizationContext); TestObject second = sut.construct(fromClass(TestObject.class), customizationContext); - assertThat(first.getIntegers()).usingRecursiveComparison().isEqualTo(second.getIntegers()); - assertThat(first.getStrings()).usingRecursiveComparison().isEqualTo(second.getStrings()); + assertThat(first.getIntegers()).usingRecursiveComparison().isNotEqualTo(second.getIntegers()); + assertThat(first.getStrings()).usingRecursiveComparison().isNotEqualTo(second.getStrings()); assertThat(first.getValue()).as("primitives are never cached").isNotEqualTo(second.getValue()); } diff --git a/src/test/java/com/github/nylle/javafixture/specimen/AbstractSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/AbstractSpecimenTest.java index 90d836e..e27e310 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/AbstractSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/AbstractSpecimenTest.java @@ -108,23 +108,27 @@ void voidAbstractMethodsWillJustReturnVoid() { @Test void createAbstractClassWithoutConstructor() { - var sut = new AbstractSpecimen(SpecimenType.fromClass(Charset.class), context, specimenFactory); + SpecimenType specimenType = SpecimenType.fromClass(Charset.class); + var sut = new AbstractSpecimen<>(specimenType, context, specimenFactory); + assertThat(context.isCached(specimenType)).isFalse(); var actual = sut.create(noContext(), new Annotation[0]); assertThat(actual).isInstanceOf(Charset.class); + assertThat(context.isCached(specimenType)).isFalse(); } @Test - void resultIsCached() { + void resultIsNotCached() { var original = new AbstractSpecimen(SpecimenType.fromClass(TestAbstractClass.class), context, specimenFactory).create(noContext(), new Annotation[0]); - var cached = new AbstractSpecimen(SpecimenType.fromClass(TestAbstractClass.class), context, specimenFactory).create(noContext(), new Annotation[0]); + var second = new AbstractSpecimen(SpecimenType.fromClass(TestAbstractClass.class), context, specimenFactory).create(noContext(), new Annotation[0]); assertThat(original).isInstanceOf(TestAbstractClass.class); - assertThat(original).isSameAs(cached); - assertThat(original.toString()).isEqualTo(cached.toString()); - assertThat(original.getString()).isSameAs(cached.getString()); + assertThat(original).isNotEqualTo(second); + assertThat(original.hashCode()).isNotEqualTo(second.hashCode()); + assertThat(original.toString()).isNotEqualTo(second.toString()); + assertThat(original.getString()).isNotEqualTo(second.getString()); } } diff --git a/src/test/java/com/github/nylle/javafixture/specimen/ArraySpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/ArraySpecimenTest.java index 5b7d256..26602b2 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/ArraySpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/ArraySpecimenTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import java.lang.annotation.Annotation; +import java.util.Arrays; import java.util.Map; import static com.github.nylle.javafixture.CustomizationContext.noContext; @@ -83,8 +84,18 @@ void canHandleCircularReferences() { assertThat(actual).isInstanceOf(AccountManager[].class); assertThat(actual.length).isEqualTo(2); assertThat(actual[0]).isInstanceOf(AccountManager.class); - assertThat(actual[0]).isSameAs(actual[1]); + assertThat(actual[0]).isNotEqualTo(actual[1]); assertThat(actual[0].getOtherAccountManagers()).isInstanceOf(AccountManager[].class); assertThat(actual[0].getOtherAccountManagers()).isSameAs(actual); } + + @Test + void createdArraysAreNotCached() { + var sut = new ArraySpecimen(SpecimenType.fromClass(AccountManager[].class), context, specimenFactory); + + var actual = sut.create(noContext(), new Annotation[0]); + var second = sut.create(noContext(), new Annotation[0]); + + assertThat(Arrays.asList(actual)).doesNotContainAnyElementsOf(Arrays.asList(second)); + } } diff --git a/src/test/java/com/github/nylle/javafixture/specimen/CollectionSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/CollectionSpecimenTest.java index e92af36..0a5c53d 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/CollectionSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/CollectionSpecimenTest.java @@ -132,12 +132,12 @@ void createTreeSetFromSortedSetInterface() { @Test void createHashSetFromSetInterface() { - var sut = new CollectionSpecimen<>(new SpecimenType>() {}, context, specimenFactory); + var sut = new CollectionSpecimen<>(new SpecimenType>() {}, context, specimenFactory); var actual = sut.create(noContext(), new Annotation[0]); assertThat(actual).isInstanceOf(HashSet.class); - assertThat(actual.stream().allMatch(x -> x.getClass().equals(String.class))).isTrue(); + assertThat(actual.stream().allMatch(x -> x.getClass().equals(Object.class))).isTrue(); assertThat(actual.size()).isEqualTo(2); } @@ -295,16 +295,16 @@ void createLinkedList() { } @Test - void resultIsCached() { + void resultIsNotCached() { var original = new CollectionSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); - var cached = new CollectionSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); + var second = new CollectionSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); assertThat(original).isInstanceOf(List.class); - assertThat(original.size()).isEqualTo(2); - assertThat(original).isSameAs(cached); - assertThat(original.get(0)).isEqualTo(cached.get(0)); - assertThat(original.get(1)).isEqualTo(cached.get(1)); + assertThat(original.size()).as("collection size should be two because of this test's context").isEqualTo(2); + assertThat(original).isNotEqualTo(second); + assertThat(original.get(0)).isNotEqualTo(second.get(0)); + assertThat(original.get(1)).isNotEqualTo(second.get(1)); } @Test @@ -323,7 +323,7 @@ void nestedLists() { } @Test - void nonPrimitiveElementsAreSameInstance() { + void nonPrimitiveElementsAreNotCached() { var sut = new CollectionSpecimen<>(new SpecimenType>() {}, context, specimenFactory); @@ -333,7 +333,7 @@ void nonPrimitiveElementsAreSameInstance() { assertThat(actual.size()).isEqualTo(2); assertThat(actual.get(0)).isExactlyInstanceOf(TestObject.class); assertThat(actual.get(1)).isExactlyInstanceOf(TestObject.class); - assertThat(actual.get(0)).isSameAs(actual.get(1)); + assertThat(actual.get(0)).isNotEqualTo(actual.get(1)); } } diff --git a/src/test/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimenTest.java index 1db78f2..1b300d4 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/ExperimentalAbstractSpecimenTest.java @@ -113,16 +113,16 @@ void typeMustNotBeMap() { class WhenCallingCreate { @Test - @DisplayName("the result is cached") - void resultIsCached() { + @DisplayName("the result is not cached") + void resultIsNotCached() { var original = new InterfaceSpecimen(SpecimenType.fromClass(InterfaceWithoutImplementation.class), context, specimenFactory).create(noContext(), new Annotation[0]); - var cached = new InterfaceSpecimen(SpecimenType.fromClass(InterfaceWithoutImplementation.class), context, specimenFactory).create(noContext(), new Annotation[0]); + var second = new InterfaceSpecimen(SpecimenType.fromClass(InterfaceWithoutImplementation.class), context, specimenFactory).create(noContext(), new Annotation[0]); assertThat(original) .isInstanceOf(InterfaceWithoutImplementation.class) - .isSameAs(cached); - assertThat(original.toString()).isEqualTo(cached.toString()); - assertThat(original.getTestObject()).isSameAs(cached.getTestObject()); + .isNotEqualTo(second); + assertThat(original.toString()).isNotEqualTo(second.toString()); + assertThat(original.getTestObject()).isNotEqualTo(second.getTestObject()); } @Nested diff --git a/src/test/java/com/github/nylle/javafixture/specimen/GenericSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/GenericSpecimenTest.java index f29a8f5..e65d93f 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/GenericSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/GenericSpecimenTest.java @@ -6,9 +6,12 @@ import com.github.nylle.javafixture.SpecimenException; import com.github.nylle.javafixture.SpecimenFactory; import com.github.nylle.javafixture.SpecimenType; +import com.github.nylle.javafixture.annotations.testcases.TestCase; +import com.github.nylle.javafixture.annotations.testcases.TestWithCases; import com.github.nylle.javafixture.testobjects.TestObject; import com.github.nylle.javafixture.testobjects.TestObjectGeneric; import com.github.nylle.javafixture.testobjects.inheritance.GenericChild; +import com.github.nylle.javafixture.testobjects.withconstructor.TestObjectWithConstructedField; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -108,6 +111,15 @@ void subSpecimenAreProperlyCached() { assertThat(result.getU()).isInstanceOf(Optional.class); } + @Test + void constructedGenericsAreNotCached() { + var first = new GenericSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); + var second = new GenericSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); + + assertThat(first).isNotEqualTo(second); + + } + @Test void cannotSetNonExistingField() { var sut = new GenericSpecimen<>(new SpecimenType>() {}, context, specimenFactory); @@ -147,6 +159,42 @@ void customFieldIsOnlyUsedInTopLevelObject() { assertThat(actual.getTestObject().getIntegers()).isNotEmpty(); } + @Test + void createdObjectsAreNotCached() { + var sut = new GenericSpecimen<>(new SpecimenType>() {}, context, specimenFactory); + var actual = sut.create(new CustomizationContext(List.of(), Map.of(), false), new Annotation[0]); + var second = sut.create(new CustomizationContext(List.of(), Map.of(), false), new Annotation[0]); + + assertThat(actual).isNotEqualTo(second); + } + + @DisplayName("objects are not cached, neither constructed nor populated") + @TestWithCases + @TestCase(bool1 = true) + @TestCase(bool1 = false) + void constructedObjectsAreNotCached(boolean useConstructor) { + var sut = new GenericSpecimen<>(new SpecimenType>() {}, context, specimenFactory); + + var actual = sut.create(new CustomizationContext(List.of(), Map.of(), useConstructor), new Annotation[0]); + var second = sut.create(new CustomizationContext(List.of(), Map.of(), useConstructor), new Annotation[0]); + + assertThat(actual).isNotEqualTo(second); + } + + @DisplayName("when generic type is an interface, we will fixture the non-default methods") + @Test + void interfacesAreFixtured() { + var sut = new GenericSpecimen<>(new SpecimenType>() {}, context, specimenFactory); + + var actual = sut.create(new CustomizationContext(List.of(), Map.of(), false), new Annotation[0]); + var second = sut.create(new CustomizationContext(List.of(), Map.of(), false), new Annotation[0]); + + assertThat(actual.compareTo(0)) + .as("two different fixtured objects should have two different fixtured results") + .isNotEqualTo(second.compareTo(0)); + assertThat(actual).isNotEqualTo(second); + } + @Nested @DisplayName("when specimen has superclass") class WhenInheritance { diff --git a/src/test/java/com/github/nylle/javafixture/specimen/InterfaceSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/InterfaceSpecimenTest.java index 9a0d3a5..a5cd840 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/InterfaceSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/InterfaceSpecimenTest.java @@ -70,15 +70,15 @@ void createInterface() { } @Test - void resultIsCached() { + void resultIsNotCached() { var original = new InterfaceSpecimen(SpecimenType.fromClass(InterfaceWithoutImplementation.class), context, specimenFactory).create(noContext(), new Annotation[0]); - var cached = new InterfaceSpecimen(SpecimenType.fromClass(InterfaceWithoutImplementation.class), context, specimenFactory).create(noContext(), new Annotation[0]); + var second = new InterfaceSpecimen(SpecimenType.fromClass(InterfaceWithoutImplementation.class), context, specimenFactory).create(noContext(), new Annotation[0]); assertThat(original).isInstanceOf(InterfaceWithoutImplementation.class); - assertThat(original).isSameAs(cached); - assertThat(original.toString()).isEqualTo(cached.toString()); - assertThat(original.getTestObject()).isSameAs(cached.getTestObject()); + assertThat(original).isNotEqualTo(second); + assertThat(original.toString()).isNotEqualTo(second.toString()); + assertThat(original.getTestObject()).isNotEqualTo(second.getTestObject()); } } diff --git a/src/test/java/com/github/nylle/javafixture/specimen/MapSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/MapSpecimenTest.java index 0d6fa75..5ee1ebb 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/MapSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/MapSpecimenTest.java @@ -183,16 +183,15 @@ void createEnumMap() { } @Test - void resultIsCached() { + void resultIsNotCached() { var original = new MapSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); - var cached = new MapSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); + var second = new MapSpecimen<>(new SpecimenType>() {}, context, specimenFactory).create(noContext(), new Annotation[0]); assertThat(original).isInstanceOf(Map.class); assertThat(original.size()).isEqualTo(2); - assertThat(original).isSameAs(cached); - assertThat(original.get(0)).isEqualTo(cached.get(0)); - assertThat(original.get(1)).isEqualTo(cached.get(1)); + assertThat(original).isNotEqualTo(second); + assertThat(original.values()).doesNotContainAnyElementsOf(second.values()); } @Test diff --git a/src/test/java/com/github/nylle/javafixture/specimen/ObjectSpecimenTest.java b/src/test/java/com/github/nylle/javafixture/specimen/ObjectSpecimenTest.java index 205b0af..3203378 100644 --- a/src/test/java/com/github/nylle/javafixture/specimen/ObjectSpecimenTest.java +++ b/src/test/java/com/github/nylle/javafixture/specimen/ObjectSpecimenTest.java @@ -6,6 +6,8 @@ import com.github.nylle.javafixture.SpecimenException; import com.github.nylle.javafixture.SpecimenFactory; import com.github.nylle.javafixture.SpecimenType; +import com.github.nylle.javafixture.annotations.testcases.TestCase; +import com.github.nylle.javafixture.annotations.testcases.TestWithCases; import com.github.nylle.javafixture.testobjects.TestObject; import com.github.nylle.javafixture.testobjects.inheritance.Child; import org.junit.jupiter.api.BeforeEach; @@ -88,16 +90,20 @@ void create() { assertThat(second.getValue()).isExactlyInstanceOf(String.class); } - @Test - void resultIsCached() { + @DisplayName("when creating objects, they are not cached, regardless of the creation technique") + @TestWithCases + @TestCase(bool1 = true) + @TestCase(bool1 = false) + void resultIsNotCached(boolean useRandomConstructor) { - var original = new ObjectSpecimen(SpecimenType.fromClass(TestObject.class), context, specimenFactory).create(noContext(), new Annotation[0]); - var cached = new ObjectSpecimen(SpecimenType.fromClass(TestObject.class), context, specimenFactory).create(noContext(), new Annotation[0]); + var customizationContext = new CustomizationContext(List.of(), Map.of(), useRandomConstructor); + var original = new ObjectSpecimen(SpecimenType.fromClass(TestObject.class), context, specimenFactory).create(customizationContext, new Annotation[0]); + var second = new ObjectSpecimen(SpecimenType.fromClass(TestObject.class), context, specimenFactory).create(customizationContext, new Annotation[0]); assertThat(original).isInstanceOf(TestObject.class); - assertThat(original).isSameAs(cached); - assertThat(original.getValue()).isEqualTo(cached.getValue()); - assertThat(original.getIntegers()).isEqualTo(cached.getIntegers()); + assertThat(original).isNotEqualTo(second); + assertThat(original.getValue()).isNotEqualTo(second.getValue()); + assertThat(original.getIntegers()).isNotEqualTo(second.getIntegers()); } @Test