From d1c00bad12b74b1113ddde6496f7429a604d5a82 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 4 Dec 2024 19:04:29 +0100 Subject: [PATCH 01/23] Reverts back to version 3.17.1 --- .../extended_contract/RecordsTest.java | 2 +- .../vintage/RecordFallbackFactoryTest.java | 51 ----- .../RecordObjectAccessorCopyingTest.java | 2 +- .../RecordObjectAccessorScramblingTest.java | 24 +-- .../RecordObjectAccessorTest.java | 19 +- ...Test.java => ClassAccessorSealedTest.java} | 2 +- .../SealedTypesFallbackFactoryTest.java | 87 --------- equalsverifier-core/pom.xml | 14 +- .../ConfiguredEqualsVerifier.java | 8 +- .../equalsverifier/EqualsVerifierReport.java | 2 +- .../api/SingleTypeEqualsVerifierApi.java | 27 +-- .../internal/SuppressFBWarnings.java | 16 -- .../checkers/AbstractDelegationChecker.java | 9 +- .../internal/checkers/ExamplesChecker.java | 2 +- .../internal/checkers/HierarchyChecker.java | 2 +- .../MapEntryHashCodeRequirementChecker.java | 3 +- .../fieldchecks/JpaLazyGetterFieldCheck.java | 11 +- .../NullPointerExceptionFieldCheck.java | 2 +- .../fieldchecks/ReflexivityFieldCheck.java | 10 +- .../fieldchecks/StringFieldCheck.java | 8 +- .../fieldchecks/SymmetryFieldCheck.java | 2 +- .../fieldchecks/TransientFieldsCheck.java | 2 +- .../fieldchecks/TransitivityFieldCheck.java | 2 +- .../internal/exceptions/NoValueException.java | 31 --- .../exceptions/RecursionException.java | 2 +- .../reflection/ConditionalInstantiator.java | 2 +- .../internal/reflection/FactoryCache.java | 88 +++++++++ .../internal/reflection/FieldCache.java | 60 ++++++ .../internal/reflection/FieldProbe.java | 2 +- .../reflection/JavaApiPrefabValues.java | 23 +-- .../internal/reflection/Tuple.java | 15 -- .../instantiation/CachedValueProvider.java | 75 -------- .../instantiation/ChainedValueProvider.java | 56 ------ .../instantiation/SubjectCreator.java | 18 +- .../instantiation/ValueProvider.java | 81 +------- .../VintageValueProvider.java | 97 +++++----- .../reflection/vintage/ClassAccessor.java | 108 +++++++++++ .../reflection/vintage/FactoryCache.java | 180 ------------------ .../vintage/{mutation => }/FieldModifier.java | 12 +- .../{mutation => }/InPlaceObjectAccessor.java | 10 +- .../{mutation => }/ObjectAccessor.java | 10 +- .../{mutation => }/RecordObjectAccessor.java | 10 +- .../vintage/mutation/ClassAccessor.java | 68 ------- .../factories/AbstractGenericFactory.java | 20 +- .../prefabvalues/factories/CopyFactory.java | 15 +- .../factories/EnumMapFactory.java | 14 +- .../factories/EnumSetFactory.java | 14 +- .../factories/ExternalFactory.java | 10 +- .../factories/FallbackFactory.java | 56 ++++-- .../prefabvalues/factories/MapFactory.java | 16 +- .../factories/PrefabValueFactory.java | 13 +- .../prefabvalues/factories/SimpleFactory.java | 6 +- .../factories/SimpleGenericFactory.java | 12 +- .../factoryproviders/AwtFactoryProvider.java | 2 +- .../factoryproviders/FactoryProvider.java | 2 +- .../GuavaFactoryProvider.java | 48 +++-- .../JavaFxFactoryProvider.java | 20 +- .../JavaxFactoryProvider.java | 2 +- .../factoryproviders/JodaFactoryProvider.java | 2 +- .../factoryproviders/RmiFactoryProvider.java | 2 +- .../testhelpers/ExpectedException.java | 2 +- .../testhelpers/TestValueProviders.java | 20 -- .../internal/testhelpers/Util.java | 2 +- .../util/CachedHashCodeInitializer.java | 2 +- .../internal/util/Configuration.java | 2 +- .../equalsverifier/internal/util/Context.java | 28 ++- .../internal/util/DefaultValueProviders.java | 32 ---- .../vintage => util}/PrefabValuesApi.java | 48 ++--- .../internal/util/Validations.java | 49 +++-- .../extended_contract/GenericTypesTest.java | 89 --------- .../ConfiguredEqualsVerifierMultipleTest.java | 21 -- .../ConfiguredEqualsVerifierSingleTest.java | 21 -- .../operational/RecursionTest.java | 36 +--- .../WithPrefabValuesForFieldTest.java | 109 +---------- .../architecture/ArchitectureTest.java | 33 +++- .../exceptions/NoValueExceptionTest.java | 26 --- .../{vintage => }/FactoryCacheTest.java | 59 +----- .../internal/reflection/FieldCacheTest.java | 61 ++++++ .../internal/reflection/TupleTest.java | 12 -- .../CachedValueProviderTest.java | 62 ------ .../ChainedValueProviderTest.java | 124 ------------ .../instantiation/SubjectCreatorTest.java | 43 ++--- .../VintageValueProviderCreatorTest.java | 33 ++-- .../VintageValueProviderTest.java | 74 +++++-- .../{mutation => }/ClassAccessorTest.java | 66 ++++--- .../{mutation => }/FieldModifierTest.java | 2 +- .../InPlaceObjectAccessorCopyingTest.java | 2 +- .../InPlaceObjectAccessorScramblingTest.java | 22 +-- .../InPlaceObjectAccessorTest.java | 2 +- .../factories/AbstractGenericFactoryTest.java | 6 +- .../factories/FallbackFactoryTest.java | 41 ++-- .../factories/MapFactoryTest.java | 24 +-- .../factories/SimpleGenericFactoryTest.java | 24 +-- .../JavaFxFactoryProviderTest.java | 25 +-- .../vintage => util}/PrefabValuesApiTest.java | 2 +- .../internal/util/ValidationsTest.java | 123 +----------- .../FactoryCacheFactory.java | 4 +- .../jar/helper/JarAsserter.java | 2 +- 98 files changed, 900 insertions(+), 1942 deletions(-) delete mode 100644 equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/RecordObjectAccessorCopyingTest.java (96%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/RecordObjectAccessorScramblingTest.java (74%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/RecordObjectAccessorTest.java (84%) rename equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/{ClassProbeSealedTest.java => ClassAccessorSealedTest.java} (94%) delete mode 100644 equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/{vintage => instantiation}/VintageValueProvider.java (65%) create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/FieldModifier.java (91%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/InPlaceObjectAccessor.java (86%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/ObjectAccessor.java (91%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/RecordObjectAccessor.java (88%) delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/vintage => util}/PrefabValuesApi.java (63%) delete mode 100644 equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/{vintage => }/FactoryCacheTest.java (53%) create mode 100644 equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FieldCacheTest.java delete mode 100644 equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java delete mode 100644 equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/{vintage => instantiation}/VintageValueProviderCreatorTest.java (84%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/{vintage => instantiation}/VintageValueProviderTest.java (75%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/ClassAccessorTest.java (69%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/FieldModifierTest.java (95%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/InPlaceObjectAccessorCopyingTest.java (97%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/InPlaceObjectAccessorScramblingTest.java (88%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/{mutation => }/InPlaceObjectAccessorTest.java (92%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => util}/PrefabValuesApiTest.java (82%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/{internal/reflection/vintage/mutation => testhelpers}/FactoryCacheFactory.java (86%) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java index fd6aa50ae..076a44c41 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java @@ -134,7 +134,7 @@ public void succeed_whenRecordValidatesInput_givenValidPrefabValues() { } @Test - public void succeed_whenRecordHasBoundedWildcardGeneric() { + public void succeed_whenRecord() { EqualsVerifier.forClass(WildcardGenericRecordContainer.class).verify(); } diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java deleted file mode 100644 index 5c2a62dea..000000000 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; - -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.objenesis.Objenesis; -import org.objenesis.ObjenesisStd; - -public class RecordFallbackFactoryTest { - - private FallbackFactory factory; - private VintageValueProvider valueProvider; - private Attributes attributes; - - @BeforeEach - public void setUp() { - Objenesis objenesis = new ObjenesisStd(); - factory = new FallbackFactory<>(objenesis); - CachedValueProvider cache = new CachedValueProvider(); - FactoryCache factoryCache = new FactoryCache(); - factoryCache.put(int.class, values(42, 1337, 42)); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - attributes = Attributes.unlabeled(); - } - - @Test - public void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenticalInRedAndRedCopy() { - Tuple tuple = factory.createValues( - new TypeTag(GenericRecordContainer.class), - valueProvider, - attributes - ); - - assertEquals(tuple.getRed(), tuple.getRedCopy()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); - } - - record GenericRecord(T t) {} - - record GenericRecordContainer(GenericRecord bgr) {} -} diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorCopyingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java similarity index 96% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorCopyingTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java index cbcc3c17a..25c904414 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorCopyingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorScramblingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java similarity index 74% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorScramblingTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java index 7c9a42732..830186672 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorScramblingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java @@ -1,39 +1,29 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; import java.lang.reflect.Constructor; +import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.objenesis.ObjenesisStd; public class RecordObjectAccessorScramblingTest { - private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); - private CachedValueProvider cache; + private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); private FactoryCache factoryCache; private VintageValueProvider valueProvider; @BeforeEach public void setup() throws Exception { - cache = new CachedValueProvider(); factoryCache = JavaApiPrefabValues.build(); - valueProvider = - new VintageValueProvider( - TestValueProviders.empty(), - cache, - factoryCache, - new ObjenesisStd() - ); + valueProvider = new VintageValueProvider(factoryCache, new ObjenesisStd()); } @Test @@ -67,7 +57,7 @@ private RecordObjectAccessor create(T object) { } private ObjectAccessor doScramble(Object object) { - return create(object).scramble(valueProvider, TypeTag.NULL, EMPTY_ATTRIBUTES); + return create(object).scramble(valueProvider, TypeTag.NULL, EMPTY_TYPE_STACK); } record Point(int x, int y) {} diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java similarity index 84% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java index 83a5d6333..dbcbb904f 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessorTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java @@ -1,19 +1,17 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Constructor; +import java.util.LinkedHashSet; import java.util.Objects; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.objenesis.Objenesis; @@ -21,7 +19,7 @@ public class RecordObjectAccessorTest { - private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); + private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); private Objenesis objenesis; private Object recordInstance; @@ -76,14 +74,9 @@ public void fail_whenConstructorThrowsOnSomethingElse() { .of(OtherThrowingConstructorRecord.class, objenesis) .instantiate(); - VintageValueProvider vp = new VintageValueProvider( - TestValueProviders.empty(), - new CachedValueProvider(), - JavaApiPrefabValues.build(), - objenesis - ); + VintageValueProvider vp = new VintageValueProvider(JavaApiPrefabValues.build(), objenesis); ExpectedException - .when(() -> accessorFor(instance).scramble(vp, TypeTag.NULL, EMPTY_ATTRIBUTES)) + .when(() -> accessorFor(instance).scramble(vp, TypeTag.NULL, EMPTY_TYPE_STACK)) .assertThrows(ReflectionException.class) .assertMessageContains("Record:", "failed to run constructor", "prefab values"); } diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java similarity index 94% rename from equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java rename to equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java index f9539c7a5..2b7ad0633 100644 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -public class ClassProbeSealedTest { +public class ClassAccessorSealedTest { @Test public void isNotSealed() { diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java deleted file mode 100644 index afc7eb192..000000000 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; - -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -import java.util.Objects; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.objenesis.Objenesis; -import org.objenesis.ObjenesisStd; - -public class SealedTypesFallbackFactoryTest { - - private FallbackFactory factory; - private VintageValueProvider valueProvider; - private Attributes attributes; - - @BeforeEach - public void setUp() { - Objenesis objenesis = new ObjenesisStd(); - factory = new FallbackFactory<>(objenesis); - CachedValueProvider cache = new CachedValueProvider(); - FactoryCache factoryCache = new FactoryCache(); - factoryCache.put(int.class, values(42, 1337, 42)); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - attributes = Attributes.unlabeled(); - } - - @Test - public void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsField() { - Tuple tuple = factory.createValues( - new TypeTag(SealedParentWithFinalChild.class), - valueProvider, - attributes - ); - - assertEquals(tuple.getRed(), tuple.getRedCopy()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); - } - - public abstract static sealed class SealedParentWithFinalChild permits FinalSealedChild { - - private final int i; - - public SealedParentWithFinalChild(int i) { - this.i = i; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof SealedParentWithFinalChild other && i == other.i; - } - - @Override - public int hashCode() { - return Objects.hash(i); - } - } - - public static final class FinalSealedChild extends SealedParentWithFinalChild { - - private final int j; - - public FinalSealedChild(int i, int j) { - super(i); - this.j = j; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof FinalSealedChild other && super.equals(obj) && j == other.j; - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), j); - } - } -} diff --git a/equalsverifier-core/pom.xml b/equalsverifier-core/pom.xml index 8a04f1f3e..2a565181b 100644 --- a/equalsverifier-core/pom.xml +++ b/equalsverifier-core/pom.xml @@ -86,6 +86,14 @@ ${version.bytebuddy} + + + com.github.spotbugs + spotbugs-annotations + ${version.spotbugs} + provided + + org.junit.jupiter @@ -105,12 +113,6 @@ ${version.commons-lang3} test - - com.github.spotbugs - spotbugs-annotations - ${version.spotbugs} - test - diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java index 8e9aa2e57..5574cfb43 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java @@ -9,10 +9,10 @@ import nl.jqno.equalsverifier.api.EqualsVerifierApi; import nl.jqno.equalsverifier.api.MultipleTypeEqualsVerifierApi; import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.PackageScanner; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.PrefabValuesApi; import nl.jqno.equalsverifier.internal.util.ListBuilders; +import nl.jqno.equalsverifier.internal.util.PrefabValuesApi; import nl.jqno.equalsverifier.internal.util.Validations; import org.objenesis.Objenesis; import org.objenesis.ObjenesisStd; @@ -51,7 +51,7 @@ private ConfiguredEqualsVerifier( public ConfiguredEqualsVerifier copy() { return new ConfiguredEqualsVerifier( EnumSet.copyOf(warningsToSuppress), - factoryCache.copy(), + new FactoryCache().merge(factoryCache), usingGetClass, fieldnameToGetter ); @@ -127,7 +127,7 @@ public SingleTypeEqualsVerifierApi forClass(Class type) { return new SingleTypeEqualsVerifierApi<>( type, EnumSet.copyOf(warningsToSuppress), - factoryCache.copy(), + factoryCache, objenesis, usingGetClass, fieldnameToGetter diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java index 6fb507982..f367a1a4b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java @@ -1,7 +1,7 @@ package nl.jqno.equalsverifier; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; /** * Contains the results of an {@link nl.jqno.equalsverifier.EqualsVerifier} run. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java index 60b05d151..c09b94d68 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java @@ -7,11 +7,10 @@ import nl.jqno.equalsverifier.Func.Func1; import nl.jqno.equalsverifier.Func.Func2; import nl.jqno.equalsverifier.Warning; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.checkers.*; import nl.jqno.equalsverifier.internal.exceptions.MessagingException; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.PrefabValuesApi; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FieldCache; import nl.jqno.equalsverifier.internal.util.*; import nl.jqno.equalsverifier.internal.util.Formatter; import org.objenesis.Objenesis; @@ -32,6 +31,7 @@ public class SingleTypeEqualsVerifierApi implements EqualsVerifierApi { private boolean hasRedefinedSuperclass = false; private Class redefinedSubclass = null; private FactoryCache factoryCache = new FactoryCache(); + private FieldCache fieldCache = new FieldCache(); private CachedHashCodeInitializer cachedHashCodeInitializer = CachedHashCodeInitializer.passthrough(); private Function fieldnameToGetter = null; @@ -39,7 +39,6 @@ public class SingleTypeEqualsVerifierApi implements EqualsVerifierApi { private Set allIncludedFields = new HashSet<>(); private Set nonnullFields = new HashSet<>(); private Set ignoredAnnotationClassNames = new HashSet<>(); - private Set prefabbedFieldNames = new HashSet<>(); private List equalExamples = new ArrayList<>(); private List unequalExamples = new ArrayList<>(); private final Objenesis objenesis; @@ -76,10 +75,6 @@ public SingleTypeEqualsVerifierApi(Class type, Objenesis objenesis) { * equals} method, instead of an {@code instanceof} check. * @param converter A function that converts from field name to getter name. */ - @SuppressFBWarnings( - value = "EI_EXPOSE_REP2", - justification = "FactoryCache is inherently mutable" - ) public SingleTypeEqualsVerifierApi( Class type, EnumSet warningsToSuppress, @@ -90,7 +85,7 @@ public SingleTypeEqualsVerifierApi( ) { this(type, objenesis); this.warningsToSuppress = EnumSet.copyOf(warningsToSuppress); - this.factoryCache = factoryCache; + this.factoryCache = this.factoryCache.merge(factoryCache); this.usingGetClass = usingGetClass; this.fieldnameToGetter = converter; } @@ -148,15 +143,7 @@ public SingleTypeEqualsVerifierApi withPrefabValuesForField( S red, S blue ) { - PrefabValuesApi.addPrefabValuesForField( - factoryCache, - objenesis, - type, - fieldName, - red, - blue - ); - prefabbedFieldNames.add(fieldName); + PrefabValuesApi.addPrefabValuesForField(fieldCache, objenesis, type, fieldName, red, blue); withNonnullFields(fieldName); return this; } @@ -444,7 +431,7 @@ private void performVerification() { Validations.validateClassCanBeVerified(type); Configuration config = buildConfig(); - Context context = new Context<>(config, factoryCache, objenesis); + Context context = new Context<>(config, factoryCache, fieldCache, objenesis); Validations.validateProcessedAnnotations( type, config.getAnnotationCache(), @@ -463,7 +450,7 @@ private Configuration buildConfig() { allExcludedFields, allIncludedFields, nonnullFields, - prefabbedFieldNames, + fieldCache.getFieldNames(), cachedHashCodeInitializer, hasRedefinedSuperclass, redefinedSubclass, diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java deleted file mode 100644 index 2750319d7..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java +++ /dev/null @@ -1,16 +0,0 @@ -package nl.jqno.equalsverifier.internal; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -// CHECKSTYLE OFF: AbbreviationAsWordInName - -/** - * Copied over from spotbugs-annotations to avoid the dependency; see https://github.com/jqno/equalsverifier/issues/1026. - */ -@Retention(RetentionPolicy.CLASS) -public @interface SuppressFBWarnings { - String[] value() default {}; - - String justification() default ""; -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java index 30635bb1a..ca64fabb1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java @@ -2,15 +2,14 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.ClassProbe; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.*; public class AbstractDelegationChecker implements Checker { @@ -64,7 +63,7 @@ private void checkAbstractEqualsAndHashCode() { private void checkAbstractDelegationInFields() { for (Field field : FieldIterable.of(type)) { TypeTag tag = TypeTag.of(field, typeTag); - Tuple tuple = safelyGetTuple(tag, field.getName()); + Tuple tuple = safelyGetTuple(tag); if (tuple != null) { Object instance = tuple.getRed(); Object copy = tuple.getBlue(); @@ -73,9 +72,9 @@ private void checkAbstractDelegationInFields() { } } - private Tuple safelyGetTuple(TypeTag tag, String fieldName) { + private Tuple safelyGetTuple(TypeTag tag) { try { - return valueProvider.provideOrThrow(tag, Attributes.labeled(fieldName)); + return valueProvider.provide(tag); } catch (Exception ignored) { // If it fails for some reason, any reason, just return null so we can skip the test. return null; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java index 3195e1be8..fd53331b1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java @@ -3,11 +3,11 @@ import static nl.jqno.equalsverifier.internal.util.Assert.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.AssertionException; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java index fc7de55b4..815370e31 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java @@ -3,10 +3,10 @@ import static nl.jqno.equalsverifier.internal.util.Assert.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import nl.jqno.equalsverifier.Warning; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.ClassProbe; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java index f9abe6f8c..3ae750f99 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java @@ -5,7 +5,6 @@ import java.util.Map; import java.util.Objects; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -24,7 +23,7 @@ public MapEntryHashCodeRequirementChecker(Context context) { public void check() { if (Map.Entry.class.isAssignableFrom(config.getType())) { Map.Entry e = valueProvider - .>provideOrThrow(config.getTypeTag(), Attributes.unlabeled()) + .>provide(config.getTypeTag()) .getRed(); int expectedHashCode = Objects.hashCode(e.getKey()) ^ Objects.hashCode(e.getValue()); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java index 0ef963e88..9727744bf 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java @@ -9,12 +9,15 @@ import java.util.function.Function; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException; -import nl.jqno.equalsverifier.internal.reflection.*; +import nl.jqno.equalsverifier.internal.reflection.ClassProbe; +import nl.jqno.equalsverifier.internal.reflection.FieldProbe; +import nl.jqno.equalsverifier.internal.reflection.Instantiator; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -64,8 +67,8 @@ public void execute(FieldProbe fieldProbe) { classProbe.hasMethod(getterName) ); - TypeTag sub = new TypeTag(throwingGetterCreator(getterName)); - Tuple tuple = valueProvider.provideOrThrow(sub, Attributes.labeled(fieldName)); + Class sub = throwingGetterCreator(getterName); + Tuple tuple = valueProvider.provide(new TypeTag(sub)); T red1 = tuple.getRed(); T red2 = tuple.getRedCopy(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java index ce83a8c38..0ad2fd058 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java @@ -2,8 +2,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldMutator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java index e3d3b25b1..3d775008a 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java @@ -7,13 +7,11 @@ import java.util.EnumSet; import java.util.Set; import nl.jqno.equalsverifier.Warning; -import nl.jqno.equalsverifier.internal.exceptions.NoValueException; import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -27,6 +25,7 @@ public class ReflexivityFieldCheck implements FieldCheck { private final Set nonnullFields; private final Set prefabbedFields; private final AnnotationCache annotationCache; + private final FieldCache fieldCache; public ReflexivityFieldCheck(Context context) { this.subjectCreator = context.getSubjectCreator(); @@ -38,6 +37,7 @@ public ReflexivityFieldCheck(Context context) { this.nonnullFields = config.getNonnullFields(); this.prefabbedFields = config.getPrefabbedFields(); this.annotationCache = config.getAnnotationCache(); + this.fieldCache = context.getFieldCache(); } @Override @@ -80,9 +80,9 @@ private void checkValueReflexivity(FieldProbe probe) { Field field = probe.getField(); String fieldName = field.getName(); TypeTag tag = TypeTag.of(field, typeTag); - Tuple tuple = valueProvider - .provide(tag, Attributes.labeled(fieldName)) - .orElseThrow(() -> new NoValueException(tag, fieldName)); + Tuple tuple = prefabbedFields.contains(fieldName) + ? fieldCache.get(fieldName) + : valueProvider.provide(tag); Object left = subjectCreator.withFieldSetTo(field, tuple.getRed()); Object right = subjectCreator.withFieldSetTo(field, tuple.getRedCopy()); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java index aa3823061..e05e50ad5 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java @@ -2,13 +2,12 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer; import nl.jqno.equalsverifier.internal.util.Formatter; @@ -41,10 +40,7 @@ public StringFieldCheck( ) public void execute(FieldProbe fieldProbe) { if (String.class.equals(fieldProbe.getType()) && !fieldProbe.isStatic()) { - TypeTag string = new TypeTag(String.class); - String red = valueProvider - .provideOrThrow(string, Attributes.labeled(fieldProbe.getName())) - .getRed(); + String red = valueProvider.provide(new TypeTag(String.class)).getRed(); final T reference; final T copy; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java index cad26b78b..c3611eebc 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.assertTrue; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java index c149c2ccc..261d970a7 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java index 243c7b91f..6e20d3991 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java deleted file mode 100644 index 5a3d5310b..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java +++ /dev/null @@ -1,31 +0,0 @@ -package nl.jqno.equalsverifier.internal.exceptions; - -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; - -@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "EqualsVerifier doesn't serialize.") -public class NoValueException extends MessagingException { - - private final TypeTag tag; - private final String label; - - public NoValueException(TypeTag tag) { - this(tag, null); - } - - public NoValueException(TypeTag tag, String label) { - super(); - this.tag = tag; - this.label = label; - } - - @Override - public String getDescription() { - return ( - "Could not find a value for " + - tag + - (label == null ? "" : " and label " + label) + - ". Please add prefab values for this type." - ); - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java index 1b7d590e4..1221f1c0b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.exceptions; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Iterator; import java.util.LinkedHashSet; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.TypeTag; /** Signals that a recursion has been detected while traversing the fields of a data structure. */ diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java index c7fcf7a1f..b96e779fe 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java @@ -2,10 +2,10 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.classForName; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; /** Allows instantiation of classes that may or may not be present on the classpath. */ diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java new file mode 100644 index 000000000..1d77eabdd --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java @@ -0,0 +1,88 @@ +package nl.jqno.equalsverifier.internal.reflection; + +import java.util.HashMap; +import java.util.Map; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; + +/** Contains a cache of factories, for {@link VintageValueProvider}. */ +public class FactoryCache { + + /** + * We store Strings instead of Classes, so that the cache can be lazy and initializers won't be + * called until the class is actually needed. + */ + private final Map> cache = new HashMap<>(); + + /** + * Adds the given factory to the cache and associates it with the given type. + * + * @param The type of the factory. + * @param type The type to associate with the factory. + * @param factory The factory to associate with the type. + */ + public void put(Class type, PrefabValueFactory factory) { + if (type != null) { + cache.put(type.getName(), factory); + } + } + + /** + * Adds the given factory to the cache and associates it with the given type name. + * + * @param Should match {@code typeName}. + * @param typeName The fully qualified name of the type. + * @param factory The factory to associate with {@code typeName} + */ + public void put(String typeName, PrefabValueFactory factory) { + if (typeName != null) { + cache.put(typeName, factory); + } + } + + /** + * Retrieves the factory from the cache for the given type. + * + *

What happens when there is no factory, is undefined. Always call {@link #contains(Class)} + * first. + * + * @param The returned factory will have this as generic type. + * @param type The type for which a factory is needed. + * @return A factory for the given type, or {@code null} if none is available. + */ + @SuppressWarnings("unchecked") + public PrefabValueFactory get(Class type) { + if (type == null) { + return null; + } + return (PrefabValueFactory) cache.get(type.getName()); + } + + /** + * @param type The type for which a factory is needed. + * @return Whether a factory is available for the given type. + */ + public boolean contains(Class type) { + return cache.containsKey(type.getName()); + } + + /** + * Returns a new {@code FactoryCache} instance containing the factories from {@code this} and + * from the {@code other} cache. + * + * @param other The other cache + * @return a new instance containing factories from {@code this} and {@code other} + */ + public FactoryCache merge(FactoryCache other) { + FactoryCache result = new FactoryCache(); + copy(result, this); + copy(result, other); + return result; + } + + private void copy(FactoryCache to, FactoryCache from) { + for (Map.Entry> entry : from.cache.entrySet()) { + to.put(entry.getKey(), entry.getValue()); + } + } +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java new file mode 100644 index 000000000..455a786e5 --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java @@ -0,0 +1,60 @@ +package nl.jqno.equalsverifier.internal.reflection; + +import java.util.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; + +/** Contains a cache for values connected to specific fields, for {@link SubjectCreator}. */ +public class FieldCache { + + /** + * We store Strings instead of Fields, to make it easier to interact with when we don't + * actually have a reference to a Field. + */ + private final Map> cache = new HashMap<>(); + + /** + * Adds the given factory to the cache and associates it with the given type. + * + * @param The type of the values. + * @param fieldName The name of the field to associate with the values. + * @param tuple The tuple that contains the values. + */ + public void put(String fieldName, Tuple tuple) { + if (fieldName != null) { + cache.put(fieldName, tuple); + } + } + + /** + * Retrieves the values from the cache for the given field. + * + *

What happens when there are no values, is undefined. Always call {@link #contains(String)} + * first. + * + * @param The returned values will have this as generic type. + * @param fieldName The name of the field for which values are needed. + * @return A tuple of values for the given type, or {@code null} if none is available. + */ + @SuppressWarnings("unchecked") + public Tuple get(String fieldName) { + if (fieldName == null) { + return null; + } + return (Tuple) cache.get(fieldName); + } + + /** + * @param fieldName The name of the field for which values are needed. + * @return Whether values are available for the given field. + */ + public boolean contains(String fieldName) { + return cache.containsKey(fieldName); + } + + /** + * @return The fields preset in the cache. + */ + public Set getFieldNames() { + return new HashSet<>(cache.keySet()); + } +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java index 63012e644..56cd194b6 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java @@ -3,10 +3,10 @@ import static nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import nl.jqno.equalsverifier.Warning; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.util.Configuration; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java index ab4417d51..e1db1d3e3 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java @@ -5,21 +5,21 @@ import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.beans.PropertyChangeSupport; import java.io.File; import java.io.PrintStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; +import java.lang.reflect.*; import java.math.BigDecimal; import java.math.BigInteger; -import java.net.InetSocketAddress; -import java.net.URI; -import java.net.URL; +import java.net.*; import java.nio.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.text.*; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.*; @@ -28,10 +28,11 @@ import java.util.concurrent.locks.StampedLock; import java.util.function.Supplier; import java.util.regex.Pattern; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumMapFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumSetFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.ExternalFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; /** * Creates instances of classes for use in a {@link VintageValueProvider} object. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/Tuple.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/Tuple.java index 892be3407..c276f3fac 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/Tuple.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/Tuple.java @@ -1,8 +1,5 @@ package nl.jqno.equalsverifier.internal.reflection; -import java.util.function.BiFunction; -import java.util.function.Function; - /** * Container for three values of the same type: a "red" one, a "blue" one, and a shallow copy of the * "red" one. @@ -55,18 +52,6 @@ public T getRedCopy() { return redCopy; } - public Tuple map(Function fn) { - return Tuple.of(fn.apply(red), fn.apply(blue), fn.apply(redCopy)); - } - - public static Tuple combine(Tuple t, Tuple u, BiFunction fn) { - return Tuple.of( - fn.apply(t.getRed(), u.getRed()), - fn.apply(t.getBlue(), u.getBlue()), - fn.apply(t.getRedCopy(), u.getRedCopy()) - ); - } - /** {@inheritDoc} */ @Override public boolean equals(Object obj) { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java deleted file mode 100644 index e564ecb99..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; - -import java.util.*; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; - -/** - * Provider of instances that have been created before, e.g. by other ValueProviders. - */ -public class CachedValueProvider implements ValueProvider { - - private final Map> cache = new HashMap<>(); - - /** - * Adds a value to the cache. - * - * @param tag The type to assign the value to. - * @param label The label that the value should be linked to. - * @param tuple The value to add to the cache. - */ - public void put(TypeTag tag, String label, Tuple tuple) { - cache.put(Key.of(tag, label), tuple); - } - - /** - * {@inheritDoc}} - */ - @SuppressWarnings("unchecked") - @Override - public Optional> provide(TypeTag tag, Attributes attributes) { - Key first = Key.of(tag, attributes.label); - if (cache.containsKey(first)) { - return Optional.of((Tuple) cache.get(first)); - } - Key second = Key.of(tag, null); - if (cache.containsKey(second)) { - return Optional.of((Tuple) cache.get(second)); - } - return Optional.empty(); - } - - static final class Key { - - final TypeTag tag; - final String label; - - private Key(TypeTag tag, String label) { - this.tag = tag; - this.label = label; - } - - public static Key of(TypeTag tag, String label) { - return new Key(tag, label); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Key)) { - return false; - } - Key other = (Key) obj; - return Objects.equals(tag, other.tag) && Objects.equals(label, other.label); - } - - @Override - public int hashCode() { - return Objects.hash(tag, label); - } - - @Override - public String toString() { - return "Key: [" + tag + "/" + label + "]"; - } - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java deleted file mode 100644 index 3409f23cd..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; - -/** - * Provider of instances of classes, delegating to other ValueProviders in sequence. - */ -public class ChainedValueProvider implements ValueProvider { - - private boolean locked = false; - private final List providers = new ArrayList<>(); - private final CachedValueProvider cache; - - @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "A cache is inherently mutable") - public ChainedValueProvider(CachedValueProvider cache) { - this.cache = cache; - providers.add(cache); - } - - /** - * Adds providers to the chain, so they can be delegated to when providing a value. - * - * @param valueProviders ValueProviders to add to the chain. - */ - public void register(ValueProvider... valueProviders) { - if (locked) { - throw new EqualsVerifierInternalBugException( - "Provider is locked; can't add any new ones." - ); - } - for (ValueProvider p : valueProviders) { - providers.add(p); - } - locked = true; - } - - /** {@inheritDoc} */ - @Override - public Optional> provide(TypeTag tag, Attributes attributes) { - Optional> result = providers - .stream() - .map(vp -> vp.provide(tag, attributes)) - .filter(Optional::isPresent) - .findFirst() - .orElse(Optional.empty()); - - result.ifPresent(r -> cache.put(tag, attributes.label, r)); - return result; - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java index f5871bdf6..86c3a7cb2 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java @@ -1,12 +1,11 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ModuleException; import nl.jqno.equalsverifier.internal.reflection.*; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Rethrow; import org.objenesis.Objenesis; @@ -22,6 +21,7 @@ public class SubjectCreator { private final Configuration config; private final ValueProvider valueProvider; private final ClassProbe classProbe; + private final FieldCache fieldCache; private final Objenesis objenesis; private final InstanceCreator instanceCreator; @@ -30,12 +30,14 @@ public class SubjectCreator { * * @param config A configuration object. * @param valueProvider To provide values for the fields of the subject. + * @param fieldCache Prepared values for the fields of the subject. * @param objenesis Needed by InstanceCreator to instantiate non-record classes. */ @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "A cache is inherently mutable") public SubjectCreator( Configuration config, ValueProvider valueProvider, + FieldCache fieldCache, Objenesis objenesis ) { this.typeTag = config.getTypeTag(); @@ -43,6 +45,7 @@ public SubjectCreator( this.config = config; this.valueProvider = valueProvider; this.classProbe = new ClassProbe<>(type); + this.fieldCache = fieldCache; this.objenesis = objenesis; this.instanceCreator = new InstanceCreator<>(classProbe, objenesis); } @@ -236,12 +239,13 @@ private FieldIterable nonSuperFields() { } private Tuple valuesFor(Field f) { + String fieldName = f.getName(); + if (fieldCache.contains(fieldName)) { + return fieldCache.get(fieldName); + } try { - TypeTag fieldTag = TypeTag.of(f, typeTag); - Tuple tuple = valueProvider.provideOrThrow( - fieldTag, - Attributes.labeled(f.getName()) - ); + Tuple tuple = valueProvider.provide(TypeTag.of(f, typeTag)); + fieldCache.put(fieldName, tuple); return tuple; } catch (ModuleException e) { throw new ModuleException( diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java index 366f6963a..eef125f5c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java @@ -1,8 +1,5 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; -import java.util.LinkedHashSet; -import java.util.Optional; -import nl.jqno.equalsverifier.internal.exceptions.NoValueException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; @@ -17,83 +14,11 @@ */ public interface ValueProvider { /** - * Returns a tuple of prefabricated values of the specified type, or, if none exists, returns - * an empty Optional. + * Returns a tuple of two different prefabricated values of the specified type. * * @param The returned tuple will have this generic type. * @param tag A description of the desired type, including generic parameters. - * @param attributes Provides metadata needed to provide a value. - * @return A tuple of two different values of the given type, or an empty Optional if none - * could be found. + * @return A tuple of two different values of the given type. */ - Optional> provide(TypeTag tag, Attributes attributes); - - /** - * Returns a tuple of prefabricated values of the specified type, or, if none exists, throws a - * NoValueException. - * - * @param The returned tuple will have this generic type. - * @param tag A description of the desired type, including generic parameters. - * @param attributes Provides metadata needed to provide a value. - * @return A tuple of two different values of the given type, or an empty Optional if none - * could be found. - * @throws NoValueException if no value could be found for the given tag. - */ - default Tuple provideOrThrow(TypeTag tag, Attributes attributes) { - return this.provide(tag, attributes).orElseThrow(() -> new NoValueException(tag)); - } - - /** - * Container for metadata needed to provide values. - */ - public static final class Attributes { - - /** - * Values can be assigned to a label; if one is specified, ValueProvider returns the value - * assigned to it (or falls back to the value assigned to a null label). If label is null, - * it immediately returns the value assigned to the null label. - */ - public final String label; - /** - * Keeps track of recursion. - */ - public final LinkedHashSet typeStack; - - /** Private constructor. Use the factories instead. */ - private Attributes(String label, LinkedHashSet typeStack) { - this.label = label; - this.typeStack = typeStack; - } - - /** - * Don't use a label when providing a value. - * - * @return An Attributes object with no label. - */ - public static Attributes unlabeled() { - return new Attributes(null, new LinkedHashSet<>()); - } - - /** - * Use a label when providing a value. - * - * @param label The label to use. - * @return An Attributes object with the given label. - */ - public static Attributes labeled(String label) { - return new Attributes(label, new LinkedHashSet<>()); - } - - /** - * Clones the internal typeStack and adds a type to it. - * - * @param tag A type to add to the recursion checker. - * @return A new Attributes object with a type added to its typeStack. - */ - public Attributes cloneAndAdd(TypeTag tag) { - LinkedHashSet clone = new LinkedHashSet<>(typeStack); - clone.add(tag); - return new Attributes(label, clone); - } - } + Tuple provide(TypeTag tag); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java similarity index 65% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java index 0206a2c8f..4af2fbd1b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java @@ -1,14 +1,12 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.instantiation; -import java.util.Arrays; -import java.util.Optional; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.*; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.util.PrimitiveMappers; @@ -16,7 +14,7 @@ import org.objenesis.Objenesis; /** - * Provider of prefabricated instances of classes, using a "vintage" strategy for doing so. + * Creator of prefabricated instances of classes, using a "vintage" strategy for doing so. * * Vintage in this case means that it employs the creation strategy that EqualsVerifier has been * using since its inception. This strategy is quite hacky and messy, and other strategies might @@ -24,34 +22,28 @@ */ public class VintageValueProvider implements ValueProvider { - private final ValueProvider valueProvider; + // I'd like to remove this, but that affects recursion detection it a way I can't yet explain + private final Map> valueCache = new HashMap<>(); + private final FactoryCache factoryCache; private final PrefabValueFactory fallbackFactory; /** * Constructor. * - * @param valueProvider Will be used to look up values before they are created. - * @param cache The values that have already been constructed. * @param factoryCache The factories that can be used to create values. * @param objenesis To instantiate non-record classes. */ @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "A cache is inherently mutable.") - public VintageValueProvider( - ValueProvider valueProvider, - CachedValueProvider cache, - FactoryCache factoryCache, - Objenesis objenesis - ) { - this.valueProvider = valueProvider; + public VintageValueProvider(FactoryCache factoryCache, Objenesis objenesis) { this.factoryCache = factoryCache; this.fallbackFactory = new FallbackFactory<>(objenesis); } /** {@inheritDoc} */ @Override - public Optional> provide(TypeTag tag, Attributes attributes) { - return Rethrow.rethrow(() -> Optional.of(giveTuple(tag, attributes))); + public Tuple provide(TypeTag tag) { + return Rethrow.rethrow(() -> giveTuple(tag)); } /** @@ -64,11 +56,7 @@ public Optional> provide(TypeTag tag, Attributes attributes) { * @return The "red" prefabricated value. */ public T giveRed(TypeTag tag) { - return giveRed(tag, Attributes.unlabeled()); - } - - public T giveRed(TypeTag tag, Attributes attributes) { - return this.giveTuple(tag, attributes).getRed(); + return this.giveTuple(tag).getRed(); } /** @@ -81,11 +69,7 @@ public T giveRed(TypeTag tag, Attributes attributes) { * @return The "blue" prefabricated value. */ public T giveBlue(TypeTag tag) { - return giveBlue(tag, Attributes.unlabeled()); - } - - public T giveBlue(TypeTag tag, Attributes attributes) { - return this.giveTuple(tag, attributes).getBlue(); + return this.giveTuple(tag).getBlue(); } /** @@ -98,11 +82,7 @@ public T giveBlue(TypeTag tag, Attributes attributes) { * @return A shallow copy of the "red" prefabricated value. */ public T giveRedCopy(TypeTag tag) { - return giveRedCopy(tag, Attributes.unlabeled()); - } - - public T giveRedCopy(TypeTag tag, Attributes attributes) { - return this.giveTuple(tag, attributes).getRedCopy(); + return this.giveTuple(tag).getRedCopy(); } /** @@ -112,11 +92,11 @@ public T giveRedCopy(TypeTag tag, Attributes attributes) { * @param The type of the value. * @param tag A description of the desired type, including generic parameters. * @param value A value that is different from the value that will be returned. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. + * @param typeStack Keeps track of recursion in the type. * @return A value that is different from {@code value}. */ // CHECKSTYLE OFF: CyclomaticComplexity - public T giveOther(TypeTag tag, T value, Attributes attributes) { + public T giveOther(TypeTag tag, T value, LinkedHashSet typeStack) { Class type = tag.getType(); if ( value != null && @@ -126,7 +106,7 @@ public T giveOther(TypeTag tag, T value, Attributes attributes) { throw new ReflectionException("TypeTag does not match value."); } - Tuple tuple = giveTuple(tag, attributes); + Tuple tuple = giveTuple(tag, typeStack); if (tuple.getRed() == null) { return null; } @@ -157,27 +137,44 @@ private boolean arraysAreDeeplyEqual(Object x, Object y) { return Arrays.deepEquals(new Object[] { x }, new Object[] { y }); } - @SuppressWarnings("unchecked") - private Tuple giveTuple(TypeTag tag, Attributes attributes) { - if (attributes.typeStack.contains(tag)) { - throw new RecursionException(attributes.typeStack); + /** + * Makes sure that values for the specified type are present in the cache, but doesn't return + * them. + * + * @param The desired type. + * @param tag A description of the desired type, including generic parameters. + * @param typeStack Keeps track of recursion in the type. + */ + public void realizeCacheFor(TypeTag tag, LinkedHashSet typeStack) { + if (!valueCache.containsKey(tag)) { + Tuple tuple = createTuple(tag, typeStack); + valueCache.put(tag, tuple); } + } + + private Tuple giveTuple(TypeTag tag) { + return giveTuple(tag, new LinkedHashSet<>()); + } - Optional> provided = valueProvider.provide(tag, attributes); - if (provided.isPresent()) { - return provided.get(); + @SuppressWarnings("unchecked") + private Tuple giveTuple(TypeTag tag, LinkedHashSet typeStack) { + realizeCacheFor(tag, typeStack); + return (Tuple) valueCache.get(tag); + } + + private Tuple createTuple(TypeTag tag, LinkedHashSet typeStack) { + if (typeStack.contains(tag)) { + throw new RecursionException(typeStack); } Class type = tag.getType(); - if (attributes.label != null && factoryCache.contains(type, attributes.label)) { - PrefabValueFactory factory = factoryCache.get(type, attributes.label); - return factory.createValues(tag, this, attributes); - } if (factoryCache.contains(type)) { PrefabValueFactory factory = factoryCache.get(type); - return factory.createValues(tag, this, attributes); + return factory.createValues(tag, this, typeStack); } - return (Tuple) fallbackFactory.createValues(tag, this, attributes); + @SuppressWarnings("unchecked") + Tuple result = (Tuple) fallbackFactory.createValues(tag, this, typeStack); + return result; } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java new file mode 100644 index 000000000..e19fde95d --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java @@ -0,0 +1,108 @@ +package nl.jqno.equalsverifier.internal.reflection.vintage; + +import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.reflection.Instantiator; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import org.objenesis.Objenesis; + +/** + * Instantiates and populates objects of a given class. {@link ClassAccessor} can create two + * different instances of T, which are guaranteed not to be equal to each other, and which contain + * no null values. + * + * @param A class. + */ +public class ClassAccessor { + + private final Class type; + private final VintageValueProvider valueProvider; + private final Objenesis objenesis; + + /** Private constructor. Call {@link #of(Class, PrefabValues)} instead. */ + ClassAccessor(Class type, VintageValueProvider valueProvider, Objenesis objenesis) { + this.type = type; + this.valueProvider = valueProvider; + this.objenesis = objenesis; + } + + /** + * Factory method. + * + * @param The class on which {@link ClassAccessor} operates. + * @param type The class on which {@link ClassAccessor} operates. Should be the same as T. + * @param valueProvider Prefabricated values with which to fill instantiated objects. + * @param objenesis To instantiate non-record classes. + * @return A {@link ClassAccessor} for T. + */ + public static ClassAccessor of( + Class type, + VintageValueProvider valueProvider, + Objenesis objenesis + ) { + return new ClassAccessor<>(type, valueProvider, objenesis); + } + + /** + * Returns an instance of T that is not equal to the instance of T returned by {@link + * #getBlueObject(TypeTag, LinkedHashSet)}. + * + * @param enclosingType Describes the type that contains this object as a field, to determine + * any generic parameters it may contain. + * @param typeStack Keeps track of recursion in the type. + * @return An instance of T. + */ + public T getRedObject(TypeTag enclosingType, LinkedHashSet typeStack) { + return getRedAccessor(enclosingType, typeStack).get(); + } + + /** + * Returns an {@link ObjectAccessor} for {@link #getRedObject(TypeTag, LinkedHashSet)}. + * + * @param enclosingType Describes the type that contains this object as a field, to determine + * any generic parameters it may contain. + * @param typeStack Keeps track of recursion in the type. + * @return An {@link ObjectAccessor} for {@link #getRedObject}. + */ + public ObjectAccessor getRedAccessor( + TypeTag enclosingType, + LinkedHashSet typeStack + ) { + return buildObjectAccessor().scramble(valueProvider, enclosingType, typeStack); + } + + /** + * Returns an instance of T that is not equal to the instance of T returned by {@link + * #getRedObject(TypeTag, LinkedHashSet)}. + * + * @param enclosingType Describes the type that contains this object as a field, to determine + * any generic parameters it may contain. + * @param typeStack Keeps track of recursion in the type. + * @return An instance of T. + */ + public T getBlueObject(TypeTag enclosingType, LinkedHashSet typeStack) { + return getBlueAccessor(enclosingType, typeStack).get(); + } + + /** + * Returns an {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, LinkedHashSet)}. + * + * @param enclosingType Describes the type that contains this object as a field, to determine + * any generic parameters it may contain. + * @param typeStack Keeps track of recursion in the type. + * @return An {@link ObjectAccessor} for {@link #getBlueObject(TypeTag, LinkedHashSet)}. + */ + public ObjectAccessor getBlueAccessor( + TypeTag enclosingType, + LinkedHashSet typeStack + ) { + return buildObjectAccessor() + .scramble(valueProvider, enclosingType, typeStack) + .scramble(valueProvider, enclosingType, typeStack); + } + + private ObjectAccessor buildObjectAccessor() { + T object = Instantiator.of(type, objenesis).instantiate(); + return ObjectAccessor.of(object); + } +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java deleted file mode 100644 index 61ea3e55b..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCache.java +++ /dev/null @@ -1,180 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; - -/** Contains a cache of factories, for {@link VintageValueProvider}. */ -public class FactoryCache { - - /** - * We store Strings instead of Classes, so that the cache can be lazy and initializers won't be - * called until the class is actually needed. - */ - private final Map> cache = new HashMap<>(); - - /** - * Adds the given factory to the cache and associates it with the given type. - * - * @param The type of the factory. - * @param type The type to associate with the factory. - * @param factory The factory to associate with the type. - */ - public void put(Class type, PrefabValueFactory factory) { - if (type != null) { - put(Key.of(type.getName()), factory); - } - } - - /** - * Adds the given factory to the cache and associates it with the given type. - * - * @param The type of the factory. - * @param type The type to associate with the factory. - * @param label The label that the factory is linked to, or null if it is not assigned to any label. - * @param factory The factory to associate with the type. - */ - public void put(Class type, String label, PrefabValueFactory factory) { - if (type != null) { - put(Key.of(type.getName(), label), factory); - } - } - - /** - * Adds the given factory to the cache and associates it with the given type name. - * - * @param Should match {@code typeName}. - * @param typeName The fully qualified name of the type. - * @param factory The factory to associate with {@code typeName} - */ - public void put(String typeName, PrefabValueFactory factory) { - if (typeName != null) { - put(Key.of(typeName), factory); - } - } - - private void put(Key key, PrefabValueFactory factory) { - cache.put(key, factory); - } - - /** - * Retrieves the factory from the cache for the given type. - * - *

What happens when there is no factory, is undefined. Always call {@link #contains(Class)} - * first. - * - * @param The returned factory will have this as generic type. - * @param type The type for which a factory is needed. - * @return A factory for the given type, or {@code null} if none is available. - */ - public PrefabValueFactory get(Class type) { - return get(type, null); - } - - /** - * Retrieves the factory from the cache for the given type. - * - *

What happens when there is no factory, is undefined. Always call {@link #contains(Class)} - * first. - * - * @param The returned factory will have this as generic type. - * @param type The type for which a factory is needed. - * @param label Returns only the factory assigned to the given label, or if label is null, - * returns the factory that's not assigned to any label. - * @return A factory for the given type, or {@code null} if none is available. - */ - @SuppressWarnings("unchecked") - public PrefabValueFactory get(Class type, String label) { - if (type == null) { - return null; - } - return (PrefabValueFactory) cache.get(Key.of(type.getName(), label)); - } - - /** - * @param type The type for which a factory is needed. - * @return Whether a factory is available for the given type. - */ - public boolean contains(Class type) { - return cache.containsKey(Key.of(type.getName())); - } - - /** - * @param type The type for which a factory is needed. - * @param label The label that the factory needs to be assigned to. - * @return Whether a factory is available for the given type. - */ - public boolean contains(Class type, String label) { - return cache.containsKey(Key.of(type.getName(), label)); - } - - /** - * Returns a new {@code FactoryCache} instance containing the factories from {@code this}. - * - * @return a new instance containing factories from {@code this} - */ - public FactoryCache copy() { - FactoryCache result = new FactoryCache(); - addAll(result, this); - return result; - } - - /** - * Returns a new {@code FactoryCache} instance containing the factories from {@code this} and - * from the {@code other} cache. - * - * @param other The other cache - * @return a new instance containing factories from {@code this} and {@code other} - */ - public FactoryCache merge(FactoryCache other) { - FactoryCache result = new FactoryCache(); - addAll(result, this); - addAll(result, other); - return result; - } - - private void addAll(FactoryCache to, FactoryCache from) { - for (Map.Entry> entry : from.cache.entrySet()) { - to.put(entry.getKey(), entry.getValue()); - } - } - - static final class Key { - - final String typeName; - final String label; - - private Key(String typeName, String label) { - this.typeName = typeName; - this.label = label; - } - - public static Key of(String typeName) { - return new Key(typeName, null); - } - - public static Key of(String typeName, String label) { - return new Key(typeName, label); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Key)) { - return false; - } - Key other = (Key) obj; - return Objects.equals(typeName, other.typeName) && Objects.equals(label, other.label); - } - - @Override - public int hashCode() { - return Objects.hash(typeName, label); - } - - @Override - public String toString() { - return "Key: [" + typeName + "/" + label + "]"; - } - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java similarity index 91% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifier.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java index fd5725b16..0b91e5f87 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java @@ -1,13 +1,13 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; import java.lang.reflect.Field; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public final class FieldModifier { @@ -53,17 +53,17 @@ public void copyTo(Object to) { * will be taken from it. * @param enclosingType A tag for the type that contains the field. Needed to determine a * generic type, if it has one.. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. + * @param typeStack Keeps track of recursion in the type. * @throws ReflectionException If the operation fails. */ public void changeField( VintageValueProvider valueProvider, TypeTag enclosingType, - Attributes attributes + LinkedHashSet typeStack ) { FieldChanger fm = () -> { TypeTag tag = TypeTag.of(field, enclosingType); - Object newValue = valueProvider.giveOther(tag, field.get(object), attributes); + Object newValue = valueProvider.giveOther(tag, field.get(object), typeStack); field.set(object, newValue); }; change(fm, false); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java similarity index 86% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java index 89943838f..c9cf1c573 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java @@ -1,11 +1,11 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import java.lang.reflect.Field; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** @@ -35,10 +35,10 @@ public T copy(Objenesis objenesis) { public ObjectAccessor scramble( VintageValueProvider valueProvider, TypeTag enclosingType, - Attributes attributes + LinkedHashSet typeStack ) { for (Field field : FieldIterable.of(type())) { - fieldModifierFor(field).changeField(valueProvider, enclosingType, attributes); + fieldModifierFor(field).changeField(valueProvider, enclosingType, typeStack); } return this; } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java similarity index 91% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java index 7cdd484cb..480e30224 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.RecordsHelper; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** @@ -95,12 +95,12 @@ public Class type() { * @param valueProvider Prefabricated values to take values from. * @param enclosingType Describes the type that contains this object as a field, to determine * any generic parameters it may contain. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. + * @param typeStack Keeps track of recursion in the type. * @return An accessor to the scrambled object. */ public abstract ObjectAccessor scramble( VintageValueProvider valueProvider, TypeTag enclosingType, - Attributes attributes + LinkedHashSet typeStack ); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java similarity index 88% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java index 98a80dd49..c1f63ea44 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/RecordObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java @@ -1,14 +1,14 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import java.lang.reflect.Field; +import java.util.LinkedHashSet; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.RecordProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** @@ -40,12 +40,12 @@ public T copy(Objenesis objenesis) { public ObjectAccessor scramble( VintageValueProvider valueProvider, TypeTag enclosingType, - Attributes attributes + LinkedHashSet typeStack ) { return makeAccessor(f -> { Object value = getField(f); TypeTag tag = TypeTag.of(f, enclosingType); - return valueProvider.giveOther(tag, value, attributes); + return valueProvider.giveOther(tag, value, typeStack); }); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java deleted file mode 100644 index bc4757e96..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessor.java +++ /dev/null @@ -1,68 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; - -import nl.jqno.equalsverifier.internal.reflection.Instantiator; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import org.objenesis.Objenesis; - -/** - * Instantiates and populates objects of a given class. {@link ClassAccessor} can create two - * different instances of T, which are guaranteed not to be equal to each other, and which contain - * no null values. - * - * @param A class. - */ -public class ClassAccessor { - - private final Class type; - private final VintageValueProvider valueProvider; - private final Objenesis objenesis; - - /** - * Constructor. - * - * @param type The class on which {@link ClassAccessor} operates. Should be the same as T. - * @param valueProvider Prefabricated values with which to fill instantiated objects. - * @param objenesis To instantiate non-record classes. - */ - public ClassAccessor(Class type, VintageValueProvider valueProvider, Objenesis objenesis) { - this.type = type; - this.valueProvider = valueProvider; - this.objenesis = objenesis; - } - - /** - * Returns an instance of T that is not equal to the instance of T returned by {@link - * #getBlueObject(TypeTag, Attributes)}. - * - * @param enclosingType Describes the type that contains this object as a field, to determine - * any generic parameters it may contain. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. - * @return An instance of T. - */ - public T getRedObject(TypeTag enclosingType, Attributes attributes) { - return buildObjectAccessor().scramble(valueProvider, enclosingType, attributes).get(); - } - - /** - * Returns an instance of T that is not equal to the instance of T returned by {@link - * #getRedObject(TypeTag, Attributes)}. - * - * @param enclosingType Describes the type that contains this object as a field, to determine - * any generic parameters it may contain. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. - * @return An instance of T. - */ - public T getBlueObject(TypeTag enclosingType, Attributes attributes) { - return buildObjectAccessor() - .scramble(valueProvider, enclosingType, attributes) - .scramble(valueProvider, enclosingType, attributes) - .get(); - } - - private ObjectAccessor buildObjectAccessor() { - T object = Instantiator.of(type, objenesis).instantiate(); - return ObjectAccessor.of(object); - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java index 3346e071f..0058867ad 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java @@ -1,14 +1,14 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Abstract implementation of {@link PrefabValueFactory} that provides helper functions for dealing @@ -18,6 +18,13 @@ public abstract class AbstractGenericFactory implements PrefabValueFactory public static final TypeTag OBJECT_TYPE_TAG = new TypeTag(Object.class); + protected LinkedHashSet cloneWith(LinkedHashSet typeStack, TypeTag tag) { + @SuppressWarnings("unchecked") + LinkedHashSet clone = (LinkedHashSet) typeStack.clone(); + clone.add(tag); + return clone; + } + protected TypeTag copyGenericTypesInto(Class type, TypeTag source) { List genericTypes = new ArrayList<>(); for (TypeTag tag : source.getGenericTypes()) { @@ -30,22 +37,23 @@ protected TypeTag determineAndCacheActualTypeTag( int n, TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - return determineAndCacheActualTypeTag(n, tag, valueProvider, attributes, null); + return determineAndCacheActualTypeTag(n, tag, valueProvider, typeStack, null); } protected TypeTag determineAndCacheActualTypeTag( int n, TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes, + LinkedHashSet typeStack, Class bottomType ) { TypeTag result = determineActualTypeTagFor(n, tag); if (bottomType != null && result.getType().equals(Object.class)) { result = new TypeTag(bottomType); } + valueProvider.realizeCacheFor(result, typeStack); return result; } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java index 5b8f782c1..1b1222861 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java @@ -1,10 +1,10 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +import java.util.LinkedHashSet; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public class CopyFactory extends AbstractGenericFactory { @@ -20,14 +20,15 @@ public CopyFactory(Class source, Function copy) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag sourceTag = copyGenericTypesInto(source, tag); + valueProvider.realizeCacheFor(sourceTag, clone); - S redSource = valueProvider.giveRed(sourceTag, clone); - S blueSource = valueProvider.giveBlue(sourceTag, clone); - S redCopySource = valueProvider.giveRedCopy(sourceTag, clone); + S redSource = valueProvider.giveRed(sourceTag); + S blueSource = valueProvider.giveBlue(sourceTag); + S redCopySource = valueProvider.giveRedCopy(sourceTag); return Tuple.of(copy.apply(redSource), copy.apply(blueSource), copy.apply(redCopySource)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java index abbf32cac..5b1424694 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java @@ -1,12 +1,12 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; @SuppressWarnings({ "unchecked", "rawtypes" }) public final class EnumMapFactory extends AbstractGenericFactory { @@ -21,18 +21,18 @@ public EnumMapFactory(Function factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone, Enum.class); Map red = new HashMap<>(); Map blue = new HashMap<>(); Map redCopy = new HashMap<>(); - red.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); - blue.put(valueProvider.giveBlue(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); - redCopy.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); + red.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); + blue.put(valueProvider.giveBlue(keyTag), valueProvider.giveBlue(valueTag)); + redCopy.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); return Tuple.of(factory.apply(red), factory.apply(blue), factory.apply(redCopy)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java index f6dae8634..61a59e447 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java @@ -2,11 +2,11 @@ import java.util.Collection; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.function.Function; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that instantiates EnumSets using reflection, while @@ -25,17 +25,17 @@ public EnumSetFactory(Function factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag entryTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); Collection red = new HashSet<>(); Collection blue = new HashSet<>(); Collection redCopy = new HashSet<>(); - red.add(valueProvider.giveRed(entryTag, clone)); - blue.add(valueProvider.giveBlue(entryTag, clone)); - redCopy.add(valueProvider.giveRed(entryTag, clone)); + red.add(valueProvider.giveRed(entryTag)); + blue.add(valueProvider.giveBlue(entryTag)); + redCopy.add(valueProvider.giveRed(entryTag)); return new Tuple<>(factory.apply(red), factory.apply(blue), factory.apply(redCopy)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java index d777d7a64..0bea3340b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java @@ -3,12 +3,12 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.classes; import static nl.jqno.equalsverifier.internal.reflection.Util.objects; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.FactoryProvider; public class ExternalFactory implements PrefabValueFactory { @@ -27,7 +27,7 @@ public ExternalFactory(String factoryName) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { if (factoryCache == null) { ConditionalInstantiator ci = new ConditionalInstantiator(factoryName); @@ -36,6 +36,6 @@ public Tuple createValues( } PrefabValueFactory factory = factoryCache.get(tag.getType()); - return factory.createValues(tag, valueProvider, attributes); + return factory.createValues(tag, valueProvider, typeStack); } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java index 917f7eb88..eb69ea6b3 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java @@ -1,13 +1,14 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.lang.reflect.Array; -import nl.jqno.equalsverifier.internal.reflection.ClassProbe; +import java.lang.reflect.Field; +import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.reflection.FieldIterable; +import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.InstanceCreator; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ClassAccessor; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor; import org.objenesis.Objenesis; /** @@ -28,9 +29,11 @@ public FallbackFactory(Objenesis objenesis) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + @SuppressWarnings("unchecked") + LinkedHashSet clone = (LinkedHashSet) typeStack.clone(); + clone.add(tag); Class type = tag.getType(); if (type.isEnum()) { @@ -40,6 +43,7 @@ public Tuple createValues( return giveArrayInstances(tag, valueProvider, clone); } + traverseFields(tag, valueProvider, clone); return giveInstances(tag, valueProvider, clone); } @@ -61,35 +65,47 @@ private Tuple giveEnumInstances(TypeTag tag) { private Tuple giveArrayInstances( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { Class type = tag.getType(); Class componentType = type.getComponentType(); TypeTag componentTag = new TypeTag(componentType); + valueProvider.realizeCacheFor(componentTag, typeStack); T red = (T) Array.newInstance(componentType, 1); - Array.set(red, 0, valueProvider.giveRed(componentTag, attributes)); + Array.set(red, 0, valueProvider.giveRed(componentTag)); T blue = (T) Array.newInstance(componentType, 1); - Array.set(blue, 0, valueProvider.giveBlue(componentTag, attributes)); + Array.set(blue, 0, valueProvider.giveBlue(componentTag)); T redCopy = (T) Array.newInstance(componentType, 1); - Array.set(redCopy, 0, valueProvider.giveRed(componentTag, attributes)); + Array.set(redCopy, 0, valueProvider.giveRed(componentTag)); return new Tuple<>(red, blue, redCopy); } - private Tuple giveInstances( + private void traverseFields( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - ClassAccessor accessor = new ClassAccessor<>(tag.getType(), valueProvider, objenesis); - T red = accessor.getRedObject(tag, attributes); - T blue = accessor.getBlueObject(tag, attributes); - - @SuppressWarnings("unchecked") - Class actualType = (Class) red.getClass(); - T redCopy = new InstanceCreator<>(new ClassProbe(actualType), objenesis).copy(red); + Class type = tag.getType(); + for (Field field : FieldIterable.of(type)) { + FieldProbe probe = FieldProbe.of(field); + boolean isStaticAndFinal = probe.isStatic() && probe.isFinal(); + if (!isStaticAndFinal) { + valueProvider.realizeCacheFor(TypeTag.of(field, tag), typeStack); + } + } + } + private Tuple giveInstances( + TypeTag tag, + VintageValueProvider valueProvider, + LinkedHashSet typeStack + ) { + ClassAccessor accessor = ClassAccessor.of(tag.getType(), valueProvider, objenesis); + T red = accessor.getRedObject(tag, typeStack); + T blue = accessor.getBlueObject(tag, typeStack); + T redCopy = accessor.getRedObject(tag, typeStack); return new Tuple<>(red, blue, redCopy); } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java index 40030f4de..f835cfe90 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java @@ -1,11 +1,11 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Supplier; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that specializes in creating implementations of @@ -24,9 +24,9 @@ public MapFactory(Supplier createEmpty) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone); @@ -34,16 +34,16 @@ public Tuple createValues( // values. // But don't do it in the Blue map, or they may cancel each other out again. - Object redKey = valueProvider.giveRed(keyTag, clone); - Object blueKey = valueProvider.giveBlue(keyTag, clone); - Object blueValue = valueProvider.giveBlue(valueTag, clone); + Object redKey = valueProvider.giveRed(keyTag); + Object blueKey = valueProvider.giveBlue(keyTag); + Object blueValue = valueProvider.giveBlue(valueTag); T red = createEmpty.get(); red.put(redKey, blueValue); T blue = createEmpty.get(); if (!redKey.equals(blueKey)) { // This happens with single-element enums - blue.put(valueProvider.giveBlue(keyTag, clone), blueValue); + blue.put(valueProvider.giveBlue(keyTag), blueValue); } T redCopy = createEmpty.get(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java index e7c2c3c13..4616c2660 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java @@ -1,9 +1,9 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Creates instances of generic types for use as prefab value. @@ -17,8 +17,13 @@ public interface PrefabValueFactory { * * @param tag The typetag of the type for which to create values. * @param valueProvider Repository for querying instances of generic types of the type tag. - * @param attributes Provides metadata needed to provide a value and to keep track of recursion. + * @param typeStack A stack of {@link TypeTag}s that require tag in order to be created. Used + * for recursion detection. * @return A "red" instance of {@code T}. */ - Tuple createValues(TypeTag tag, VintageValueProvider valueProvider, Attributes attributes); + Tuple createValues( + TypeTag tag, + VintageValueProvider valueProvider, + LinkedHashSet typeStack + ); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java index 3012b2cf5..44a7ae041 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java @@ -1,9 +1,9 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that holds on to two instances that have already @@ -21,7 +21,7 @@ public SimpleFactory(T red, T blue, T redCopy) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { return tuple; } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java index 558a8465b..748f64f7f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java @@ -1,13 +1,13 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.function.Supplier; import nl.jqno.equalsverifier.Func; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public class SimpleGenericFactory extends AbstractGenericFactory { @@ -23,9 +23,9 @@ public SimpleGenericFactory(Func factory, Supplier emptyFactory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); List redValues = new ArrayList<>(); List blueValues = new ArrayList<>(); @@ -35,8 +35,8 @@ public Tuple createValues( for (int i = 0; i < n; i++) { TypeTag paramTag = determineAndCacheActualTypeTag(i, tag, valueProvider, clone); - Object redValue = valueProvider.giveRed(paramTag, clone); - Object blueValue = valueProvider.giveBlue(paramTag, clone); + Object redValue = valueProvider.giveRed(paramTag); + Object blueValue = valueProvider.giveBlue(paramTag); if (redValue.equals(blueValue)) { // This happens with single-element enums useEmpty = true; } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java index 9499349f6..2312d3b5a 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java @@ -7,7 +7,7 @@ import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; import java.awt.image.BufferedImage; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; public final class AwtFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java index 9da2eef3b..c81cda452 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java @@ -1,6 +1,6 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; public interface FactoryProvider { FactoryCache getFactoryCache(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java index e9860bd40..4416de38c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java @@ -6,12 +6,14 @@ import com.google.common.reflect.TypeToken; import java.util.*; import java.util.function.Supplier; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumMapFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumSetFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories; public final class GuavaFactoryProvider implements FactoryProvider { @@ -158,24 +160,18 @@ private MultimapFactory(Supplier factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone); T red = factory.get(); T blue = factory.get(); T redCopy = factory.get(); - red.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone)); - blue.put( - valueProvider.giveBlue(keyTag, clone), - valueProvider.giveBlue(valueTag, clone) - ); - redCopy.put( - valueProvider.giveRed(keyTag, clone), - valueProvider.giveBlue(valueTag, clone) - ); + red.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); + blue.put(valueProvider.giveBlue(keyTag), valueProvider.giveBlue(valueTag)); + redCopy.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); return Tuple.of(red, blue, redCopy); } @@ -194,9 +190,9 @@ private TableFactory(Supplier factory) { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { - Attributes clone = attributes.cloneAndAdd(tag); + LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag columnTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone); TypeTag rowTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone); TypeTag valueTag = determineAndCacheActualTypeTag(2, tag, valueProvider, clone); @@ -205,19 +201,19 @@ public Tuple createValues( T blue = factory.get(); T redCopy = factory.get(); red.put( - valueProvider.giveRed(columnTag, clone), - valueProvider.giveRed(rowTag, clone), - valueProvider.giveBlue(valueTag, clone) + valueProvider.giveRed(columnTag), + valueProvider.giveRed(rowTag), + valueProvider.giveBlue(valueTag) ); blue.put( - valueProvider.giveBlue(columnTag, clone), - valueProvider.giveBlue(rowTag, clone), - valueProvider.giveBlue(valueTag, clone) + valueProvider.giveBlue(columnTag), + valueProvider.giveBlue(rowTag), + valueProvider.giveBlue(valueTag) ); redCopy.put( - valueProvider.giveRed(columnTag, clone), - valueProvider.giveRed(rowTag, clone), - valueProvider.giveBlue(valueTag, clone) + valueProvider.giveRed(columnTag), + valueProvider.giveRed(rowTag), + valueProvider.giveBlue(valueTag) ); return Tuple.of(red, blue, redCopy); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java index f601fa8cb..aa2b6a3ca 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java @@ -5,16 +5,10 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.objects; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.copy; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Function; -import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.*; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; @@ -114,22 +108,22 @@ static final class PropertyFactory extends AbstractGenericFactory { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { ConditionalInstantiator ci = new ConditionalInstantiator(fullyQualifiedTypeName); TypeTag singleParameterTag = copyGenericTypesInto(parameterRawType, tag); T red = ci.instantiate( classes(parameterRawType), - objects(valueProvider.giveRed(singleParameterTag, attributes)) + objects(valueProvider.giveRed(singleParameterTag)) ); T blue = ci.instantiate( classes(parameterRawType), - objects(valueProvider.giveBlue(singleParameterTag, attributes)) + objects(valueProvider.giveBlue(singleParameterTag)) ); T redCopy = ci.instantiate( classes(parameterRawType), - objects(valueProvider.giveRed(singleParameterTag, attributes)) + objects(valueProvider.giveRed(singleParameterTag)) ); return Tuple.of(red, blue, redCopy); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java index b968c0bc6..386bb67ae 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java @@ -4,7 +4,7 @@ import javax.naming.Reference; import javax.swing.tree.DefaultMutableTreeNode; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; public final class JavaxFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java index 33eb24584..da40b542d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import org.joda.time.*; import org.joda.time.chrono.GregorianChronology; import org.joda.time.chrono.ISOChronology; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java index 72e45f836..edb25d411 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java @@ -4,7 +4,7 @@ import java.rmi.dgc.VMID; import java.rmi.server.UID; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; public final class RmiFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java index 2749f0320..523cc4e97 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java @@ -1,6 +1,6 @@ package nl.jqno.equalsverifier.internal.testhelpers; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.MessagingException; @SuppressFBWarnings( diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java deleted file mode 100644 index 3e971ef63..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/TestValueProviders.java +++ /dev/null @@ -1,20 +0,0 @@ -package nl.jqno.equalsverifier.internal.testhelpers; - -import java.util.Optional; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; - -public final class TestValueProviders { - - private TestValueProviders() {} - - public static ValueProvider empty() { - return new ValueProvider() { - @Override - public Optional> provide(TypeTag tag, Attributes attributes) { - return Optional.empty(); - } - }; - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java index feb7cd492..9b67fd1e1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java @@ -1,9 +1,9 @@ package nl.jqno.equalsverifier.internal.testhelpers; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.util.Objects; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java index 697631262..a45fc40d4 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java @@ -2,10 +2,10 @@ import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.SuperclassIterable; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java index 428a617cf..72c06ef98 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java @@ -1,11 +1,11 @@ package nl.jqno.equalsverifier.internal.util; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; import nl.jqno.equalsverifier.Warning; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.*; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java index ae240d693..e70f1620d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java @@ -1,11 +1,10 @@ package nl.jqno.equalsverifier.internal.util; -import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.reflection.ClassProbe; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; public final class Context { @@ -13,22 +12,30 @@ public final class Context { private final Class type; private final Configuration configuration; private final ClassProbe classProbe; + private final FieldCache fieldCache; - private final ValueProvider valueProvider; private final SubjectCreator subjectCreator; + private final ValueProvider valueProvider; @SuppressFBWarnings( value = "EI_EXPOSE_REP2", justification = "FieldCache is inherently mutable" ) - public Context(Configuration configuration, FactoryCache factoryCache, Objenesis objenesis) { + public Context( + Configuration configuration, + FactoryCache factoryCache, + FieldCache fieldCache, + Objenesis objenesis + ) { this.type = configuration.getType(); this.configuration = configuration; this.classProbe = new ClassProbe<>(configuration.getType()); + this.fieldCache = fieldCache; FactoryCache cache = JavaApiPrefabValues.build().merge(factoryCache); - this.valueProvider = DefaultValueProviders.create(cache, objenesis); - this.subjectCreator = new SubjectCreator<>(configuration, valueProvider, objenesis); + this.valueProvider = new VintageValueProvider(cache, objenesis); + this.subjectCreator = + new SubjectCreator<>(configuration, valueProvider, fieldCache, objenesis); } public Class getType() { @@ -43,6 +50,11 @@ public ClassProbe getClassProbe() { return classProbe; } + @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "A cache is inherently mutable") + public FieldCache getFieldCache() { + return fieldCache; + } + @SuppressFBWarnings( value = "EI_EXPOSE_REP", justification = "VintageValueProvider can use a mutable cache." diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java deleted file mode 100644 index 664cd03b6..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/DefaultValueProviders.java +++ /dev/null @@ -1,32 +0,0 @@ -package nl.jqno.equalsverifier.internal.util; - -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ChainedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import org.objenesis.Objenesis; - -public final class DefaultValueProviders { - - private DefaultValueProviders() {} - - public static ValueProvider create(FactoryCache factoryCache, Objenesis objenesis) { - CachedValueProvider cache = new CachedValueProvider(); - - ChainedValueProvider mainChain = new ChainedValueProvider(cache); - ChainedValueProvider vintageChain = new ChainedValueProvider(cache); - - ValueProvider vintage = new VintageValueProvider( - vintageChain, - cache, - factoryCache, - objenesis - ); - - mainChain.register(cache, vintage); - vintageChain.register(cache); - - return mainChain; - } -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java similarity index 63% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApi.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java index 0b1a86954..8bc5c9c0c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApi.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java @@ -1,15 +1,15 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.util; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.simple; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; -import java.lang.reflect.Field; import nl.jqno.equalsverifier.Func.Func1; import nl.jqno.equalsverifier.Func.Func2; -import nl.jqno.equalsverifier.internal.reflection.SuperclassIterable; -import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ObjectAccessor; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FieldCache; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.vintage.ObjectAccessor; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; -import nl.jqno.equalsverifier.internal.util.Validations; import org.objenesis.Objenesis; public final class PrefabValuesApi { @@ -40,47 +40,27 @@ public static void addPrefabValues( @SuppressWarnings("unchecked") public static void addPrefabValuesForField( - FactoryCache factoryCache, + FieldCache fieldCache, Objenesis objenesis, - Class enclosingType, + Class type, String fieldName, T red, T blue ) { - Field field = findField(enclosingType, fieldName); - Class type = (Class) field.getType(); - - Validations.validateRedAndBluePrefabValues(type, red, blue); - Validations.validateFieldTypeMatches(field, red.getClass()); + Validations.validateRedAndBluePrefabValues((Class) red.getClass(), red, blue); + Validations.validateFieldTypeMatches(type, fieldName, red.getClass()); - if (type.isArray()) { - factoryCache.put(type, fieldName, values(red, blue, red)); + if (red.getClass().isArray()) { + fieldCache.put(fieldName, new Tuple<>(red, blue, red)); } else { try { T redCopy = ObjectAccessor.of(red).copy(objenesis); - factoryCache.put(type, fieldName, values(red, blue, redCopy)); + fieldCache.put(fieldName, new Tuple<>(red, blue, redCopy)); } catch (RuntimeException ignored) { /* specifically, on Java 9+: InacessibleObjectException */ - factoryCache.put(type, fieldName, values(red, blue, red)); - } - } - } - - private static Field findField(Class type, String fieldName) { - for (Class c : SuperclassIterable.ofIncludeSelf(type)) { - try { - return c.getDeclaredField(fieldName); - } catch (NoSuchFieldException ignored) { - // Do nothing + fieldCache.put(fieldName, new Tuple<>(red, blue, red)); } } - throw new IllegalStateException( - "Precondition: class " + - type.getSimpleName() + - " does not contain field " + - fieldName + - "." - ); } public static void addGenericPrefabValues( @@ -107,7 +87,7 @@ private static void addGenericPrefabValueFactory( PrefabValueFactory factory, int arity ) { - Validations.validateGenericPrefabValues(otherType, arity); + Validations.validateGenericPrefabValues(otherType, factory, arity); factoryCache.put(otherType, factory); } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java index 4d7666227..0adb4f04d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java @@ -12,6 +12,7 @@ import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; public final class Validations { @@ -88,24 +89,40 @@ public static void validateRedAndBluePrefabValues(Class type, T red, T bl ); } - public static void validateFieldTypeMatches(Field field, Class realFieldType) { - boolean typeCompatible = field.getType().isAssignableFrom(realFieldType); - boolean wrappingCompatible = realFieldType.equals( - PrimitiveMappers.PRIMITIVE_OBJECT_MAPPER.get(field.getType()) - ); - validate( - !typeCompatible && !wrappingCompatible, - "Prefab values for field " + - field.getName() + - " should be of type " + - field.getType().getSimpleName() + - " but are " + - realFieldType.getSimpleName() + - "." - ); + public static void validateFieldTypeMatches( + Class container, + String fieldName, + Class fieldType + ) { + try { + Field f = container.getDeclaredField(fieldName); + boolean sameFields = f.getType().equals(fieldType); + boolean compatibleFields = fieldType.equals( + PrimitiveMappers.PRIMITIVE_OBJECT_MAPPER.get(f.getType()) + ); + validate( + !sameFields && !compatibleFields, + "Prefab values for field " + + fieldName + + " should be of type " + + f.getType().getSimpleName() + + " but are " + + fieldType.getSimpleName() + + "." + ); + } catch (NoSuchFieldException e) { + validate( + false, + "Class " + container.getSimpleName() + " has no field named " + fieldName + "." + ); + } } - public static void validateGenericPrefabValues(Class type, int arity) { + public static void validateGenericPrefabValues( + Class type, + PrefabValueFactory factory, + int arity + ) { validateNotNull(type, "type is null."); int n = type.getTypeParameters().length; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 43bddc2f6..822567528 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -15,11 +15,6 @@ public class GenericTypesTest { - @Test - public void succeed_whenClassHasGenericFieldThatsSpecifiedToABuiltinGeneric() { - EqualsVerifier.forClass(GenericContainerWithBuiltin.class).verify(); - } - @Test public void succeed_whenEqualsLooksAtJava8TypesGenericContent() { EqualsVerifier.forClass(JavaGenericTypeContainer.class).verify(); @@ -90,11 +85,6 @@ public void succeed_whenToStringLooksAtNonCollectionGenericContent() { EqualsVerifier.forClass(SparseArrayToStringContainer.class).verify(); } - @Test - public void succeed_whenEqualsLooksAtGenericContent_givenTwoGenericFields() { - EqualsVerifier.forClass(TwoGenericsContainerWithIntrospection.class).verify(); - } - @Test public void succeed_whenClassHasTypeVariableThatExtendsSomething() { EqualsVerifier.forClass(TypeVariableExtendsContainer.class).verify(); @@ -131,29 +121,6 @@ public void succeed_whenClassHasASelfReferenceGenericParameter_givenPrefabValues .verify(); } - static final class GenericContainerWithBuiltin { - - private final Generic> b; - - public GenericContainerWithBuiltin(Generic> b) { - this.b = b; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof GenericContainerWithBuiltin)) { - return false; - } - GenericContainerWithBuiltin other = (GenericContainerWithBuiltin) obj; - return Objects.equals(b, other.b); - } - - @Override - public int hashCode() { - return Objects.hash(b); - } - } - static final class JavaGenericTypeContainer { private final Optional optional; @@ -205,30 +172,6 @@ public String toString() { } } - static final class Generic { - - private final T t; - - public Generic(T t) { - this.t = t; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Generic)) { - return false; - } - @SuppressWarnings("unchecked") - Generic other = (Generic) obj; - return Objects.equals(t, other.t); - } - - @Override - public int hashCode() { - return Objects.hash(t); - } - } - static final class ListContainer { private final List list; @@ -750,38 +693,6 @@ public String toString() { } } - public static final class TwoGenericsContainerWithIntrospection { - - private final List stringList = new ArrayList<>(); - private final List intList = new ArrayList<>(); - - @SuppressWarnings("unused") - @Override - public boolean equals(Object obj) { - if (stringList != null && stringList.size() > 0) { - String key = stringList.get(0); // force a cast - } - if (intList != null && intList.size() > 0) { - Integer key = intList.get(0); // force a cast - } - - if (!(obj instanceof TwoGenericsContainerWithIntrospection)) { - return false; - } - TwoGenericsContainerWithIntrospection other = - (TwoGenericsContainerWithIntrospection) obj; - return ( - Objects.equals(stringList, other.stringList) && - Objects.equals(intList, other.intList) - ); - } - - @Override - public int hashCode() { - return Objects.hash(stringList, intList); - } - } - @SuppressWarnings("unused") static final class TypeVariableExtendsContainer> { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java index 8600efe44..94ce5f16d 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java @@ -156,27 +156,6 @@ public void individuallySuppressedWarningsAreNotAddedGlobally() { public void individuallyAddedPrefabValuesAreNotAddedGlobally() { ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); - // should succeed - ev - .forClasses(RecursiveTypeContainer.class, A.class) - .withPrefabValues( - RecursiveType.class, - new RecursiveType(null), - new RecursiveType(new RecursiveType(null)) - ) - .verify(); - - // PrefabValues are not added to configuration, so should fail - ExpectedException - .when(() -> ev.forClasses(RecursiveTypeContainer.class, A.class).verify()) - .assertFailure() - .assertMessageContains("Recursive datastructure"); - } - - @Test - public void individuallyAddedGenericPrefabValuesAreNotAddedGlobally() { - ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); - // should succeed ev .forClasses(SingleGenericContainerContainer.class, A.class) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java index 7ace3f1ae..16cd8f8a9 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java @@ -117,27 +117,6 @@ public void individuallySuppressedWarningsAreNotAddedGlobally() { public void individuallyAddedPrefabValuesAreNotAddedGlobally() { ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); - // should succeed - ev - .forClass(RecursiveTypeContainer.class) - .withPrefabValues( - RecursiveType.class, - new RecursiveType(null), - new RecursiveType(new RecursiveType(null)) - ) - .verify(); - - // PrefabValues are not added to configuration, so should fail - ExpectedException - .when(() -> ev.forClass(RecursiveTypeContainer.class).verify()) - .assertFailure() - .assertMessageContains("Recursive datastructure"); - } - - @Test - public void individuallyAddedGenericPrefabValuesAreNotAddedGlobally() { - ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); - // should succeed ev .forClass(SingleGenericContainerContainer.class) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java index 8724bd3c1..952b32f0f 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java @@ -4,7 +4,10 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import com.google.common.collect.ImmutableList; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; @@ -42,21 +45,11 @@ public void succeed_whenDatastructureIsRecursive_givenPrefabValues() { EqualsVerifier.forClass(Node.class).withPrefabValues(Node.class, red, blue).verify(); } - @Test - public void succeed_whenDatastructureIsRecursive_givenPrefabValuesForField() { - EqualsVerifier.forClass(Node.class).withPrefabValuesForField("node", red, blue).verify(); - } - @Test public void succeed_whenDatastructureIsRecursive_givenPrefabValuesOfSuperclass() { EqualsVerifier.forClass(SubNode.class).withPrefabValues(Node.class, red, blue).verify(); } - @Test - public void succeed_whenDatastructureIsRecursive_givenPrefabValuesForFieldOfSuperclass() { - EqualsVerifier.forClass(SubNode.class).withPrefabValuesForField("node", red, blue).verify(); - } - @Test public void fail_whenFieldIsARecursiveType() { ExpectedException @@ -73,14 +66,6 @@ public void succeed_whenFieldIsARecursiveType_givenPrefabValues() { .verify(); } - @Test - public void succeed_whenFieldIsARecursiveType_givenPrefabValuesForField() { - EqualsVerifier - .forClass(NodeContainer.class) - .withPrefabValuesForField("node", red, blue) - .verify(); - } - @Test public void succeed_whenFieldIsARecursiveType_givenPrefabValuesOfSuperclass() { EqualsVerifier @@ -89,14 +74,6 @@ public void succeed_whenFieldIsARecursiveType_givenPrefabValuesOfSuperclass() { .verify(); } - @Test - public void succeed_whenFieldIsARecursiveType_givenPrefabValuesForFieldOfSuperclass() { - EqualsVerifier - .forClass(SubNodeContainer.class) - .withPrefabValuesForField("node", red, blue) - .verify(); - } - @Test public void fail_whenDatastructureIsRecursiveInGenerics() { ExpectedException @@ -137,8 +114,9 @@ public void giveCorrectErrorMessage_whenFieldIsInstantiatedUsingReflectiveFactor .assertMessageContains( RECURSIVE_DATASTRUCTURE, ImmutableListTree.class.getSimpleName(), - new TypeTag(ImmutableList.class, new TypeTag(ImmutableListTree.class)).toString() - ); + new TypeTag(ImmutableList.class, new TypeTag(ImmutableListTree.class)).toString(), + new TypeTag(Collection.class, new TypeTag(ImmutableListTree.class)).toString() + ); // I'd prefer not to have this last one though. } @Test diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java index a3330ca3c..0d39f7c59 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java @@ -2,7 +2,7 @@ import java.time.LocalDate; import java.time.Month; -import java.util.*; +import java.util.Objects; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; @@ -157,41 +157,6 @@ public void dontThrow_whenAddingPrefabValuesFromAnotherModuleAndThereforeARedCop .verify(); } - @Test - public void succeed_whenPrefabForArrayIsOverridden() { - EqualsVerifier - .forClass(ThrowingArrayContainer.class) - .withPrefabValuesForField("field", new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }) - .verify(); - } - - @Test - public void succeed_whenClassContainsSomethingThatAllowsSubclassesAndASubclassIsGiven() { - EqualsVerifier - .forClass(ListContainer.class) - .withPrefabValuesForField( - "list", - Collections.singletonList("x"), - Collections.singletonList("y") - ) - .verify(); - } - - @Test - public void succeed_whenClassContainsAGenericInterfaceThatRefersToItself() { - DifficultGeneric one = new DifficultGeneric(new ArrayList<>()); - DifficultGeneric two = new DifficultGeneric(null); - - EqualsVerifier - .forClass(DifficultGeneric.class) - .withPrefabValuesForField( - "list", - Collections.singletonList(one), - Collections.singletonList(two) - ) - .verify(); - } - static final class SinglePrecondition { private final FinalPoint point; @@ -274,76 +239,4 @@ public int hashCode() { return Objects.hash(date); } } - - static final class ThrowingArrayContainer { - - private final int[] field; - - public ThrowingArrayContainer(int[] field) { - this.field = field; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ThrowingArrayContainer)) { - return false; - } - if (field != null && field.length == 1) { - throw new IllegalStateException("Don't use a built-in prefab value!"); - } - ThrowingArrayContainer other = (ThrowingArrayContainer) obj; - return Arrays.equals(field, other.field); - } - - @Override - public int hashCode() { - return Arrays.hashCode(field); - } - } - - static final class ListContainer { - - private final List list; - - public ListContainer(List list) { - this.list = list; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ListContainer)) { - return false; - } - ListContainer other = (ListContainer) obj; - return Objects.equals(list, other.list); - } - - @Override - public int hashCode() { - return Objects.hash(list); - } - } - - public final class DifficultGeneric { - - private final List list; - - public DifficultGeneric(List list) { - this.list = list; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof DifficultGeneric)) { - return false; - } - DifficultGeneric other = (DifficultGeneric) obj; - return Objects.equals(list, other.list); - } - - @Override - public int hashCode() { - return Objects.hash(list); - } - } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java index 8614a5eb5..b7461f4e9 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java @@ -5,9 +5,17 @@ import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchRule; -import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ClassAccessor; -import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.FieldModifier; -import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.ObjectAccessor; +import nl.jqno.equalsverifier.internal.reflection.FactoryCacheTest; +import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProviderCreatorTest; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProviderTest; +import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor; +import nl.jqno.equalsverifier.internal.reflection.vintage.FieldModifier; +import nl.jqno.equalsverifier.internal.reflection.vintage.ObjectAccessor; +import nl.jqno.equalsverifier.internal.util.Context; +import nl.jqno.equalsverifier.internal.util.PrefabValuesApi; +import nl.jqno.equalsverifier.testhelpers.FactoryCacheFactory; @AnalyzeClasses(packages = "nl.jqno.equalsverifier") public final class ArchitectureTest { @@ -15,15 +23,22 @@ public final class ArchitectureTest { @ArchTest public static final ArchRule ONLY_VINTAGE_INSTANTIATORS_CAN_USE_VINTAGE_REFLECTION = noClasses() .that() + .doNotBelongToAnyOf( + VintageValueProvider.class, + Context.class, + PrefabValuesApi.class, + JavaApiPrefabValues.class, + // 👇 Test classes + FactoryCacheFactory.class, + FactoryCacheTest.class, + VintageValueProviderTest.class, + VintageValueProviderCreatorTest.class + ) + .and() .resideOutsideOfPackage("nl.jqno.equalsverifier.internal.reflection.vintage..") .should() .accessClassesThat() - .resideInAPackage("nl.jqno.equalsverifier.internal.reflection.vintage.mutation..") - .orShould() - .accessClassesThat() - .resideInAPackage( - "nl.jqno.equalsverifier.internal.reflection.vintage.mutation.prefabvalues.." - ); + .resideInAPackage("nl.jqno.equalsverifier.internal.reflection.vintage.."); @ArchTest public static final ArchRule DONT_USE_VINTAGE_REFLECTION_DIRECTLY = noClasses() diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java deleted file mode 100644 index 5eec5c2d8..000000000 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package nl.jqno.equalsverifier.internal.exceptions; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import org.junit.jupiter.api.Test; - -public class NoValueExceptionTest { - - @Test - public void descriptionWithoutLabel() { - TypeTag tag = new TypeTag(String.class); - NoValueException e = new NoValueException(tag, null); - assertTrue(e.getDescription().contains("String")); - assertFalse(e.getDescription().contains("label")); - } - - @Test - public void descriptionWithLabel() { - TypeTag tag = new TypeTag(String.class); - NoValueException e = new NoValueException(tag, "lbl"); - assertTrue(e.getDescription().contains("String")); - assertTrue(e.getDescription().contains("label lbl")); - } -} diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java similarity index 53% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java index 614d06fdd..bbe20d280 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java @@ -1,16 +1,13 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection; import static org.junit.jupiter.api.Assertions.*; -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache.Key; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.SimpleFactory; import org.junit.jupiter.api.Test; public class FactoryCacheTest { - private static final String SOME_LABEL = "label"; private static final Class STRING_CLASS = String.class; private static final PrefabValueFactory STRING_FACTORY = new SimpleFactory<>( "red", @@ -30,14 +27,6 @@ public class FactoryCacheTest { public void putAndGetTuple() { cache.put(STRING_CLASS, STRING_FACTORY); assertEquals(STRING_FACTORY, cache.get(STRING_CLASS)); - assertNull(cache.get(STRING_CLASS, SOME_LABEL)); - } - - @Test - public void putAndGetTupleWithLabel() { - cache.put(STRING_CLASS, SOME_LABEL, STRING_FACTORY); - assertEquals(STRING_FACTORY, cache.get(STRING_CLASS, SOME_LABEL)); - assertNull(cache.get(STRING_CLASS)); } @Test @@ -49,64 +38,23 @@ public void putTwiceAndGetBoth() { assertEquals(STRING_FACTORY, cache.get(STRING_CLASS)); } - @Test - public void putTwiceAndGetBothWithLabel() { - cache.put(STRING_CLASS, SOME_LABEL, STRING_FACTORY); - cache.put(INT_CLASS, SOME_LABEL, INT_FACTORY); - - assertEquals(INT_FACTORY, cache.get(INT_CLASS, SOME_LABEL)); - assertEquals(STRING_FACTORY, cache.get(STRING_CLASS, SOME_LABEL)); - } - @Test public void putNullAndGetNothingBack() { cache.put((Class) null, STRING_FACTORY); assertNull(cache.get(null)); } - @Test - public void putNullAndGetNothingBackWithLabel() { - cache.put((Class) null, SOME_LABEL, STRING_FACTORY); - assertNull(cache.get(null, SOME_LABEL)); - } - @Test public void contains() { cache.put(STRING_CLASS, STRING_FACTORY); assertTrue(cache.contains(STRING_CLASS)); } - @Test - public void containsWithLabel() { - cache.put(STRING_CLASS, SOME_LABEL, STRING_FACTORY); - assertTrue(cache.contains(STRING_CLASS, SOME_LABEL)); - assertFalse(cache.contains(STRING_CLASS)); - } - @Test public void doesntContain() { assertFalse(cache.contains(STRING_CLASS)); } - @Test - public void doesntContainWithLabel() { - cache.put(STRING_CLASS, STRING_FACTORY); - assertFalse(cache.contains(STRING_CLASS, SOME_LABEL)); - } - - @Test - public void copy() { - cache.put(STRING_CLASS, STRING_FACTORY); - - FactoryCache copy = cache.copy(); - copy.put(INT_CLASS, INT_FACTORY); - - assertTrue(copy.contains(STRING_CLASS)); - - assertFalse(copy == cache); - assertFalse(cache.contains(INT_CLASS)); - } - @Test public void merge() { FactoryCache a = new FactoryCache(); @@ -124,9 +72,4 @@ public void merge() { assertFalse(a.contains(INT_CLASS)); assertFalse(b.contains(STRING_CLASS)); } - - @Test - public void key() { - EqualsVerifier.forClass(Key.class).verify(); - } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FieldCacheTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FieldCacheTest.java new file mode 100644 index 000000000..5d09df19a --- /dev/null +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FieldCacheTest.java @@ -0,0 +1,61 @@ +package nl.jqno.equalsverifier.internal.reflection; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.junit.jupiter.api.Test; + +public class FieldCacheTest { + + private String stringField = "string"; + private final Tuple stringValues = new Tuple<>("red", "blue", "red"); + + private String intField = "int"; + private final Tuple intValues = new Tuple<>(1, 2, 1); + + private FieldCache cache = new FieldCache(); + + @Test + public void putAndGetTuple() { + cache.put(stringField, stringValues); + assertEquals(stringValues, cache.get(stringField)); + } + + @Test + public void putTwiceAndGetBoth() { + cache.put(stringField, stringValues); + cache.put(intField, intValues); + + assertEquals(intValues, cache.get(intField)); + assertEquals(stringValues, cache.get(stringField)); + } + + @Test + public void putNullAndGetNothingBack() { + cache.put(null, stringValues); + assertNull(cache.get(null)); + } + + @Test + public void contains() { + cache.put(stringField, stringValues); + assertTrue(cache.contains(stringField)); + } + + @Test + public void doesntContain() { + assertFalse(cache.contains(stringField)); + } + + @Test + public void getFieldNames() { + assertEquals(Collections.emptySet(), cache.getFieldNames()); + + cache.put(stringField, stringValues); + Set expected = new HashSet<>(); + expected.add(stringField); + assertEquals(expected, cache.getFieldNames()); + } +} diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java index 8a59ccd51..ec04bba0b 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java @@ -36,16 +36,4 @@ public void redAndRedCopyInvariant() { assertEquals(tuple.getRed(), tuple.getRedCopy()); assertNotSame(tuple.getRed(), tuple.getRedCopy()); } - - @Test - public void map() { - assertEquals(Tuple.of("redx", "bluex", "redx"), tuple.map(s -> s + "x")); - } - - @Test - public void combine() { - Tuple ints = Tuple.of(2, 3, 2); - Tuple actual = Tuple.combine(tuple, ints, (s, n) -> s + n); - assertEquals(Tuple.of("red2", "blue3", "red2"), actual); - } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java deleted file mode 100644 index db4c5d5c9..000000000 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Optional; -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider.Key; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import org.junit.jupiter.api.Test; - -public class CachedValueProviderTest { - - private static final TypeTag INT = new TypeTag(int.class); - - private CachedValueProvider sut = new CachedValueProvider(); - - @Test - public void aRegisteredValueCanBeFound() { - sut.put(INT, null, Tuple.of(3, 2, 3)); - assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.unlabeled()).get()); - } - - @Test - public void aValueRegisteredWithALabelCanBeFoundUnderThatLabel() { - sut.put(INT, "label", Tuple.of(3, 2, 3)); - assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.labeled("label")).get()); - } - - @Test - public void aValueRegisteredWithALabelCanNotBeFoundWithoutThatLabel() { - sut.put(INT, "label", Tuple.of(3, 2, 3)); - assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); - } - - @Test - public void aQueryWithLabelFallsBackToRegisteredValueWithoutLabel() { - sut.put(INT, null, Tuple.of(3, 2, 3)); - assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.labeled("label")).get()); - } - - @Test - public void aQueryWithLabelPrefersRegisteredValueWithThatLabel() { - sut.put(INT, null, Tuple.of(3, 2, 3)); - sut.put(INT, "label", Tuple.of(4, 3, 4)); - assertEquals(Tuple.of(4, 3, 4), sut.provide(INT, Attributes.labeled("label")).get()); - } - - @Test - public void anUnregisteredValueCanNotBeFound() { - assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); - } - - @Test - public void key() { - EqualsVerifier - .forClass(Key.class) - .withPrefabValues(TypeTag.class, new TypeTag(String.class), new TypeTag(Integer.class)) - .verify(); - } -} diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java deleted file mode 100644 index 9f092f438..000000000 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ChainedValueProviderTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Optional; -import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException; -import nl.jqno.equalsverifier.internal.exceptions.NoValueException; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; -import org.junit.jupiter.api.Test; - -public class ChainedValueProviderTest { - - private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); - private static final TypeTag INT = new TypeTag(int.class); - - private final SingleTypeValueProvider intProvider = new SingleTypeValueProvider<>( - int.class, - 1, - 2, - 1 - ); - private final SingleTypeValueProvider stringProvider = new SingleTypeValueProvider<>( - String.class, - "a", - "b", - "a" - ); - - private final CachedValueProvider cache = new CachedValueProvider(); - private final ChainedValueProvider sut = new ChainedValueProvider(cache); - - @Test - public void returnsValueIfMatch() { - sut.register(intProvider); - assertEquals(1, sut.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); - } - - @Test - public void returnsEmptyIfNoMatch() { - sut.register(stringProvider); - assertEquals(Optional.empty(), sut.provide(INT, EMPTY_ATTRIBUTES)); - } - - @Test - public void throwsExceptionIfNoMatch() { - sut.register(stringProvider); - ExpectedException - .when(() -> sut.provideOrThrow(INT, EMPTY_ATTRIBUTES)) - .assertThrows(NoValueException.class) - .assertDescriptionContains("Could not find a value for int"); - } - - @Test - public void skipsNonMatchingValue() { - sut.register(stringProvider, intProvider); - assertEquals(1, sut.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); - assertEquals(1, stringProvider.called); - assertEquals(1, intProvider.called); - } - - @Test - public void returnsValueFromFirstMatch() { - SingleTypeValueProvider anotherIntProvider = new SingleTypeValueProvider( - int.class, - 1, - 2, - 1 - ); - sut.register(intProvider, anotherIntProvider); - assertEquals(1, sut.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); - assertEquals(1, intProvider.called); - assertEquals(0, anotherIntProvider.called); - } - - @Test - public void updatesTheCache() { - sut.register(intProvider); - sut.provideOrThrow(INT, EMPTY_ATTRIBUTES); - - assertEquals(1, cache.provideOrThrow(INT, EMPTY_ATTRIBUTES).getRed()); - } - - @Test - public void makesDefensiveCopy() { - ValueProvider[] providers = { stringProvider }; - sut.register(providers); - providers[0] = intProvider; - assertEquals(Optional.empty(), sut.provide(INT, EMPTY_ATTRIBUTES)); - } - - @Test - public void locksAfterFirstAssignment() { - sut.register(intProvider); - ExpectedException - .when(() -> sut.register(stringProvider)) - .assertThrows(EqualsVerifierInternalBugException.class) - .assertMessageContains("Provider is locked"); - } - - static class SingleTypeValueProvider implements ValueProvider { - - private final Class type; - private final Tuple values; - private int called = 0; - - public SingleTypeValueProvider(Class type, X red, X blue, X redCopy) { - this.type = type; - this.values = Tuple.of(red, blue, redCopy); - } - - @Override - @SuppressWarnings("unchecked") - public Optional> provide(TypeTag tag, Attributes attributes) { - called++; - if (tag.getType().equals(type)) { - return Optional.of((Tuple) values); - } - return Optional.empty(); - } - } -} diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java index e99595234..d9e9ba8cd 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java @@ -5,11 +5,9 @@ import java.lang.reflect.Field; import java.util.Objects; -import java.util.Optional; -import nl.jqno.equalsverifier.internal.exceptions.NoValueException; +import nl.jqno.equalsverifier.internal.reflection.FieldCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.ConfigurationHelper; import org.junit.jupiter.api.BeforeEach; @@ -28,8 +26,14 @@ public class SubjectCreatorTest { SomeClass.class ); private ValueProvider valueProvider = new SubjectCreatorTestValueProvider(); + private FieldCache fieldCache = new FieldCache(); private Objenesis objenesis = new ObjenesisStd(); - private SubjectCreator sut = new SubjectCreator<>(config, valueProvider, objenesis); + private SubjectCreator sut = new SubjectCreator<>( + config, + valueProvider, + fieldCache, + objenesis + ); private Field fieldX; private Field fieldI; @@ -45,6 +49,9 @@ public void setup() throws NoSuchFieldException { fieldS = SomeClass.class.getDeclaredField("s"); } + @Test + public void sanity() {} + @Test public void plain() { expected = new SomeClass(I_RED, I_RED, S_RED); @@ -187,36 +194,16 @@ public void copyIntoSubclass() { assertEquals(SomeSub.class, actual.getClass()); } - @Test - public void noValueFound() { - sut = new SubjectCreator<>(config, new NoValueProvider(), objenesis); - - ExpectedException - .when(() -> sut.plain()) - .assertThrows(NoValueException.class) - .assertDescriptionContains("int"); - - assertEquals(expected, actual); - } - static class SubjectCreatorTestValueProvider implements ValueProvider { - public Optional> provide(TypeTag tag, Attributes attributes) { + public Tuple provide(TypeTag tag) { if (int.class.equals(tag.getType())) { - return Optional.of(Tuple.of(I_RED, I_BLUE, I_RED)); + return Tuple.of(I_RED, I_BLUE, I_RED); } if (String.class.equals(tag.getType())) { - return Optional.of(Tuple.of(S_RED, S_BLUE, new String(S_RED))); + return Tuple.of(S_RED, S_BLUE, new String(S_RED)); } - return Optional.empty(); - } - } - - static class NoValueProvider implements ValueProvider { - - @Override - public Optional> provide(TypeTag tag, Attributes attributes) { - return Optional.empty(); + throw new IllegalStateException(); } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java similarity index 84% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderCreatorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java index 2a6808a9a..45bba76bc 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java @@ -1,14 +1,13 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.instantiation; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.*; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.mutation.FactoryCacheFactory; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import nl.jqno.equalsverifier.testhelpers.FactoryCacheFactory; import nl.jqno.equalsverifier.testhelpers.types.Point; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.*; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.EmptyEnum; @@ -31,17 +30,14 @@ public class VintageValueProviderCreatorTest { private static final TypeTag TWOSTEP_NODE_ARRAY_A_TAG = new TypeTag(TwoStepNodeArrayA.class); private Objenesis objenesis; - private CachedValueProvider cache; private FactoryCache factoryCache; private VintageValueProvider valueProvider; @BeforeEach public void setup() { objenesis = new ObjenesisStd(); - cache = new CachedValueProvider(); factoryCache = FactoryCacheFactory.withPrimitiveFactories(); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + valueProvider = new VintageValueProvider(factoryCache, objenesis); } @Test @@ -51,6 +47,15 @@ public void simple() { assertFalse(red.equals(blue)); } + @Test + public void createSecondTimeIsNoOp() { + Point red = valueProvider.giveRed(POINT_TAG); + Point blue = valueProvider.giveBlue(POINT_TAG); + + assertSame(red, valueProvider.giveRed(POINT_TAG)); + assertSame(blue, valueProvider.giveBlue(POINT_TAG)); + } + @Test public void createEnum() { assertNotNull(valueProvider.giveRed(ENUM_TAG)); @@ -72,8 +77,7 @@ public void createEmptyEnum() { @Test public void oneStepRecursiveType() { factoryCache.put(Node.class, values(new Node(), new Node(), new Node())); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + valueProvider = new VintageValueProvider(factoryCache, objenesis); valueProvider.giveRed(NODE_TAG); } @@ -90,8 +94,7 @@ public void oneStepRecursiveArrayType() { NodeArray.class, values(new NodeArray(), new NodeArray(), new NodeArray()) ); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + valueProvider = new VintageValueProvider(factoryCache, objenesis); valueProvider.giveRed(NODE_ARRAY_TAG); } @@ -108,8 +111,7 @@ public void addTwoStepRecursiveType() { TwoStepNodeB.class, values(new TwoStepNodeB(), new TwoStepNodeB(), new TwoStepNodeB()) ); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + valueProvider = new VintageValueProvider(factoryCache, objenesis); valueProvider.giveRed(TWOSTEP_NODE_A_TAG); } @@ -126,8 +128,7 @@ public void twoStepRecursiveArrayType() { TwoStepNodeArrayB.class, values(new TwoStepNodeArrayB(), new TwoStepNodeArrayB(), new TwoStepNodeArrayB()) ); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + valueProvider = new VintageValueProvider(factoryCache, objenesis); valueProvider.giveRed(TWOSTEP_NODE_ARRAY_A_TAG); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java similarity index 75% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java index dab6fa67e..2fa15353e 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.reflection.instantiation; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultEquals; @@ -8,13 +8,12 @@ import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Point; import nl.jqno.equalsverifier.testhelpers.types.ThrowingInitializer; import org.junit.jupiter.api.BeforeEach; @@ -29,20 +28,27 @@ public class VintageValueProviderTest { private static final TypeTag INT_TAG = new TypeTag(int.class); private Objenesis objenesis = new ObjenesisStd(); - private CachedValueProvider cache = new CachedValueProvider(); private FactoryCache factoryCache = new FactoryCache(); private VintageValueProvider vp; @BeforeEach public void setUp() { - factoryCache.put(String.class, values("r", "b", new String("r"))); + factoryCache.put(String.class, new AppendingStringTestFactory()); factoryCache.put(int.class, values(42, 1337, 42)); - vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + vp = new VintageValueProvider(factoryCache, objenesis); + } + + @Test + public void sanityTestFactoryIncreasesStringLength() { + AppendingStringTestFactory f = new AppendingStringTestFactory(); + assertEquals("r", f.createValues(null, null, null).getRed()); + assertEquals("rr", f.createValues(null, null, null).getRed()); + assertEquals("rrr", f.createValues(null, null, null).getRed()); } @Test public void provide() { - Tuple actual = vp.provideOrThrow(POINT_TAG, Attributes.unlabeled()); + Tuple actual = vp.provide(POINT_TAG); assertEquals(Tuple.of(new Point(42, 42), new Point(1337, 1337), new Point(42, 42)), actual); } @@ -51,17 +57,36 @@ public void giveRedFromFactory() { assertEquals("r", vp.giveRed(STRING_TAG)); } + @Test + public void giveRedFromCache() { + vp.giveRed(STRING_TAG); + assertEquals("r", vp.giveRed(STRING_TAG)); + } + @Test public void giveBlueFromFactory() { assertEquals("b", vp.giveBlue(STRING_TAG)); } + @Test + public void giveBlueFromCache() { + vp.giveBlue(STRING_TAG); + assertEquals("b", vp.giveBlue(STRING_TAG)); + } + @Test public void giveRedCopyFromFactory() { assertEquals("r", vp.giveRedCopy(STRING_TAG)); assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG)); } + @Test + public void giveRedCopyFromCache() { + vp.giveRedCopy(STRING_TAG); + assertEquals("r", vp.giveRedCopy(STRING_TAG)); + assertNotSame(vp.giveRed(STRING_TAG), vp.giveRedCopy(STRING_TAG)); + } + @Test public void giveRedFromFallbackFactory() { Point actual = vp.giveRed(POINT_TAG); @@ -91,7 +116,7 @@ public void fallbackDoesNotAffectStaticFields() { @Test public void stringListIsSeparateFromIntegerList() { factoryCache.put(List.class, new ListTestFactory()); - vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + vp = new VintageValueProvider(factoryCache, objenesis); List strings = vp.giveRed(new TypeTag(List.class, STRING_TAG)); List ints = vp.giveRed(new TypeTag(List.class, INT_TAG)); @@ -108,7 +133,7 @@ public void addingNullDoesntBreakAnything() { @Test public void addingATypeTwiceOverrulesTheExistingOne() { factoryCache.put(int.class, values(-1, -2, -1)); - vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + vp = new VintageValueProvider(factoryCache, objenesis); assertEquals(-1, (int) vp.giveRed(INT_TAG)); assertEquals(-2, (int) vp.giveBlue(INT_TAG)); } @@ -117,7 +142,7 @@ public void addingATypeTwiceOverrulesTheExistingOne() { public void addLazyFactoryWorks() { TypeTag lazyTag = new TypeTag(Lazy.class); factoryCache.put(Lazy.class.getName(), values(Lazy.X, Lazy.Y, Lazy.X)); - vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + vp = new VintageValueProvider(factoryCache, objenesis); assertEquals(Lazy.X, vp.giveRed(lazyTag)); assertEquals(Lazy.Y, vp.giveBlue(lazyTag)); assertEquals(Lazy.X, vp.giveRedCopy(lazyTag)); @@ -133,7 +158,7 @@ public void addLazyFactoryIsLazy() { (t, p, ts) -> Tuple.of(ThrowingInitializer.X, ThrowingInitializer.Y, ThrowingInitializer.X) ); - vp = new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); + vp = new VintageValueProvider(factoryCache, objenesis); // Should throw, because `giveRed` does instantiate objects: try { @@ -167,6 +192,28 @@ public int hashCode() { } } + private static class AppendingStringTestFactory implements PrefabValueFactory { + + private String red; + private String blue; + + public AppendingStringTestFactory() { + red = ""; + blue = ""; + } + + @Override + public Tuple createValues( + TypeTag tag, + VintageValueProvider valueProvider, + LinkedHashSet typeStack + ) { + red += "r"; + blue += "b"; + return new Tuple<>(red, blue, new String(red)); + } + } + @SuppressWarnings("rawtypes") private static final class ListTestFactory implements PrefabValueFactory { @@ -175,7 +222,7 @@ private static final class ListTestFactory implements PrefabValueFactory { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { TypeTag subtag = tag.getGenericTypes().get(0); @@ -200,6 +247,7 @@ private static final class StaticContainer { int regularInt = 3; } + @SuppressWarnings("unused") public static class Lazy { public static final Lazy X = new Lazy(1); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java similarity index 69% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java index 17cb4b1e0..3fbfcb6cb 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/ClassAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java @@ -1,17 +1,15 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.testhelpers.types.PointContainer; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.TwoStepNodeA; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.TwoStepNodeB; @@ -23,23 +21,19 @@ public class ClassAccessorTest { - private Attributes empty; + private LinkedHashSet empty; private Objenesis objenesis; - private CachedValueProvider cache; private FactoryCache factoryCache; private VintageValueProvider valueProvider; private ClassAccessor pointContainerAccessor; @BeforeEach public void setup() { - empty = Attributes.unlabeled(); + empty = new LinkedHashSet<>(); objenesis = new ObjenesisStd(); - cache = new CachedValueProvider(); factoryCache = JavaApiPrefabValues.build(); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - pointContainerAccessor = - new ClassAccessor<>(PointContainer.class, valueProvider, objenesis); + valueProvider = new VintageValueProvider(factoryCache, objenesis); + pointContainerAccessor = ClassAccessor.of(PointContainer.class, valueProvider, objenesis); } @Test @@ -50,7 +44,7 @@ public void getRedObject() { @Test @SuppressWarnings("rawtypes") public void getRedObjectGeneric() { - ClassAccessor accessor = new ClassAccessor<>( + ClassAccessor accessor = ClassAccessor.of( GenericTypeVariableListContainer.class, valueProvider, objenesis @@ -62,6 +56,16 @@ public void getRedObjectGeneric() { assertEquals(String.class, foo.tList.get(0).getClass()); } + @Test + public void getRedAccessor() { + PointContainer foo = pointContainerAccessor.getRedObject(TypeTag.NULL, empty); + ObjectAccessor objectAccessor = pointContainerAccessor.getRedAccessor( + TypeTag.NULL, + empty + ); + assertEquals(foo, objectAccessor.get()); + } + @Test public void getBlueObject() { assertObjectHasNoNullFields(pointContainerAccessor.getBlueObject(TypeTag.NULL, empty)); @@ -70,7 +74,7 @@ public void getBlueObject() { @Test @SuppressWarnings("rawtypes") public void getBlueObjectGeneric() { - ClassAccessor accessor = new ClassAccessor<>( + ClassAccessor accessor = ClassAccessor.of( GenericTypeVariableListContainer.class, valueProvider, objenesis @@ -82,6 +86,16 @@ public void getBlueObjectGeneric() { assertEquals(String.class, foo.tList.get(0).getClass()); } + @Test + public void getBlueAccessor() { + PointContainer foo = pointContainerAccessor.getBlueObject(TypeTag.NULL, empty); + ObjectAccessor objectAccessor = pointContainerAccessor.getBlueAccessor( + TypeTag.NULL, + empty + ); + assertEquals(foo, objectAccessor.get()); + } + @Test public void redAndBlueNotEqual() { PointContainer red = pointContainerAccessor.getRedObject(TypeTag.NULL, empty); @@ -91,13 +105,15 @@ public void redAndBlueNotEqual() { @Test public void instantiateAllTypes() { - new ClassAccessor<>(AllTypesContainer.class, valueProvider, objenesis) + ClassAccessor + .of(AllTypesContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void instantiateArrayTypes() { - new ClassAccessor<>(AllArrayTypesContainer.class, valueProvider, objenesis) + ClassAccessor + .of(AllArrayTypesContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @@ -107,27 +123,29 @@ public void instantiateRecursiveTypeUsingPrefabValue() { TwoStepNodeB.class, values(new TwoStepNodeB(), new TwoStepNodeB(), new TwoStepNodeB()) ); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - new ClassAccessor<>(TwoStepNodeA.class, valueProvider, objenesis) + valueProvider = new VintageValueProvider(factoryCache, objenesis); + ClassAccessor + .of(TwoStepNodeA.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void instantiateInterfaceField() { - new ClassAccessor<>(InterfaceContainer.class, valueProvider, objenesis) + ClassAccessor + .of(InterfaceContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void instantiateAbstractClassField() { - new ClassAccessor<>(AbstractClassContainer.class, valueProvider, objenesis) + ClassAccessor + .of(AbstractClassContainer.class, valueProvider, objenesis) .getRedObject(TypeTag.NULL, empty); } @Test public void anInvalidTypeShouldNotThrowAnExceptionUponCreation() { - new ClassAccessor<>(null, valueProvider, objenesis); + ClassAccessor.of(null, valueProvider, objenesis); } private void assertObjectHasNoNullFields(PointContainer foo) { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifierTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java similarity index 95% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifierTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java index 060709d09..e0b2562b2 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FieldModifierTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorCopyingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java similarity index 97% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorCopyingTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java index 71fa1f1aa..a224280df 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorCopyingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorScramblingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java similarity index 88% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorScramblingTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java index f6e6aca62..a6775ab59 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorScramblingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java @@ -1,20 +1,18 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.*; import java.text.AttributedString; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import nl.jqno.equalsverifier.internal.exceptions.ModuleException; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Point; import nl.jqno.equalsverifier.testhelpers.types.Point3D; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.StaticFinalContainer; @@ -27,7 +25,7 @@ public class InPlaceObjectAccessorScramblingTest { - private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled(); + private static final LinkedHashSet EMPTY_TYPE_STACK = new LinkedHashSet<>(); private Objenesis objenesis; private VintageValueProvider valueProviderTest; @@ -36,13 +34,7 @@ public void setup() { FactoryCache factoryCache = JavaApiPrefabValues.build(); factoryCache.put(Point.class, values(new Point(1, 2), new Point(2, 3), new Point(1, 2))); objenesis = new ObjenesisStd(); - valueProviderTest = - new VintageValueProvider( - TestValueProviders.empty(), - new CachedValueProvider(), - factoryCache, - objenesis - ); + valueProviderTest = new VintageValueProvider(factoryCache, objenesis); } @Test @@ -162,7 +154,7 @@ private T copy(T object) { } private ObjectAccessor doScramble(Object object) { - return create(object).scramble(valueProviderTest, TypeTag.NULL, EMPTY_ATTRIBUTES); + return create(object).scramble(valueProviderTest, TypeTag.NULL, EMPTY_TYPE_STACK); } static final class StringContainer { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java similarity index 92% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java index b44d77d52..85152215a 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/InPlaceObjectAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.internal.reflection.vintage; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java index b35ebc104..e0a2263fd 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java @@ -4,11 +4,11 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.objects; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,7 +26,7 @@ public void setUp() { public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, - Attributes attributes + LinkedHashSet typeStack ) { return Tuple.of("red", "blue", new String("red")); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java index 074f279ee..ff91709c4 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -5,17 +5,14 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; +import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.Node; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.NodeArray; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.TwoStepNodeA; @@ -31,18 +28,16 @@ public class FallbackFactoryTest { private FallbackFactory factory; private VintageValueProvider valueProvider; - private Attributes attributes; + private LinkedHashSet typeStack; @BeforeEach public void setUp() { Objenesis objenesis = new ObjenesisStd(); factory = new FallbackFactory<>(objenesis); - CachedValueProvider cache = new CachedValueProvider(); FactoryCache factoryCache = new FactoryCache(); factoryCache.put(int.class, values(42, 1337, 42)); - valueProvider = - new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); - attributes = Attributes.unlabeled(); + valueProvider = new VintageValueProvider(factoryCache, objenesis); + typeStack = new LinkedHashSet<>(); } @Test @@ -62,7 +57,7 @@ public void giveMultiElementEnum() { @Test public void giveArray() { - Tuple tuple = factory.createValues(new TypeTag(int[].class), valueProvider, attributes); + Tuple tuple = factory.createValues(new TypeTag(int[].class), valueProvider, typeStack); assertArrayEquals(new int[] { 42 }, (int[]) tuple.getRed()); assertArrayEquals(new int[] { 1337 }, (int[]) tuple.getBlue()); } @@ -79,22 +74,10 @@ public void giveClassWithFields() { assertEquals(-10, IntContainer.STATIC_FINAL_I); } - @Test - public void redCopyIsNotSameAsRed() { - Tuple tuple = factory.createValues( - new TypeTag(IntContainer.class), - valueProvider, - attributes - ); - - assertEquals(tuple.getRed(), tuple.getRedCopy()); - assertNotSame(tuple.getRed(), tuple.getRedCopy()); - } - @Test public void dontGiveRecursiveClass() { ExpectedException - .when(() -> factory.createValues(new TypeTag(Node.class), valueProvider, attributes)) + .when(() -> factory.createValues(new TypeTag(Node.class), valueProvider, typeStack)) .assertThrows(RecursionException.class); } @@ -102,7 +85,7 @@ public void dontGiveRecursiveClass() { public void dontGiveTwoStepRecursiveClass() { ExpectedException .when(() -> - factory.createValues(new TypeTag(TwoStepNodeA.class), valueProvider, attributes) + factory.createValues(new TypeTag(TwoStepNodeA.class), valueProvider, typeStack) ) .assertThrows(RecursionException.class) .assertDescriptionContains("TwoStepNodeA", "TwoStepNodeB"); @@ -111,17 +94,15 @@ public void dontGiveTwoStepRecursiveClass() { @Test public void dontGiveRecursiveArray() { ExpectedException - .when(() -> - factory.createValues(new TypeTag(NodeArray.class), valueProvider, attributes) + .when(() -> factory.createValues(new TypeTag(NodeArray.class), valueProvider, typeStack) ) .assertThrows(RecursionException.class); } private void assertCorrectTuple(Class type, T expectedRed, T expectedBlue) { - Tuple tuple = factory.createValues(new TypeTag(type), valueProvider, attributes); + Tuple tuple = factory.createValues(new TypeTag(type), valueProvider, typeStack); assertEquals(expectedRed, tuple.getRed()); assertEquals(expectedBlue, tuple.getBlue()); - assertEquals(expectedRed, tuple.getRedCopy()); } private static final class IntContainer { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java index 664462bcf..afd23e9d7 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java @@ -3,14 +3,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.Map; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.OneElementEnum; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,7 +39,7 @@ public class MapFactoryTest { private static final MapFactory MAP_FACTORY = new MapFactory<>(HashMap::new); - private final Attributes attributes = Attributes.unlabeled(); + private final LinkedHashSet typeStack = new LinkedHashSet<>(); private VintageValueProvider valueProvider; private String red; private String blue; @@ -51,13 +49,7 @@ public class MapFactoryTest { @BeforeEach public void setUp() { - valueProvider = - new VintageValueProvider( - TestValueProviders.empty(), - new CachedValueProvider(), - JavaApiPrefabValues.build(), - new ObjenesisStd() - ); + valueProvider = new VintageValueProvider(JavaApiPrefabValues.build(), new ObjenesisStd()); red = valueProvider.giveRed(STRING_TYPETAG); blue = valueProvider.giveBlue(STRING_TYPETAG); redObject = valueProvider.giveRed(OBJECT_TYPETAG); @@ -70,7 +62,7 @@ public void createMapsOfStringToString() { Tuple tuple = MAP_FACTORY.createValues( STRINGSTRINGMAP_TYPETAG, valueProvider, - attributes + typeStack ); assertEquals(mapOf(red, blue), tuple.getRed()); assertEquals(mapOf(blue, blue), tuple.getBlue()); @@ -78,14 +70,14 @@ public void createMapsOfStringToString() { @Test public void createMapsOfWildcard() { - Tuple tuple = MAP_FACTORY.createValues(WILDCARDMAP_TYPETAG, valueProvider, attributes); + Tuple tuple = MAP_FACTORY.createValues(WILDCARDMAP_TYPETAG, valueProvider, typeStack); assertEquals(mapOf(redObject, blueObject), tuple.getRed()); assertEquals(mapOf(blueObject, blueObject), tuple.getBlue()); } @Test public void createRawMaps() { - Tuple tuple = MAP_FACTORY.createValues(RAWMAP_TYPETAG, valueProvider, attributes); + Tuple tuple = MAP_FACTORY.createValues(RAWMAP_TYPETAG, valueProvider, typeStack); assertEquals(mapOf(redObject, blueObject), tuple.getRed()); assertEquals(mapOf(blueObject, blueObject), tuple.getBlue()); } @@ -95,7 +87,7 @@ public void createMapOfOneElementEnumKey() { Tuple tuple = MAP_FACTORY.createValues( ONEELEMENTENUMKEYMAP_TYPETAG, valueProvider, - attributes + typeStack ); assertEquals(mapOf(redEnum, blueObject), tuple.getRed()); assertEquals(new HashMap<>(), tuple.getBlue()); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java index 1065d71e2..ff5f32d6e 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java @@ -2,14 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.LinkedHashSet; import java.util.Optional; import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.testhelpers.types.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,7 +40,7 @@ public class SimpleGenericFactoryTest { ); private static final PrefabValueFactory PAIR_FACTORY = Factories.simple(Pair::new, null); - private final Attributes attributes = Attributes.unlabeled(); + private final LinkedHashSet typeStack = new LinkedHashSet<>(); private VintageValueProvider valueProvider; private String redString; private String blueString; @@ -53,13 +51,7 @@ public class SimpleGenericFactoryTest { @BeforeEach public void setUp() { - valueProvider = - new VintageValueProvider( - TestValueProviders.empty(), - new CachedValueProvider(), - JavaApiPrefabValues.build(), - new ObjenesisStd() - ); + valueProvider = new VintageValueProvider(JavaApiPrefabValues.build(), new ObjenesisStd()); redString = valueProvider.giveRed(STRING_TYPETAG); blueString = valueProvider.giveBlue(STRING_TYPETAG); redInt = valueProvider.giveRed(INTEGER_TYPETAG); @@ -73,7 +65,7 @@ public void createOptionalsOfMapOfString() { Tuple tuple = OPTIONAL_FACTORY.createValues( STRINGOPTIONAL_TYPETAG, valueProvider, - attributes + typeStack ); assertEquals(Optional.of(redString), tuple.getRed()); assertEquals(Optional.of(blueString), tuple.getBlue()); @@ -84,7 +76,7 @@ public void createOptionalsOfWildcard() { Tuple tuple = OPTIONAL_FACTORY.createValues( WILDCARDOPTIONAL_TYPETAG, valueProvider, - attributes + typeStack ); assertEquals(Optional.of(redObject), tuple.getRed()); assertEquals(Optional.of(blueObject), tuple.getBlue()); @@ -95,7 +87,7 @@ public void createRawOptionals() { Tuple tuple = OPTIONAL_FACTORY.createValues( RAWOPTIONAL_TYPETAG, valueProvider, - attributes + typeStack ); assertEquals(Optional.of(redObject), tuple.getRed()); assertEquals(Optional.of(blueObject), tuple.getBlue()); @@ -103,7 +95,7 @@ public void createRawOptionals() { @Test public void createSomethingWithMoreThanOneTypeParameter() { - Tuple tuple = PAIR_FACTORY.createValues(PAIR_TYPETAG, valueProvider, attributes); + Tuple tuple = PAIR_FACTORY.createValues(PAIR_TYPETAG, valueProvider, typeStack); assertEquals(new Pair<>(redString, redInt), tuple.getRed()); assertEquals(new Pair<>(blueString, blueInt), tuple.getBlue()); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java index f782fae61..06681caeb 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java @@ -8,12 +8,9 @@ import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; -import nl.jqno.equalsverifier.internal.reflection.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.JavaFxFactoryProvider.PropertyFactory; -import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; import nl.jqno.equalsverifier.testhelpers.types.Point; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,13 +23,7 @@ public class JavaFxFactoryProviderTest { @BeforeEach public void setUp() { - valueProvider = - new VintageValueProvider( - TestValueProviders.empty(), - new CachedValueProvider(), - JavaApiPrefabValues.build(), - new ObjenesisStd() - ); + valueProvider = new VintageValueProvider(JavaApiPrefabValues.build(), new ObjenesisStd()); } @Test @@ -49,11 +40,7 @@ public void createInstancesWithCorrectSingleGenericParameter() { GenericContainer.class.getName(), List.class ); - Tuple tuple = factory.createValues( - tag, - valueProvider, - Attributes.unlabeled() - ); + Tuple tuple = factory.createValues(tag, valueProvider, null); assertEquals(valueProvider.giveRed(listTag), tuple.getRed().t); assertEquals(valueProvider.giveBlue(listTag), tuple.getBlue().t); @@ -77,11 +64,7 @@ public void createInstancesWithCorrectMultipleGenericParameter() { GenericMultiContainer.class.getName(), Map.class ); - Tuple tuple = factory.createValues( - tag, - valueProvider, - Attributes.unlabeled() - ); + Tuple tuple = factory.createValues(tag, valueProvider, null); assertEquals(valueProvider.giveRed(mapTag), tuple.getRed().t); assertEquals(valueProvider.giveBlue(mapTag), tuple.getBlue().t); diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApiTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java similarity index 82% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApiTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java index b8c43352c..cae0f474d 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/PrefabValuesApiTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.util; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java index a4fd8efd6..e291c4a00 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java @@ -1,134 +1,13 @@ package nl.jqno.equalsverifier.internal.util; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import java.lang.reflect.Field; -import java.util.*; -import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import org.junit.jupiter.api.Test; -class ValidationsTest { +public class ValidationsTest { @Test public void coverTheConstructor() { coverThePrivateConstructor(Validations.class); } - - @Test - public void validateFieldTypeMatches_shouldFailOnWrongType() { - assertAll( - () -> { - ExpectedException - .when(() -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "listField"), - HashSet.class - ) - ) - .assertThrows(IllegalStateException.class) - .assertMessageContains("should be of type List", "but are HashSet"); - }, - () -> { - ExpectedException - .when(() -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "objectField"), - int.class - ) - ) - .assertThrows(IllegalStateException.class) - .assertMessageContains("should be of type Object", "but are int"); - }, - () -> { - ExpectedException - .when(() -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "charsField"), - Character.class - ) - ) - .assertThrows(IllegalStateException.class) - .assertMessageContains("should be of type CharSequence", "but are Character"); - } - ); - } - - @Test - public void validateFieldTypeMatches_shouldAllowSubTypes() { - assertAll( - () -> - assertDoesNotThrow( - () -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "listField"), - ArrayList.class - ), - "Should allow ArrayList as a List" - ), - () -> - assertDoesNotThrow( - () -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "objectField"), - Integer.class - ), - "Should allow Integer as an Object" - ), - () -> - assertDoesNotThrow( - () -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "charsField"), - String.class - ), - "Should allow String as a CharSequence" - ) - ); - } - - @Test - public void validateFieldTypeMatches_shouldFailOnSuperTypes() { - assertAll( - () -> { - ExpectedException - .when(() -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "listField"), - Collection.class - ) - ) - .assertThrows(IllegalStateException.class) - .assertMessageContains("should be of type List", "but are Collection"); - }, - () -> { - ExpectedException - .when(() -> - Validations.validateFieldTypeMatches( - getField(TestContainer.class, "charsField"), - Object.class - ) - ) - .assertThrows(IllegalStateException.class) - .assertMessageContains("should be of type CharSequence", "but are Object"); - } - ); - } - - private Field getField(Class type, String fieldName) { - try { - return type.getDeclaredField(fieldName); - } catch (NoSuchFieldException e) { - throw new AssertionError("Class " + type + " has no field " + fieldName); - } - } - - @SuppressWarnings("unused") - private static final class TestContainer { - - List listField; - Object objectField; - CharSequence charsField; - } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FactoryCacheFactory.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java similarity index 86% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FactoryCacheFactory.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java index 9a07e1245..9f9871c6e 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/mutation/FactoryCacheFactory.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java @@ -1,8 +1,8 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.mutation; +package nl.jqno.equalsverifier.testhelpers; import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; -import nl.jqno.equalsverifier.internal.reflection.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; public final class FactoryCacheFactory { diff --git a/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java b/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java index be86ac31b..2da2a26f3 100644 --- a/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java +++ b/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java @@ -23,7 +23,7 @@ public JarAsserter(JarReader reader) { public void assertPresenceOfCoreClasses() { assertPresenceOf( EV + "/EqualsVerifier.class", - EV + "/internal/reflection/vintage/mutation/ClassAccessor.class", + EV + "/internal/reflection/vintage/ClassAccessor.class", EV + "/internal/checkers/HierarchyChecker.class" ); } From 411284c30232dd2582e4a1bee963f9eb2d9a6fcf Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 4 Dec 2024 19:14:49 +0100 Subject: [PATCH 02/23] Let ValueProvider return an Optional --- .../checkers/AbstractDelegationChecker.java | 2 +- .../MapEntryHashCodeRequirementChecker.java | 2 +- .../fieldchecks/JpaLazyGetterFieldCheck.java | 10 ++---- .../fieldchecks/ReflexivityFieldCheck.java | 2 +- .../fieldchecks/StringFieldCheck.java | 3 +- .../internal/exceptions/NoValueException.java | 20 +++++++++++ .../instantiation/SubjectCreator.java | 3 +- .../instantiation/ValueProvider.java | 21 ++++++++++-- .../instantiation/VintageValueProvider.java | 4 +-- .../exceptions/NoValueExceptionTest.java | 16 +++++++++ .../instantiation/SubjectCreatorTest.java | 34 +++++++++++++++---- .../VintageValueProviderTest.java | 11 +++--- 12 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java create mode 100644 equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java index ca64fabb1..3b5820ab7 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java @@ -74,7 +74,7 @@ private void checkAbstractDelegationInFields() { private Tuple safelyGetTuple(TypeTag tag) { try { - return valueProvider.provide(tag); + return valueProvider.provideOrThrow(tag); } catch (Exception ignored) { // If it fails for some reason, any reason, just return null so we can skip the test. return null; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java index 3ae750f99..3caf7f991 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java @@ -23,7 +23,7 @@ public MapEntryHashCodeRequirementChecker(Context context) { public void check() { if (Map.Entry.class.isAssignableFrom(config.getType())) { Map.Entry e = valueProvider - .>provide(config.getTypeTag()) + .>provideOrThrow(config.getTypeTag()) .getRed(); int expectedHashCode = Objects.hashCode(e.getKey()) ^ Objects.hashCode(e.getValue()); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java index 9727744bf..2632bc342 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java @@ -9,11 +9,7 @@ import java.util.function.Function; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException; -import nl.jqno.equalsverifier.internal.reflection.ClassProbe; -import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.Instantiator; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; @@ -67,8 +63,8 @@ public void execute(FieldProbe fieldProbe) { classProbe.hasMethod(getterName) ); - Class sub = throwingGetterCreator(getterName); - Tuple tuple = valueProvider.provide(new TypeTag(sub)); + TypeTag sub = new TypeTag(throwingGetterCreator(getterName)); + Tuple tuple = valueProvider.provideOrThrow(sub); T red1 = tuple.getRed(); T red2 = tuple.getRedCopy(); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java index 3d775008a..c8705a78c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java @@ -82,7 +82,7 @@ private void checkValueReflexivity(FieldProbe probe) { TypeTag tag = TypeTag.of(field, typeTag); Tuple tuple = prefabbedFields.contains(fieldName) ? fieldCache.get(fieldName) - : valueProvider.provide(tag); + : valueProvider.provideOrThrow(tag); Object left = subjectCreator.withFieldSetTo(field, tuple.getRed()); Object right = subjectCreator.withFieldSetTo(field, tuple.getRedCopy()); diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java index e05e50ad5..9377394a0 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java @@ -40,7 +40,8 @@ public StringFieldCheck( ) public void execute(FieldProbe fieldProbe) { if (String.class.equals(fieldProbe.getType()) && !fieldProbe.isStatic()) { - String red = valueProvider.provide(new TypeTag(String.class)).getRed(); + TypeTag string = new TypeTag(String.class); + String red = valueProvider.provideOrThrow(string).getRed(); final T reference; final T copy; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java new file mode 100644 index 000000000..182a71572 --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java @@ -0,0 +1,20 @@ +package nl.jqno.equalsverifier.internal.exceptions; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; + +@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "EqualsVerifier doesn't serialize.") +public class NoValueException extends MessagingException { + + private final TypeTag tag; + + public NoValueException(TypeTag tag) { + super(); + this.tag = tag; + } + + @Override + public String getDescription() { + return "Could not find a value for " + tag + ". Please add prefab values for this type."; + } +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java index 86c3a7cb2..17fc59420 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java @@ -244,7 +244,8 @@ private Tuple valuesFor(Field f) { return fieldCache.get(fieldName); } try { - Tuple tuple = valueProvider.provide(TypeTag.of(f, typeTag)); + TypeTag fieldTag = TypeTag.of(f, typeTag); + Tuple tuple = valueProvider.provideOrThrow(fieldTag); fieldCache.put(fieldName, tuple); return tuple; } catch (ModuleException e) { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java index eef125f5c..268a43e24 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java @@ -1,5 +1,7 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; +import java.util.Optional; +import nl.jqno.equalsverifier.internal.exceptions.NoValueException; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; @@ -18,7 +20,22 @@ public interface ValueProvider { * * @param The returned tuple will have this generic type. * @param tag A description of the desired type, including generic parameters. - * @return A tuple of two different values of the given type. + * @return A tuple of two different values of the given type, or an empty Optional if none + * could be found. */ - Tuple provide(TypeTag tag); + Optional> provide(TypeTag tag); + + /** + * Returns a tuple of prefabricated values of the specified type, or, if none exists, throws a + * NoValueException. + * + * @param The returned tuple will have this generic type. + * @param tag A description of the desired type, including generic parameters. + * @return A tuple of two different values of the given type, or an empty Optional if none + * could be found. + * @throws NoValueException if no value could be found for the given tag. + */ + default Tuple provideOrThrow(TypeTag tag) { + return this.provide(tag).orElseThrow(() -> new NoValueException(tag)); + } } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java index 4af2fbd1b..c92154520 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java @@ -42,8 +42,8 @@ public VintageValueProvider(FactoryCache factoryCache, Objenesis objenesis) { /** {@inheritDoc} */ @Override - public Tuple provide(TypeTag tag) { - return Rethrow.rethrow(() -> giveTuple(tag)); + public Optional> provide(TypeTag tag) { + return Rethrow.rethrow(() -> Optional.of(giveTuple(tag))); } /** diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java new file mode 100644 index 000000000..58259cc49 --- /dev/null +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/NoValueExceptionTest.java @@ -0,0 +1,16 @@ +package nl.jqno.equalsverifier.internal.exceptions; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import org.junit.jupiter.api.Test; + +public class NoValueExceptionTest { + + @Test + public void description() { + TypeTag tag = new TypeTag(String.class); + NoValueException e = new NoValueException(tag); + assertTrue(e.getDescription().contains("String")); + } +} diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java index d9e9ba8cd..e62ebfd13 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java @@ -5,9 +5,12 @@ import java.lang.reflect.Field; import java.util.Objects; +import java.util.Optional; +import nl.jqno.equalsverifier.internal.exceptions.NoValueException; import nl.jqno.equalsverifier.internal.reflection.FieldCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.ConfigurationHelper; import org.junit.jupiter.api.BeforeEach; @@ -49,9 +52,6 @@ public void setup() throws NoSuchFieldException { fieldS = SomeClass.class.getDeclaredField("s"); } - @Test - public void sanity() {} - @Test public void plain() { expected = new SomeClass(I_RED, I_RED, S_RED); @@ -194,16 +194,36 @@ public void copyIntoSubclass() { assertEquals(SomeSub.class, actual.getClass()); } + @Test + public void noValueFound() { + sut = new SubjectCreator<>(config, new NoValueProvider(), fieldCache, objenesis); + + ExpectedException + .when(() -> sut.plain()) + .assertThrows(NoValueException.class) + .assertDescriptionContains("int"); + + assertEquals(expected, actual); + } + static class SubjectCreatorTestValueProvider implements ValueProvider { - public Tuple provide(TypeTag tag) { + public Optional> provide(TypeTag tag) { if (int.class.equals(tag.getType())) { - return Tuple.of(I_RED, I_BLUE, I_RED); + return Optional.of(Tuple.of(I_RED, I_BLUE, I_RED)); } if (String.class.equals(tag.getType())) { - return Tuple.of(S_RED, S_BLUE, new String(S_RED)); + return Optional.of(Tuple.of(S_RED, S_BLUE, new String(S_RED))); } - throw new IllegalStateException(); + return Optional.empty(); + } + } + + static class NoValueProvider implements ValueProvider { + + @Override + public Optional> provide(TypeTag tag) { + return Optional.empty(); } } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java index 2fa15353e..03cde5c19 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java @@ -7,9 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.fail; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; +import java.util.*; import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; @@ -48,8 +46,11 @@ public void sanityTestFactoryIncreasesStringLength() { @Test public void provide() { - Tuple actual = vp.provide(POINT_TAG); - assertEquals(Tuple.of(new Point(42, 42), new Point(1337, 1337), new Point(42, 42)), actual); + Optional> actual = vp.provide(POINT_TAG); + assertEquals( + Tuple.of(new Point(42, 42), new Point(1337, 1337), new Point(42, 42)), + actual.get() + ); } @Test From 829767c08cc56e9ca68930d4ff44eda50fcad0e7 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 4 Dec 2024 19:21:50 +0100 Subject: [PATCH 03/23] Fixes a PITest mutant --- .../WithPrefabValuesForFieldTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java index 0d39f7c59..dad621f2d 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java @@ -2,6 +2,7 @@ import java.time.LocalDate; import java.time.Month; +import java.util.Arrays; import java.util.Objects; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; @@ -157,6 +158,14 @@ public void dontThrow_whenAddingPrefabValuesFromAnotherModuleAndThereforeARedCop .verify(); } + @Test + public void succeed_whenPrefabForArrayIsOverridden() { + EqualsVerifier + .forClass(ThrowingArrayContainer.class) + .withPrefabValuesForField("field", new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }) + .verify(); + } + static final class SinglePrecondition { private final FinalPoint point; @@ -239,4 +248,30 @@ public int hashCode() { return Objects.hash(date); } } + + static final class ThrowingArrayContainer { + + private final int[] field; + + public ThrowingArrayContainer(int[] field) { + this.field = field; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ThrowingArrayContainer)) { + return false; + } + if (field != null && field.length == 1) { + throw new IllegalStateException("Don't use a built-in prefab value!"); + } + ThrowingArrayContainer other = (ThrowingArrayContainer) obj; + return Arrays.equals(field, other.field); + } + + @Override + public int hashCode() { + return Arrays.hashCode(field); + } + } } From cb0f83eb63cf401990c30a99239784079b55dc2a Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 5 Nov 2024 12:49:37 +0100 Subject: [PATCH 04/23] Allows subclasses to be passed into withPrefabValuesForField() --- .../internal/util/Validations.java | 6 +-- .../WithPrefabValuesForFieldTest.java | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java index 0adb4f04d..5bc2dcdf1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java @@ -96,12 +96,12 @@ public static void validateFieldTypeMatches( ) { try { Field f = container.getDeclaredField(fieldName); - boolean sameFields = f.getType().equals(fieldType); - boolean compatibleFields = fieldType.equals( + boolean typeCompatible = f.getType().isAssignableFrom(fieldType); + boolean wrappingCompatible = fieldType.equals( PrimitiveMappers.PRIMITIVE_OBJECT_MAPPER.get(f.getType()) ); validate( - !sameFields && !compatibleFields, + !typeCompatible && !wrappingCompatible, "Prefab values for field " + fieldName + " should be of type " + diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java index dad621f2d..1f8161e8b 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java @@ -2,8 +2,7 @@ import java.time.LocalDate; import java.time.Month; -import java.util.Arrays; -import java.util.Objects; +import java.util.*; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; @@ -166,6 +165,18 @@ public void succeed_whenPrefabForArrayIsOverridden() { .verify(); } + @Test + public void succeed_whenClassContainsSomethingThatAllowsSubclassesAndASubclassIsGiven() { + EqualsVerifier + .forClass(ListContainer.class) + .withPrefabValuesForField( + "list", + Collections.singletonList("x"), + Collections.singletonList("y") + ) + .verify(); + } + static final class SinglePrecondition { private final FinalPoint point; @@ -274,4 +285,27 @@ public int hashCode() { return Arrays.hashCode(field); } } + + static final class ListContainer { + + private final List list; + + public ListContainer(List list) { + this.list = list; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ListContainer)) { + return false; + } + ListContainer other = (ListContainer) obj; + return Objects.equals(list, other.list); + } + + @Override + public int hashCode() { + return Objects.hash(list); + } + } } From b9dcec83cebd538d9045b9fc004ae96541d9dac2 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 5 Nov 2024 20:37:38 +0100 Subject: [PATCH 05/23] Adds additional recursion tests for withPrefabValuesForField --- .../operational/RecursionTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java index 952b32f0f..62ee05800 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java @@ -45,11 +45,21 @@ public void succeed_whenDatastructureIsRecursive_givenPrefabValues() { EqualsVerifier.forClass(Node.class).withPrefabValues(Node.class, red, blue).verify(); } + @Test + public void succeed_whenDatastructureIsRecursive_givenPrefabValuesForField() { + EqualsVerifier.forClass(Node.class).withPrefabValuesForField("node", red, blue).verify(); + } + @Test public void succeed_whenDatastructureIsRecursive_givenPrefabValuesOfSuperclass() { EqualsVerifier.forClass(SubNode.class).withPrefabValues(Node.class, red, blue).verify(); } + @Test + public void succeed_whenDatastructureIsRecursive_givenPrefabValuesForFieldOfSuperclass() { + EqualsVerifier.forClass(SubNode.class).withPrefabValuesForField("node", red, blue).verify(); + } + @Test public void fail_whenFieldIsARecursiveType() { ExpectedException @@ -66,6 +76,14 @@ public void succeed_whenFieldIsARecursiveType_givenPrefabValues() { .verify(); } + @Test + public void succeed_whenFieldIsARecursiveType_givenPrefabValuesForField() { + EqualsVerifier + .forClass(NodeContainer.class) + .withPrefabValuesForField("node", red, blue) + .verify(); + } + @Test public void succeed_whenFieldIsARecursiveType_givenPrefabValuesOfSuperclass() { EqualsVerifier @@ -74,6 +92,14 @@ public void succeed_whenFieldIsARecursiveType_givenPrefabValuesOfSuperclass() { .verify(); } + @Test + public void succeed_whenFieldIsARecursiveType_givenPrefabValuesForFieldOfSuperclass() { + EqualsVerifier + .forClass(SubNodeContainer.class) + .withPrefabValuesForField("node", red, blue) + .verify(); + } + @Test public void fail_whenDatastructureIsRecursiveInGenerics() { ExpectedException From 02644f88bc70e93c3be0f4fdf77af6f210c6a554 Mon Sep 17 00:00:00 2001 From: Vankog Date: Tue, 5 Nov 2024 15:26:35 +0100 Subject: [PATCH 06/23] add tests for type validation See #1012 [Bug] withPrefabValuesForField() throws for fields declaring interfaces and super-types --- .../internal/util/ValidationsTest.java | 197 +++++++++++++++++- 1 file changed, 195 insertions(+), 2 deletions(-) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java index e291c4a00..53b31f23f 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java @@ -1,13 +1,206 @@ package nl.jqno.equalsverifier.internal.util; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; import org.junit.jupiter.api.Test; -public class ValidationsTest { +/** Tests for {@link Validations} */ +class ValidationsTest { @Test - public void coverTheConstructor() { + void coverTheConstructor() { coverThePrivateConstructor(Validations.class); } + + /** + * {@link Validations#validateFieldTypeMatches(Class, String, Class)} should + * throw if the field type does not match the given type. + */ + @Test + void validateFieldTypeMatches_ShouldFailOnWrongType() { + assertAll( + () -> { + Exception exc = assertThrows( + IllegalStateException.class, + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "listField", + HashSet.class + ), + "Should not allow HashSet as a List" + ); + assertThat( + exc.getMessage(), + allOf( + containsString("should be of type List"), + containsString("but are HashSet") + ) + ); + }, + () -> { + Exception exc = assertThrows( + IllegalStateException.class, + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "objectField", + int.class + ), + "Should not allow primitives as an Object, because primitives are not a subtype of Object" + ); + assertThat( + exc.getMessage(), + allOf(containsString("should be of type Object"), containsString("but are int")) + ); + }, + () -> { + Exception exc = assertThrows( + IllegalStateException.class, + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "charsField", + Character.class + ), + "Should not allow Character as a CharSequence" + ); + assertThat( + exc.getMessage(), + allOf( + containsString("should be of type CharSequence"), + containsString("but are Character") + ) + ); + } + ); + } + + /** + * {@link Validations#validateFieldTypeMatches(Class, String, Class)} should not + * throw if the field type is a super-type or interface of the given type. + */ + @Test + void validateFieldTypeMatches_ShouldAllowSubTypes() { + assertAll( + () -> + assertDoesNotThrow( + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "listField", + ArrayList.class + ), + "Should allow ArrayList as a List" + ), + () -> + assertDoesNotThrow( + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "objectField", + Integer.class + ), + "Should allow Integer as an Object" + ), + () -> + assertDoesNotThrow( + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "charsField", + String.class + ), + "Should allow String as a CharSequence" + ) + ); + } + + /** + * {@link Validations#validateFieldTypeMatches(Class, String, Class)} should not + * throw if the field type is a sub-type of the given type or interface. + */ + @Test + void validateFieldTypeMatches_ShouldFailOnSuperTypes() { + assertAll( + () -> { + Exception exc = assertThrows( + IllegalStateException.class, + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "listField", + Collection.class + ), + "Should not allow Collection as a List" + ); + assertThat( + exc.getMessage(), + allOf( + containsString("should be of type List"), + containsString("but are Collection") + ) + ); + }, + () -> { + Exception exc = assertThrows( + IllegalStateException.class, + () -> + Validations.validateFieldTypeMatches( + TestContainer.class, + "charsField", + Object.class + ), + "Should not allow Object as a CharSequence" + ); + assertThat( + exc.getMessage(), + allOf( + containsString("should be of type CharSequence"), + containsString("but are Object") + ) + ); + } + ); + } + + /** Test class for type checking. */ + private static class TestContainer { + + List listField; + Object objectField; + CharSequence charsField; + + @Override + public int hashCode() { + return Objects.hash(charsField, listField, objectField); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof TestContainer)) { + return false; + } + TestContainer other = (TestContainer) obj; + return ( + Objects.equals(charsField, other.charsField) && + Objects.equals(listField, other.listField) && + Objects.equals(objectField, other.objectField) + ); + } + } } From 87e41118d5866a722e4969d2f6e9556600960d41 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 6 Nov 2024 13:10:27 +0100 Subject: [PATCH 07/23] Tweaks ValidationTest to use ExpectedException --- .../internal/util/ValidationsTest.java | 136 +++++------------- 1 file changed, 33 insertions(+), 103 deletions(-) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java index 53b31f23f..3906f1183 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ValidationsTest.java @@ -1,98 +1,67 @@ package nl.jqno.equalsverifier.internal.util; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Objects; +import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import org.junit.jupiter.api.Test; -/** Tests for {@link Validations} */ class ValidationsTest { @Test - void coverTheConstructor() { + public void coverTheConstructor() { coverThePrivateConstructor(Validations.class); } - /** - * {@link Validations#validateFieldTypeMatches(Class, String, Class)} should - * throw if the field type does not match the given type. - */ @Test - void validateFieldTypeMatches_ShouldFailOnWrongType() { + public void validateFieldTypeMatches_shouldFailOnWrongType() { assertAll( () -> { - Exception exc = assertThrows( - IllegalStateException.class, - () -> + ExpectedException + .when(() -> Validations.validateFieldTypeMatches( TestContainer.class, "listField", HashSet.class - ), - "Should not allow HashSet as a List" - ); - assertThat( - exc.getMessage(), - allOf( - containsString("should be of type List"), - containsString("but are HashSet") + ) ) - ); + .assertThrows(IllegalStateException.class) + .assertMessageContains("should be of type List", "but are HashSet"); }, () -> { - Exception exc = assertThrows( - IllegalStateException.class, - () -> + ExpectedException + .when(() -> Validations.validateFieldTypeMatches( TestContainer.class, "objectField", int.class - ), - "Should not allow primitives as an Object, because primitives are not a subtype of Object" - ); - assertThat( - exc.getMessage(), - allOf(containsString("should be of type Object"), containsString("but are int")) - ); + ) + ) + .assertThrows(IllegalStateException.class) + .assertMessageContains("should be of type Object", "but are int"); }, () -> { - Exception exc = assertThrows( - IllegalStateException.class, - () -> + ExpectedException + .when(() -> Validations.validateFieldTypeMatches( TestContainer.class, "charsField", Character.class - ), - "Should not allow Character as a CharSequence" - ); - assertThat( - exc.getMessage(), - allOf( - containsString("should be of type CharSequence"), - containsString("but are Character") + ) ) - ); + .assertThrows(IllegalStateException.class) + .assertMessageContains("should be of type CharSequence", "but are Character"); } ); } - /** - * {@link Validations#validateFieldTypeMatches(Class, String, Class)} should not - * throw if the field type is a super-type or interface of the given type. - */ @Test - void validateFieldTypeMatches_ShouldAllowSubTypes() { + public void validateFieldTypeMatches_shouldAllowSubTypes() { assertAll( () -> assertDoesNotThrow( @@ -127,80 +96,41 @@ void validateFieldTypeMatches_ShouldAllowSubTypes() { ); } - /** - * {@link Validations#validateFieldTypeMatches(Class, String, Class)} should not - * throw if the field type is a sub-type of the given type or interface. - */ @Test - void validateFieldTypeMatches_ShouldFailOnSuperTypes() { + public void validateFieldTypeMatches_shouldFailOnSuperTypes() { assertAll( () -> { - Exception exc = assertThrows( - IllegalStateException.class, - () -> + ExpectedException + .when(() -> Validations.validateFieldTypeMatches( TestContainer.class, "listField", Collection.class - ), - "Should not allow Collection as a List" - ); - assertThat( - exc.getMessage(), - allOf( - containsString("should be of type List"), - containsString("but are Collection") + ) ) - ); + .assertThrows(IllegalStateException.class) + .assertMessageContains("should be of type List", "but are Collection"); }, () -> { - Exception exc = assertThrows( - IllegalStateException.class, - () -> + ExpectedException + .when(() -> Validations.validateFieldTypeMatches( TestContainer.class, "charsField", Object.class - ), - "Should not allow Object as a CharSequence" - ); - assertThat( - exc.getMessage(), - allOf( - containsString("should be of type CharSequence"), - containsString("but are Object") + ) ) - ); + .assertThrows(IllegalStateException.class) + .assertMessageContains("should be of type CharSequence", "but are Object"); } ); } - /** Test class for type checking. */ - private static class TestContainer { + @SuppressWarnings("unused") + private static final class TestContainer { List listField; Object objectField; CharSequence charsField; - - @Override - public int hashCode() { - return Objects.hash(charsField, listField, objectField); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof TestContainer)) { - return false; - } - TestContainer other = (TestContainer) obj; - return ( - Objects.equals(charsField, other.charsField) && - Objects.equals(listField, other.listField) && - Objects.equals(objectField, other.objectField) - ); - } } } From edfb49a1e4d3e098b753074e71c065c9d73351f3 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 4 Dec 2024 19:46:54 +0100 Subject: [PATCH 08/23] Adds recursive generic test --- .../WithPrefabValuesForFieldTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java index 1f8161e8b..39b88a76c 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/WithPrefabValuesForFieldTest.java @@ -177,6 +177,20 @@ public void succeed_whenClassContainsSomethingThatAllowsSubclassesAndASubclassIs .verify(); } + @Test + public void succeed_whenClassContainsAGenericInterfaceThatRefersToItself() { + DifficultGeneric one = new DifficultGeneric(new ArrayList<>()); + DifficultGeneric two = new DifficultGeneric(null); + EqualsVerifier + .forClass(DifficultGeneric.class) + .withPrefabValuesForField( + "list", + Collections.singletonList(one), + Collections.singletonList(two) + ) + .verify(); + } + static final class SinglePrecondition { private final FinalPoint point; @@ -308,4 +322,27 @@ public int hashCode() { return Objects.hash(list); } } + + public final class DifficultGeneric { + + private final List list; + + public DifficultGeneric(List list) { + this.list = list; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DifficultGeneric)) { + return false; + } + DifficultGeneric other = (DifficultGeneric) obj; + return Objects.equals(list, other.list); + } + + @Override + public int hashCode() { + return Objects.hash(list); + } + } } From 2a13d5abb541205a128908d698bf32a866eedc7e Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 15 Nov 2024 10:23:27 +0100 Subject: [PATCH 09/23] Simplifies a RecursionTest --- .../integration/operational/RecursionTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java index 62ee05800..1c01935f6 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/RecursionTest.java @@ -4,7 +4,6 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import com.google.common.collect.ImmutableList; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -140,9 +139,8 @@ public void giveCorrectErrorMessage_whenFieldIsInstantiatedUsingReflectiveFactor .assertMessageContains( RECURSIVE_DATASTRUCTURE, ImmutableListTree.class.getSimpleName(), - new TypeTag(ImmutableList.class, new TypeTag(ImmutableListTree.class)).toString(), - new TypeTag(Collection.class, new TypeTag(ImmutableListTree.class)).toString() - ); // I'd prefer not to have this last one though. + new TypeTag(ImmutableList.class, new TypeTag(ImmutableListTree.class)).toString() + ); } @Test From c296bb9d50ecf0cb131b61f464bc3b8576a641e2 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sun, 17 Nov 2024 19:43:44 +0100 Subject: [PATCH 10/23] Adds FactoryCache.copy() --- .../ConfiguredEqualsVerifier.java | 4 ++-- .../internal/reflection/FactoryCache.java | 17 ++++++++++++++--- .../internal/reflection/FactoryCacheTest.java | 10 ++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java index 5574cfb43..018445a66 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java @@ -51,7 +51,7 @@ private ConfiguredEqualsVerifier( public ConfiguredEqualsVerifier copy() { return new ConfiguredEqualsVerifier( EnumSet.copyOf(warningsToSuppress), - new FactoryCache().merge(factoryCache), + factoryCache.copy(), usingGetClass, fieldnameToGetter ); @@ -127,7 +127,7 @@ public SingleTypeEqualsVerifierApi forClass(Class type) { return new SingleTypeEqualsVerifierApi<>( type, EnumSet.copyOf(warningsToSuppress), - factoryCache, + factoryCache.copy(), objenesis, usingGetClass, fieldnameToGetter diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java index 1d77eabdd..5db5d3903 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java @@ -66,6 +66,17 @@ public boolean contains(Class type) { return cache.containsKey(type.getName()); } + /** + * Returns a new {@code FactoryCache} instance containing the factories from {@code this}. + * + * @return a new instance containing factories from {@code this} + */ + public FactoryCache copy() { + FactoryCache result = new FactoryCache(); + addAll(result, this); + return result; + } + /** * Returns a new {@code FactoryCache} instance containing the factories from {@code this} and * from the {@code other} cache. @@ -75,12 +86,12 @@ public boolean contains(Class type) { */ public FactoryCache merge(FactoryCache other) { FactoryCache result = new FactoryCache(); - copy(result, this); - copy(result, other); + addAll(result, this); + addAll(result, other); return result; } - private void copy(FactoryCache to, FactoryCache from) { + private void addAll(FactoryCache to, FactoryCache from) { for (Map.Entry> entry : from.cache.entrySet()) { to.put(entry.getKey(), entry.getValue()); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java index bbe20d280..90801ea0a 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java @@ -55,6 +55,16 @@ public void doesntContain() { assertFalse(cache.contains(STRING_CLASS)); } + @Test + public void copy() { + cache.put(STRING_CLASS, STRING_FACTORY); + FactoryCache copy = cache.copy(); + copy.put(INT_CLASS, INT_FACTORY); + assertTrue(copy.contains(STRING_CLASS)); + assertFalse(copy == cache); + assertFalse(cache.contains(INT_CLASS)); + } + @Test public void merge() { FactoryCache a = new FactoryCache(); From 642e9043c06ccc8869ebefc67f7faf000115f849 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 4 Dec 2024 19:59:01 +0100 Subject: [PATCH 11/23] Removes unnecessary complication --- .../factories/FallbackFactory.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java index eb69ea6b3..e74a21580 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java @@ -1,10 +1,7 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; import java.lang.reflect.Array; -import java.lang.reflect.Field; import java.util.LinkedHashSet; -import nl.jqno.equalsverifier.internal.reflection.FieldIterable; -import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; @@ -43,7 +40,6 @@ public Tuple createValues( return giveArrayInstances(tag, valueProvider, clone); } - traverseFields(tag, valueProvider, clone); return giveInstances(tag, valueProvider, clone); } @@ -82,21 +78,6 @@ private Tuple giveArrayInstances( return new Tuple<>(red, blue, redCopy); } - private void traverseFields( - TypeTag tag, - VintageValueProvider valueProvider, - LinkedHashSet typeStack - ) { - Class type = tag.getType(); - for (Field field : FieldIterable.of(type)) { - FieldProbe probe = FieldProbe.of(field); - boolean isStaticAndFinal = probe.isStatic() && probe.isFinal(); - if (!isStaticAndFinal) { - valueProvider.realizeCacheFor(TypeTag.of(field, tag), typeStack); - } - } - } - private Tuple giveInstances( TypeTag tag, VintageValueProvider valueProvider, From c384ef812317b2f5b968162ae31d942433972194 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 22 Nov 2024 13:48:41 +0100 Subject: [PATCH 12/23] Fixes test name --- .../integration/extended_contract/RecordsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java index 076a44c41..fd6aa50ae 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordsTest.java @@ -134,7 +134,7 @@ public void succeed_whenRecordValidatesInput_givenValidPrefabValues() { } @Test - public void succeed_whenRecord() { + public void succeed_whenRecordHasBoundedWildcardGeneric() { EqualsVerifier.forClass(WildcardGenericRecordContainer.class).verify(); } From e2f3dbd30af8f7cd69342338d25e773598c74edd Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sat, 23 Nov 2024 20:02:14 +0100 Subject: [PATCH 13/23] Adds test case --- .../factories/FallbackFactoryTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java index ff91709c4..af6902890 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -5,6 +5,7 @@ import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; @@ -74,6 +75,18 @@ public void giveClassWithFields() { assertEquals(-10, IntContainer.STATIC_FINAL_I); } + @Test + public void redCopyIsNotSameAsRed() { + Tuple tuple = factory.createValues( + new TypeTag(IntContainer.class), + valueProvider, + typeStack + ); + + assertEquals(tuple.getRed(), tuple.getRedCopy()); + assertNotSame(tuple.getRed(), tuple.getRedCopy()); + } + @Test public void dontGiveRecursiveClass() { ExpectedException @@ -103,6 +116,7 @@ private void assertCorrectTuple(Class type, T expectedRed, T expectedBlue Tuple tuple = factory.createValues(new TypeTag(type), valueProvider, typeStack); assertEquals(expectedRed, tuple.getRed()); assertEquals(expectedBlue, tuple.getBlue()); + assertEquals(expectedRed, tuple.getRedCopy()); } private static final class IntContainer { From c0d03dfb5eb2cf795a880425398bb3a1522b8721 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Sun, 24 Nov 2024 19:45:51 +0100 Subject: [PATCH 14/23] Adds two more test cases --- .../vintage/RecordFallbackFactoryTest.java | 49 +++++++++++ .../SealedTypesFallbackFactoryTest.java | 85 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java create mode 100644 equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java new file mode 100644 index 000000000..e1f4ed91e --- /dev/null +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java @@ -0,0 +1,49 @@ +package nl.jqno.equalsverifier.internal.reflection.vintage; + +import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.objenesis.Objenesis; +import org.objenesis.ObjenesisStd; + +public class RecordFallbackFactoryTest { + + private FallbackFactory factory; + private VintageValueProvider valueProvider; + private LinkedHashSet typeStack; + + @BeforeEach + public void setUp() { + Objenesis objenesis = new ObjenesisStd(); + factory = new FallbackFactory<>(objenesis); + FactoryCache factoryCache = new FactoryCache(); + factoryCache.put(int.class, values(42, 1337, 42)); + valueProvider = new VintageValueProvider(factoryCache, objenesis); + typeStack = new LinkedHashSet<>(); + } + + @Test + public void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenticalInRedAndRedCopy() { + Tuple tuple = factory.createValues( + new TypeTag(GenericRecordContainer.class), + valueProvider, + typeStack + ); + + assertEquals(tuple.getRed(), tuple.getRedCopy()); + assertNotSame(tuple.getRed(), tuple.getRedCopy()); + } + + record GenericRecord(T t) {} + + record GenericRecordContainer(GenericRecord bgr) {} +} diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java new file mode 100644 index 000000000..0babdd4c1 --- /dev/null +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java @@ -0,0 +1,85 @@ +package nl.jqno.equalsverifier.internal.reflection.vintage; + +import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import java.util.LinkedHashSet; +import java.util.Objects; +import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; +import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.objenesis.Objenesis; +import org.objenesis.ObjenesisStd; + +public class SealedTypesFallbackFactoryTest { + + private FallbackFactory factory; + private VintageValueProvider valueProvider; + private LinkedHashSet typeStack; + + @BeforeEach + public void setUp() { + Objenesis objenesis = new ObjenesisStd(); + factory = new FallbackFactory<>(objenesis); + FactoryCache factoryCache = new FactoryCache(); + factoryCache.put(int.class, values(42, 1337, 42)); + valueProvider = new VintageValueProvider(factoryCache, objenesis); + typeStack = new LinkedHashSet<>(); + } + + @Test + public void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsField() { + Tuple tuple = factory.createValues( + new TypeTag(SealedParentWithFinalChild.class), + valueProvider, + typeStack + ); + + assertEquals(tuple.getRed(), tuple.getRedCopy()); + assertNotSame(tuple.getRed(), tuple.getRedCopy()); + } + + public abstract static sealed class SealedParentWithFinalChild permits FinalSealedChild { + + private final int i; + + public SealedParentWithFinalChild(int i) { + this.i = i; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof SealedParentWithFinalChild other && i == other.i; + } + + @Override + public int hashCode() { + return Objects.hash(i); + } + } + + public static final class FinalSealedChild extends SealedParentWithFinalChild { + + private final int j; + + public FinalSealedChild(int i, int j) { + super(i); + this.j = j; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof FinalSealedChild other && super.equals(obj) && j == other.j; + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), j); + } + } +} From ec8320dcd2f39adcfcc0361779f22e9294be91f5 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 10:04:50 +0100 Subject: [PATCH 15/23] Adds additional generics test --- .../extended_contract/GenericTypesTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 822567528..554c4ab08 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -15,6 +15,11 @@ public class GenericTypesTest { + @Test + public void succeed_whenClassHasGenericFieldThatsSpecifiedToABuiltinGeneric() { + EqualsVerifier.forClass(GenericContainerWithBuiltin.class).verify(); + } + @Test public void succeed_whenEqualsLooksAtJava8TypesGenericContent() { EqualsVerifier.forClass(JavaGenericTypeContainer.class).verify(); @@ -121,6 +126,29 @@ public void succeed_whenClassHasASelfReferenceGenericParameter_givenPrefabValues .verify(); } + static final class GenericContainerWithBuiltin { + + private final Generic> b; + + public GenericContainerWithBuiltin(Generic> b) { + this.b = b; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GenericContainerWithBuiltin)) { + return false; + } + GenericContainerWithBuiltin other = (GenericContainerWithBuiltin) obj; + return Objects.equals(b, other.b); + } + + @Override + public int hashCode() { + return Objects.hash(b); + } + } + static final class JavaGenericTypeContainer { private final Optional optional; @@ -172,6 +200,30 @@ public String toString() { } } + static final class Generic { + + private final T t; + + public Generic(T t) { + this.t = t; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Generic)) { + return false; + } + @SuppressWarnings("unchecked") + Generic other = (Generic) obj; + return Objects.equals(t, other.t); + } + + @Override + public int hashCode() { + return Objects.hash(t); + } + } + static final class ListContainer { private final List list; From 35de69434f5a05ceeeb193f5cffa51aafd3c03a4 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 21:49:38 +0100 Subject: [PATCH 16/23] Fixes name --- .../{ClassAccessorSealedTest.java => ClassProbeSealedTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/{ClassAccessorSealedTest.java => ClassProbeSealedTest.java} (94%) diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java similarity index 94% rename from equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java rename to equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java index 2b7ad0633..f9539c7a5 100644 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessorSealedTest.java +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -public class ClassAccessorSealedTest { +public class ClassProbeSealedTest { @Test public void isNotSealed() { From b2e191e7eebcc9b6edcaf0358771ada73da20cca Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 28 Nov 2024 16:30:52 +0100 Subject: [PATCH 17/23] Adds test where elements from 2 generic types are cast to their type --- .../extended_contract/GenericTypesTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 554c4ab08..43bddc2f6 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -90,6 +90,11 @@ public void succeed_whenToStringLooksAtNonCollectionGenericContent() { EqualsVerifier.forClass(SparseArrayToStringContainer.class).verify(); } + @Test + public void succeed_whenEqualsLooksAtGenericContent_givenTwoGenericFields() { + EqualsVerifier.forClass(TwoGenericsContainerWithIntrospection.class).verify(); + } + @Test public void succeed_whenClassHasTypeVariableThatExtendsSomething() { EqualsVerifier.forClass(TypeVariableExtendsContainer.class).verify(); @@ -745,6 +750,38 @@ public String toString() { } } + public static final class TwoGenericsContainerWithIntrospection { + + private final List stringList = new ArrayList<>(); + private final List intList = new ArrayList<>(); + + @SuppressWarnings("unused") + @Override + public boolean equals(Object obj) { + if (stringList != null && stringList.size() > 0) { + String key = stringList.get(0); // force a cast + } + if (intList != null && intList.size() > 0) { + Integer key = intList.get(0); // force a cast + } + + if (!(obj instanceof TwoGenericsContainerWithIntrospection)) { + return false; + } + TwoGenericsContainerWithIntrospection other = + (TwoGenericsContainerWithIntrospection) obj; + return ( + Objects.equals(stringList, other.stringList) && + Objects.equals(intList, other.intList) + ); + } + + @Override + public int hashCode() { + return Objects.hash(stringList, intList); + } + } + @SuppressWarnings("unused") static final class TypeVariableExtendsContainer> { From dc75bc4eea2e5ff08351d91b68e5c5ca736907e4 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 3 Dec 2024 19:23:44 +0100 Subject: [PATCH 18/23] Replaces SuppressFBWarnings with custom annotation to avoid external dependency --- equalsverifier-core/pom.xml | 14 ++++++------- .../equalsverifier/EqualsVerifierReport.java | 2 +- .../internal/SuppressFBWarnings.java | 16 +++++++++++++++ .../checkers/AbstractDelegationChecker.java | 2 +- .../internal/checkers/ExamplesChecker.java | 2 +- .../internal/checkers/HierarchyChecker.java | 2 +- .../NullPointerExceptionFieldCheck.java | 2 +- .../fieldchecks/StringFieldCheck.java | 2 +- .../fieldchecks/SymmetryFieldCheck.java | 2 +- .../fieldchecks/TransientFieldsCheck.java | 2 +- .../fieldchecks/TransitivityFieldCheck.java | 2 +- .../internal/exceptions/NoValueException.java | 2 +- .../exceptions/RecursionException.java | 2 +- .../reflection/ConditionalInstantiator.java | 2 +- .../internal/reflection/FieldProbe.java | 2 +- .../reflection/JavaApiPrefabValues.java | 20 +++++++++---------- .../instantiation/SubjectCreator.java | 2 +- .../instantiation/VintageValueProvider.java | 2 +- .../factories/AbstractGenericFactory.java | 2 +- .../testhelpers/ExpectedException.java | 2 +- .../internal/testhelpers/Util.java | 2 +- .../util/CachedHashCodeInitializer.java | 2 +- .../internal/util/Configuration.java | 2 +- .../equalsverifier/internal/util/Context.java | 2 +- 24 files changed, 52 insertions(+), 40 deletions(-) create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java diff --git a/equalsverifier-core/pom.xml b/equalsverifier-core/pom.xml index 2a565181b..8a04f1f3e 100644 --- a/equalsverifier-core/pom.xml +++ b/equalsverifier-core/pom.xml @@ -86,14 +86,6 @@ ${version.bytebuddy} - - - com.github.spotbugs - spotbugs-annotations - ${version.spotbugs} - provided - - org.junit.jupiter @@ -113,6 +105,12 @@ ${version.commons-lang3} test + + com.github.spotbugs + spotbugs-annotations + ${version.spotbugs} + test + diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java index f367a1a4b..6fb507982 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/EqualsVerifierReport.java @@ -1,7 +1,7 @@ package nl.jqno.equalsverifier; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; /** * Contains the results of an {@link nl.jqno.equalsverifier.EqualsVerifier} run. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java new file mode 100644 index 000000000..2750319d7 --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/SuppressFBWarnings.java @@ -0,0 +1,16 @@ +package nl.jqno.equalsverifier.internal; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +// CHECKSTYLE OFF: AbbreviationAsWordInName + +/** + * Copied over from spotbugs-annotations to avoid the dependency; see https://github.com/jqno/equalsverifier/issues/1026. + */ +@Retention(RetentionPolicy.CLASS) +public @interface SuppressFBWarnings { + String[] value() default {}; + + String justification() default ""; +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java index 3b5820ab7..41eb3ef35 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java @@ -2,8 +2,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.ClassProbe; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.Tuple; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java index fd53331b1..3195e1be8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java @@ -3,11 +3,11 @@ import static nl.jqno.equalsverifier.internal.util.Assert.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.AssertionException; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java index 815370e31..fc7de55b4 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java @@ -3,10 +3,10 @@ import static nl.jqno.equalsverifier.internal.util.Assert.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.ClassProbe; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java index 0ad2fd058..ce83a8c38 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java @@ -2,8 +2,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldMutator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java index 9377394a0..ee5614ac8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java index c3611eebc..cad26b78b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.assertTrue; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java index 261d970a7..c149c2ccc 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java index 6e20d3991..243c7b91f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java @@ -2,7 +2,7 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java index 182a71572..3ccaa06b4 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java @@ -1,6 +1,6 @@ package nl.jqno.equalsverifier.internal.exceptions; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.TypeTag; @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "EqualsVerifier doesn't serialize.") diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java index 1221f1c0b..1b7d590e4 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/RecursionException.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.exceptions; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Iterator; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.TypeTag; /** Signals that a recursion has been detected while traversing the fields of a data structure. */ diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java index b96e779fe..c7fcf7a1f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ConditionalInstantiator.java @@ -2,10 +2,10 @@ import static nl.jqno.equalsverifier.internal.reflection.Util.classForName; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; /** Allows instantiation of classes that may or may not be present on the classpath. */ diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java index 56cd194b6..63012e644 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldProbe.java @@ -3,10 +3,10 @@ import static nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.util.Configuration; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java index e1db1d3e3..c52ba7ed1 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java @@ -5,21 +5,21 @@ import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.beans.PropertyChangeSupport; import java.io.File; import java.io.PrintStream; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; -import java.net.*; +import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URL; import java.nio.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.SimpleDateFormat; +import java.text.*; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.*; @@ -28,11 +28,9 @@ import java.util.concurrent.locks.StampedLock; import java.util.function.Supplier; import java.util.regex.Pattern; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumMapFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumSetFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.ExternalFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.*; /** * Creates instances of classes for use in a {@link VintageValueProvider} object. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java index 17fc59420..d4f23867f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java @@ -1,9 +1,9 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ModuleException; import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.util.Configuration; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java index c92154520..c4937e21e 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java @@ -1,7 +1,7 @@ package nl.jqno.equalsverifier.internal.reflection.instantiation; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.*; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.FactoryCache; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java index 0058867ad..ef35f58c3 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java @@ -1,11 +1,11 @@ package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java index 523cc4e97..2749f0320 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/ExpectedException.java @@ -1,6 +1,6 @@ package nl.jqno.equalsverifier.internal.testhelpers; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.MessagingException; @SuppressFBWarnings( diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java index 9b67fd1e1..feb7cd492 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/testhelpers/Util.java @@ -1,9 +1,9 @@ package nl.jqno.equalsverifier.internal.testhelpers; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.util.Objects; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java index a45fc40d4..697631262 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/CachedHashCodeInitializer.java @@ -2,10 +2,10 @@ import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.SuperclassIterable; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java index 72c06ef98..428a617cf 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Configuration.java @@ -1,11 +1,11 @@ package nl.jqno.equalsverifier.internal.util; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.*; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java index e70f1620d..d7d7a5591 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java @@ -1,6 +1,6 @@ package nl.jqno.equalsverifier.internal.util; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; From 0ea6453daf964332c299b43e3bd381977f07802a Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 5 Dec 2024 08:17:29 +0100 Subject: [PATCH 19/23] Adds test for difficult generic scenario --- .../extended_contract/GenericTypesTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 43bddc2f6..e5ada6994 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -131,6 +131,19 @@ public void succeed_whenClassHasASelfReferenceGenericParameter_givenPrefabValues .verify(); } + @Test + public void succeed_whenClassContainsAMapWithAnArray() { + EqualsVerifier.forClass(ArrayMapContainer.class).withNonnullFields("map").verify(); + } + + @Test + public void succeed_whenClassContainsAClassThatContainsAMapWithArray() { + EqualsVerifier + .forClass(ArrayMapContainerContainer.class) + .withNonnullFields("mapContainer") + .verify(); + } + static final class GenericContainerWithBuiltin { private final Generic> b; @@ -848,4 +861,63 @@ public final int hashCode() { return Objects.hash(i, wrapped); } } + + static class ArrayMapContainerContainer { + + private final ArrayMapContainer mapContainer; + + public ArrayMapContainerContainer(final ArrayMapContainer mapContainer) { + this.mapContainer = mapContainer; + } + + @Override + public final boolean equals(final Object o) { + if (!(o instanceof ArrayMapContainerContainer)) return false; + final ArrayMapContainerContainer that = (ArrayMapContainerContainer) o; + return Objects.equals(mapContainer, that.mapContainer); + } + + @Override + public final int hashCode() { + return Objects.hashCode(mapContainer); + } + } + + static class ArrayMapContainer { + + private final Map map; + + public ArrayMapContainer(final Map map) { + this.map = map; + } + + @Override + public final boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ArrayMapContainer)) { + return false; + } + final ArrayMapContainer that = (ArrayMapContainer) o; + if (map.size() != that.map.size()) { + return false; + } + for (final Map.Entry entry : map.entrySet()) { + if (!Arrays.equals(entry.getValue(), that.map.get(entry.getKey()))) { + return false; + } + } + return true; + } + + @Override + public final int hashCode() { + int hashCode = 0; + for (final Map.Entry entry : map.entrySet()) { + hashCode += entry.getKey().hashCode() ^ Arrays.hashCode(entry.getValue()); + } + return hashCode; + } + } } From 58e7e2eb78c84047fc1774d6715eaea84a13c5c5 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 5 Dec 2024 08:20:37 +0100 Subject: [PATCH 20/23] Adds test for difficult generic scenario --- .../integration/extended_contract/GenericTypesTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index e5ada6994..0a24e1fc3 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -872,7 +872,9 @@ public ArrayMapContainerContainer(final ArrayMapContainer mapContainer) { @Override public final boolean equals(final Object o) { - if (!(o instanceof ArrayMapContainerContainer)) return false; + if (!(o instanceof ArrayMapContainerContainer)) { + return false; + } final ArrayMapContainerContainer that = (ArrayMapContainerContainer) o; return Objects.equals(mapContainer, that.mapContainer); } From 17871bc82781e3600657fd79df2ac3becc81e80b Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 5 Dec 2024 08:24:08 +0100 Subject: [PATCH 21/23] Small improvement --- .../reflection/vintage/prefabvalues/factories/MapFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java index f835cfe90..5673808f7 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java @@ -43,7 +43,7 @@ public Tuple createValues( T blue = createEmpty.get(); if (!redKey.equals(blueKey)) { // This happens with single-element enums - blue.put(valueProvider.giveBlue(keyTag), blueValue); + blue.put(blueKey, blueValue); } T redCopy = createEmpty.get(); From 7da2273ff980b4774f371982237c698f32f68406 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Thu, 5 Dec 2024 09:53:56 +0100 Subject: [PATCH 22/23] Ports back some more tests --- .../extended_contract/GenericTypesTest.java | 48 +++++++++---------- .../ConfiguredEqualsVerifierMultipleTest.java | 21 ++++++++ .../ConfiguredEqualsVerifierSingleTest.java | 21 ++++++++ 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 0a24e1fc3..c3cce62cf 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -167,6 +167,30 @@ public int hashCode() { } } + static final class Generic { + + private final T t; + + public Generic(T t) { + this.t = t; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Generic)) { + return false; + } + @SuppressWarnings("unchecked") + Generic other = (Generic) obj; + return Objects.equals(t, other.t); + } + + @Override + public int hashCode() { + return Objects.hash(t); + } + } + static final class JavaGenericTypeContainer { private final Optional optional; @@ -218,30 +242,6 @@ public String toString() { } } - static final class Generic { - - private final T t; - - public Generic(T t) { - this.t = t; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Generic)) { - return false; - } - @SuppressWarnings("unchecked") - Generic other = (Generic) obj; - return Objects.equals(t, other.t); - } - - @Override - public int hashCode() { - return Objects.hash(t); - } - } - static final class ListContainer { private final List list; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java index 94ce5f16d..8600efe44 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierMultipleTest.java @@ -156,6 +156,27 @@ public void individuallySuppressedWarningsAreNotAddedGlobally() { public void individuallyAddedPrefabValuesAreNotAddedGlobally() { ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); + // should succeed + ev + .forClasses(RecursiveTypeContainer.class, A.class) + .withPrefabValues( + RecursiveType.class, + new RecursiveType(null), + new RecursiveType(new RecursiveType(null)) + ) + .verify(); + + // PrefabValues are not added to configuration, so should fail + ExpectedException + .when(() -> ev.forClasses(RecursiveTypeContainer.class, A.class).verify()) + .assertFailure() + .assertMessageContains("Recursive datastructure"); + } + + @Test + public void individuallyAddedGenericPrefabValuesAreNotAddedGlobally() { + ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); + // should succeed ev .forClasses(SingleGenericContainerContainer.class, A.class) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java index 16cd8f8a9..7ace3f1ae 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/operational/ConfiguredEqualsVerifierSingleTest.java @@ -117,6 +117,27 @@ public void individuallySuppressedWarningsAreNotAddedGlobally() { public void individuallyAddedPrefabValuesAreNotAddedGlobally() { ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); + // should succeed + ev + .forClass(RecursiveTypeContainer.class) + .withPrefabValues( + RecursiveType.class, + new RecursiveType(null), + new RecursiveType(new RecursiveType(null)) + ) + .verify(); + + // PrefabValues are not added to configuration, so should fail + ExpectedException + .when(() -> ev.forClass(RecursiveTypeContainer.class).verify()) + .assertFailure() + .assertMessageContains("Recursive datastructure"); + } + + @Test + public void individuallyAddedGenericPrefabValuesAreNotAddedGlobally() { + ConfiguredEqualsVerifier ev = EqualsVerifier.configure(); + // should succeed ev .forClass(SingleGenericContainerContainer.class) From 92025ef7997aff22efb331a15373bda50cc81a3e Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 6 Dec 2024 08:51:37 +0100 Subject: [PATCH 23/23] Re-organizes vintage packages --- .../RecordInstanceCreatorTest.java | 2 +- .../factories}/RecordFallbackFactoryTest.java | 9 +++-- .../RecordObjectAccessorCopyingTest.java | 2 +- .../RecordObjectAccessorScramblingTest.java | 10 +++--- .../reflection}/RecordObjectAccessorTest.java | 6 ++-- .../SealedTypesFallbackFactoryTest.java | 9 +++-- .../ConfiguredEqualsVerifier.java | 4 +-- .../api/SingleTypeEqualsVerifierApi.java | 3 +- .../checkers/AbstractDelegationChecker.java | 9 ++--- .../internal/checkers/ExamplesChecker.java | 2 +- .../internal/checkers/FieldsChecker.java | 2 +- .../internal/checkers/HierarchyChecker.java | 2 +- .../MapEntryHashCodeRequirementChecker.java | 2 +- .../internal/checkers/RecordChecker.java | 2 +- .../checkers/fieldchecks/ArrayFieldCheck.java | 2 +- .../fieldchecks/BigDecimalFieldCheck.java | 2 +- .../fieldchecks/FloatAndDoubleFieldCheck.java | 2 +- .../fieldchecks/JpaLazyGetterFieldCheck.java | 4 +-- .../fieldchecks/MutableStateFieldCheck.java | 2 +- .../NullPointerExceptionFieldCheck.java | 2 +- .../fieldchecks/ReflexivityFieldCheck.java | 4 +-- .../fieldchecks/SignificantFieldCheck.java | 2 +- .../fieldchecks/StringFieldCheck.java | 4 +-- .../fieldchecks/SymmetryFieldCheck.java | 2 +- .../fieldchecks/TransientFieldsCheck.java | 2 +- .../fieldchecks/TransitivityFieldCheck.java | 2 +- .../instantiation/InstanceCreator.java | 2 +- .../JavaApiPrefabValues.java | 12 ++++--- .../instantiation/SubjectCreator.java | 2 +- .../instantiation/ValueProvider.java | 2 +- .../vintage}/FactoryCache.java | 5 ++- .../vintage}/PrefabValuesApi.java | 12 +++---- .../vintage}/VintageValueProvider.java | 8 ++--- .../factories/AbstractGenericFactory.java | 4 +-- .../prefabvalues/factories/CopyFactory.java | 4 +-- .../factories/EnumMapFactory.java | 4 +-- .../factories/EnumSetFactory.java | 4 +-- .../factories/ExternalFactory.java | 10 +++--- .../prefabvalues/factories/Factories.java | 2 +- .../factories/FallbackFactory.java | 6 ++-- .../prefabvalues/factories/MapFactory.java | 4 +-- .../factories/PrefabValueFactory.java | 4 +-- .../prefabvalues/factories/SimpleFactory.java | 4 +-- .../factories/SimpleGenericFactory.java | 4 +-- .../factoryproviders/AwtFactoryProvider.java | 10 +++--- .../factoryproviders/FactoryProvider.java | 7 ++++ .../GuavaFactoryProvider.java | 13 +++----- .../JavaFxFactoryProvider.java | 15 +++++---- .../JavaxFactoryProvider.java | 6 ++-- .../factoryproviders/JodaFactoryProvider.java | 6 ++-- .../factoryproviders/RmiFactoryProvider.java | 6 ++-- .../vintage/reflection}/ClassAccessor.java | 4 +-- .../vintage/reflection}/FieldModifier.java | 4 +-- .../reflection}/InPlaceObjectAccessor.java | 4 +-- .../vintage/reflection}/ObjectAccessor.java | 4 +-- .../reflection}/RecordObjectAccessor.java | 4 +-- .../internal/reflection/FieldCache.java | 2 +- .../factoryproviders/FactoryProvider.java | 7 ---- .../equalsverifier/internal/util/Context.java | 11 ++++--- .../internal/util/Validations.java | 7 ++-- .../architecture/ArchitectureTest.java | 33 +++++++------------ .../instantiation/InstanceCreatorTest.java | 2 +- .../instantiation/SubjectCreatorTest.java | 2 +- .../vintage}/FactoryCacheTest.java | 6 ++-- .../vintage}/PrefabValuesApiTest.java | 2 +- .../VintageValueProviderCreatorTest.java | 5 ++- .../vintage}/VintageValueProviderTest.java | 7 ++-- .../factories/AbstractGenericFactoryTest.java | 4 +-- .../prefabvalues/factories/FactoriesTest.java | 2 +- .../factories/FallbackFactoryTest.java | 8 ++--- .../factories/MapFactoryTest.java | 6 ++-- .../factories/SimpleFactoryTest.java | 2 +- .../factories/SimpleGenericFactoryTest.java | 6 ++-- .../JavaFxFactoryProviderTest.java | 10 +++--- .../reflection}/ClassAccessorTest.java | 10 +++--- .../reflection}/FieldModifierTest.java | 2 +- .../InPlaceObjectAccessorCopyingTest.java | 2 +- .../InPlaceObjectAccessorScramblingTest.java | 10 +++--- .../InPlaceObjectAccessorTest.java | 2 +- .../testhelpers/FactoryCacheFactory.java | 4 +-- .../jar/helper/JarAsserter.java | 2 +- 81 files changed, 207 insertions(+), 217 deletions(-) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/{reflection => }/instantiation/RecordInstanceCreatorTest.java (93%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/prefabvalues/factories}/RecordFallbackFactoryTest.java (78%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/RecordObjectAccessorCopyingTest.java (96%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/RecordObjectAccessorScramblingTest.java (84%) rename equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/RecordObjectAccessorTest.java (94%) rename equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/prefabvalues/factories}/SealedTypesFallbackFactoryTest.java (85%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => }/instantiation/InstanceCreator.java (97%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/JavaApiPrefabValues.java (98%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => }/instantiation/SubjectCreator.java (99%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => }/instantiation/ValueProvider.java (96%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation/vintage}/FactoryCache.java (93%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{util => instantiation/vintage}/PrefabValuesApi.java (84%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/instantiation => instantiation/vintage}/VintageValueProvider.java (95%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/AbstractGenericFactory.java (94%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/CopyFactory.java (86%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/EnumMapFactory.java (89%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/EnumSetFactory.java (88%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/ExternalFactory.java (73%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/Factories.java (94%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/FallbackFactory.java (92%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/MapFactory.java (91%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/PrefabValueFactory.java (83%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/SimpleFactory.java (80%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/SimpleGenericFactory.java (91%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java (83%) create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/FactoryProvider.java rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java (92%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java (86%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java (70%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java (81%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java (61%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/ClassAccessor.java (96%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/FieldModifier.java (95%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/InPlaceObjectAccessor.java (90%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/ObjectAccessor.java (95%) rename equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/RecordObjectAccessor.java (93%) delete mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => }/instantiation/InstanceCreatorTest.java (96%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => }/instantiation/SubjectCreatorTest.java (99%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation/vintage}/FactoryCacheTest.java (89%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{util => instantiation/vintage}/PrefabValuesApiTest.java (81%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/instantiation => instantiation/vintage}/VintageValueProviderCreatorTest.java (96%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/instantiation => instantiation/vintage}/VintageValueProviderTest.java (96%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java (90%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/FactoriesTest.java (75%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/FallbackFactoryTest.java (93%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/MapFactoryTest.java (93%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/SimpleFactoryTest.java (89%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java (93%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection => instantiation}/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java (86%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/ClassAccessorTest.java (92%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/FieldModifierTest.java (95%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/InPlaceObjectAccessorCopyingTest.java (97%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/InPlaceObjectAccessorScramblingTest.java (93%) rename equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/{reflection/vintage => instantiation/vintage/reflection}/InPlaceObjectAccessorTest.java (91%) diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/RecordInstanceCreatorTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/RecordInstanceCreatorTest.java similarity index 93% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/RecordInstanceCreatorTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/RecordInstanceCreatorTest.java index 8bced9fd4..69a0ea94a 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/RecordInstanceCreatorTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/RecordInstanceCreatorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java similarity index 78% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java index e1f4ed91e..4b003c695 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/RecordFallbackFactoryTest.java @@ -1,15 +1,14 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.LinkedHashSet; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.objenesis.Objenesis; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java similarity index 96% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java index 25c904414..09720656a 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorCopyingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorCopyingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java similarity index 84% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java index 830186672..171b5dcc9 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorScramblingTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorScramblingTest.java @@ -1,15 +1,15 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; import java.lang.reflect.Constructor; import java.util.LinkedHashSet; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.objenesis.ObjenesisStd; diff --git a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorTest.java similarity index 94% rename from equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java rename to equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorTest.java index dbcbb904f..6934991b4 100644 --- a/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessorTest.java +++ b/equalsverifier-16/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -7,10 +7,10 @@ import java.util.LinkedHashSet; import java.util.Objects; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Instantiator; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java similarity index 85% rename from equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java rename to equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java index 0babdd4c1..88b60c153 100644 --- a/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java +++ b/equalsverifier-17/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SealedTypesFallbackFactoryTest.java @@ -1,16 +1,15 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.LinkedHashSet; import java.util.Objects; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.objenesis.Objenesis; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java index 018445a66..6d3ee7001 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/ConfiguredEqualsVerifier.java @@ -9,10 +9,10 @@ import nl.jqno.equalsverifier.api.EqualsVerifierApi; import nl.jqno.equalsverifier.api.MultipleTypeEqualsVerifierApi; import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.PrefabValuesApi; import nl.jqno.equalsverifier.internal.reflection.PackageScanner; import nl.jqno.equalsverifier.internal.util.ListBuilders; -import nl.jqno.equalsverifier.internal.util.PrefabValuesApi; import nl.jqno.equalsverifier.internal.util.Validations; import org.objenesis.Objenesis; import org.objenesis.ObjenesisStd; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java index c09b94d68..e87acdac8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/SingleTypeEqualsVerifierApi.java @@ -9,7 +9,8 @@ import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.checkers.*; import nl.jqno.equalsverifier.internal.exceptions.MessagingException; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.PrefabValuesApi; import nl.jqno.equalsverifier.internal.reflection.FieldCache; import nl.jqno.equalsverifier.internal.util.*; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java index 41eb3ef35..63b3cb93c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/AbstractDelegationChecker.java @@ -4,12 +4,9 @@ import java.lang.reflect.Field; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.reflection.ClassProbe; -import nl.jqno.equalsverifier.internal.reflection.FieldIterable; -import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.util.*; public class AbstractDelegationChecker implements Checker { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java index 3195e1be8..ba1e91f9f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/ExamplesChecker.java @@ -9,8 +9,8 @@ import java.util.Objects; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.AssertionException; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.*; public class ExamplesChecker implements Checker { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java index 263519800..2aab34ba8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldsChecker.java @@ -3,11 +3,11 @@ import java.util.function.Predicate; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.checkers.fieldchecks.*; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java index fc7de55b4..1367ef57f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/HierarchyChecker.java @@ -7,10 +7,10 @@ import java.lang.reflect.Modifier; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.ClassProbe; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.*; public class HierarchyChecker implements Checker { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java index 3caf7f991..7e219f02f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/MapEntryHashCodeRequirementChecker.java @@ -4,7 +4,7 @@ import java.util.Map; import java.util.Objects; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java index 30cd67409..1ac829845 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/RecordChecker.java @@ -9,9 +9,9 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.ClassProbe; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java index 506c37a19..c269b96d8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ArrayFieldCheck.java @@ -3,8 +3,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.assertEquals; import java.lang.reflect.Array; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java index d766321d8..9ec15ae89 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/BigDecimalFieldCheck.java @@ -6,8 +6,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java index 64841b5f5..a970b2e3f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FloatAndDoubleFieldCheck.java @@ -2,8 +2,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.assertEquals; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; public class FloatAndDoubleFieldCheck implements FieldCheck { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java index 2632bc342..1ed068764 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/JpaLazyGetterFieldCheck.java @@ -9,11 +9,11 @@ import java.util.function.Function; import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.internal.exceptions.EqualsVerifierInternalBugException; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java index 13b0b576e..9d71e65ee 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/MutableStateFieldCheck.java @@ -3,8 +3,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; import java.util.function.Predicate; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; public class MutableStateFieldCheck implements FieldCheck { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java index ce83a8c38..7219616f7 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/NullPointerExceptionFieldCheck.java @@ -4,9 +4,9 @@ import java.lang.reflect.Field; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldMutator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.*; @SuppressFBWarnings( diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java index c8705a78c..9e28dea88 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/ReflexivityFieldCheck.java @@ -7,11 +7,11 @@ import java.util.EnumSet; import java.util.Set; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.*; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.util.Configuration; import nl.jqno.equalsverifier.internal.util.Context; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java index c459965c7..19d530ea8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SignificantFieldCheck.java @@ -7,10 +7,10 @@ import java.util.Set; import java.util.function.Predicate; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.*; public class SignificantFieldCheck implements FieldCheck { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java index ee5614ac8..0000feb2f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/StringFieldCheck.java @@ -4,10 +4,10 @@ import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; import nl.jqno.equalsverifier.internal.util.CachedHashCodeInitializer; import nl.jqno.equalsverifier.internal.util.Formatter; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java index cad26b78b..1bc2d67ad 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java @@ -3,8 +3,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.assertTrue; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; public class SymmetryFieldCheck implements FieldCheck { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java index c149c2ccc..a0f2c9c3b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransientFieldsCheck.java @@ -3,11 +3,11 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; public class TransientFieldsCheck implements FieldCheck { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java index 243c7b91f..c4b540a96 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/TransitivityFieldCheck.java @@ -3,8 +3,8 @@ import static nl.jqno.equalsverifier.internal.util.Assert.fail; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; import nl.jqno.equalsverifier.internal.util.Formatter; public class TransitivityFieldCheck implements FieldCheck { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/InstanceCreator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/InstanceCreator.java similarity index 97% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/InstanceCreator.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/InstanceCreator.java index 51b93e953..eb79f3b79 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/InstanceCreator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/InstanceCreator.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation; import java.lang.reflect.Field; import java.util.*; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/JavaApiPrefabValues.java similarity index 98% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/JavaApiPrefabValues.java index c52ba7ed1..65e710c2e 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/JavaApiPrefabValues.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/JavaApiPrefabValues.java @@ -1,8 +1,8 @@ -package nl.jqno.equalsverifier.internal.reflection; +package nl.jqno.equalsverifier.internal.instantiation; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.*; import static nl.jqno.equalsverifier.internal.reflection.Util.classes; import static nl.jqno.equalsverifier.internal.reflection.Util.objects; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.*; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; import java.beans.PropertyChangeSupport; @@ -29,8 +29,12 @@ import java.util.function.Supplier; import java.util.regex.Pattern; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.*; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.*; +import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; /** * Creates instances of classes for use in a {@link VintageValueProvider} object. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreator.java similarity index 99% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreator.java index d4f23867f..3e5e59b6c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreator.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreator.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation; import java.lang.reflect.Field; import java.util.HashMap; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/ValueProvider.java similarity index 96% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/ValueProvider.java index 268a43e24..e2482c139 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/ValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/ValueProvider.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation; import java.util.Optional; import nl.jqno.equalsverifier.internal.exceptions.NoValueException; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/FactoryCache.java similarity index 93% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/FactoryCache.java index 5db5d3903..a07a000cc 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FactoryCache.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/FactoryCache.java @@ -1,9 +1,8 @@ -package nl.jqno.equalsverifier.internal.reflection; +package nl.jqno.equalsverifier.internal.instantiation.vintage; import java.util.HashMap; import java.util.Map; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; /** Contains a cache of factories, for {@link VintageValueProvider}. */ public class FactoryCache { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/PrefabValuesApi.java similarity index 84% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/PrefabValuesApi.java index 8bc5c9c0c..7d153fe08 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApi.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/PrefabValuesApi.java @@ -1,15 +1,15 @@ -package nl.jqno.equalsverifier.internal.util; +package nl.jqno.equalsverifier.internal.instantiation.vintage; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.simple; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.simple; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import nl.jqno.equalsverifier.Func.Func1; import nl.jqno.equalsverifier.Func.Func2; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.reflection.ObjectAccessor; import nl.jqno.equalsverifier.internal.reflection.FieldCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; -import nl.jqno.equalsverifier.internal.reflection.vintage.ObjectAccessor; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.util.Validations; import org.objenesis.Objenesis; public final class PrefabValuesApi { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProvider.java similarity index 95% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProvider.java index c4937e21e..333b2ef6c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProvider.java @@ -1,14 +1,14 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation.vintage; import java.util.*; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.FallbackFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.util.PrimitiveMappers; import nl.jqno.equalsverifier.internal.util.Rethrow; import org.objenesis.Objenesis; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/AbstractGenericFactory.java similarity index 94% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/AbstractGenericFactory.java index ef35f58c3..1534761a2 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/AbstractGenericFactory.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -7,8 +7,8 @@ import java.util.List; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Abstract implementation of {@link PrefabValueFactory} that provides helper functions for dealing diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/CopyFactory.java similarity index 86% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/CopyFactory.java index 1b1222861..332c159c2 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/CopyFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/CopyFactory.java @@ -1,10 +1,10 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.LinkedHashSet; import java.util.function.Function; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public class CopyFactory extends AbstractGenericFactory { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java similarity index 89% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java index 5b1424694..8ca507f7f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumMapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java @@ -1,12 +1,12 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Function; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; @SuppressWarnings({ "unchecked", "rawtypes" }) public final class EnumMapFactory extends AbstractGenericFactory { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java similarity index 88% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java index 61a59e447..ad0c9a806 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/EnumSetFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java @@ -1,12 +1,12 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.function.Function; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that instantiates EnumSets using reflection, while diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/ExternalFactory.java similarity index 73% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/ExternalFactory.java index 0bea3340b..7ed1166df 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/ExternalFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/ExternalFactory.java @@ -1,20 +1,20 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static nl.jqno.equalsverifier.internal.reflection.Util.classes; import static nl.jqno.equalsverifier.internal.reflection.Util.objects; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders.FactoryProvider; import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.FactoryProvider; public class ExternalFactory implements PrefabValueFactory { private static final String EXTERNAL_FACTORIES_PACKAGE = - "nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders."; + "nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders."; private final String factoryName; private FactoryCache factoryCache; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/Factories.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/Factories.java similarity index 94% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/Factories.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/Factories.java index 42cf962cd..f2240b56f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/Factories.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/Factories.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.Collection; import java.util.Map; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactory.java similarity index 92% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactory.java index e74a21580..73f459a67 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactory.java @@ -1,11 +1,11 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.lang.reflect.Array; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.reflection.ClassAccessor; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/MapFactory.java similarity index 91% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/MapFactory.java index 5673808f7..b50ca8a05 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/MapFactory.java @@ -1,11 +1,11 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Supplier; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that specializes in creating implementations of diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/PrefabValueFactory.java similarity index 83% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/PrefabValueFactory.java index 4616c2660..c7f03252a 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/PrefabValueFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/PrefabValueFactory.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Creates instances of generic types for use as prefab value. diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactory.java similarity index 80% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactory.java index 44a7ae041..77375f3d6 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactory.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; /** * Implementation of {@link PrefabValueFactory} that holds on to two instances that have already diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleGenericFactory.java similarity index 91% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleGenericFactory.java index 748f64f7f..70a8b683d 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleGenericFactory.java @@ -1,13 +1,13 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.function.Supplier; import nl.jqno.equalsverifier.Func; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public class SimpleGenericFactory extends AbstractGenericFactory { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java similarity index 83% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java index 2312d3b5a..ccee73a6b 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/AwtFactoryProvider.java @@ -1,13 +1,15 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; -import java.awt.*; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; import java.awt.image.BufferedImage; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; public final class AwtFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/FactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/FactoryProvider.java new file mode 100644 index 000000000..685937c3b --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/FactoryProvider.java @@ -0,0 +1,7 @@ +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; + +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; + +public interface FactoryProvider { + FactoryCache getFactoryCache(); +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java similarity index 92% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java index 4416de38c..ebba614d2 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/GuavaFactoryProvider.java @@ -1,19 +1,16 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.*; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.*; import com.google.common.collect.*; import com.google.common.reflect.TypeToken; import java.util.*; import java.util.function.Supplier; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.*; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumMapFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.EnumSetFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories; public final class GuavaFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java similarity index 86% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java index aa2b6a3ca..b47636262 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaFxFactoryProvider.java @@ -1,16 +1,19 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.*; import static nl.jqno.equalsverifier.internal.reflection.Util.classForName; import static nl.jqno.equalsverifier.internal.reflection.Util.classes; import static nl.jqno.equalsverifier.internal.reflection.Util.objects; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.copy; import java.util.*; import java.util.function.Function; -import nl.jqno.equalsverifier.internal.reflection.*; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.AbstractGenericFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.AbstractGenericFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator; +import nl.jqno.equalsverifier.internal.reflection.Tuple; +import nl.jqno.equalsverifier.internal.reflection.TypeTag; public final class JavaFxFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java similarity index 70% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java index 386bb67ae..a223b962f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaxFactoryProvider.java @@ -1,10 +1,10 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import javax.naming.Reference; import javax.swing.tree.DefaultMutableTreeNode; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; public final class JavaxFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java similarity index 81% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java index da40b542d..255320318 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JodaFactoryProvider.java @@ -1,8 +1,8 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; import org.joda.time.*; import org.joda.time.chrono.GregorianChronology; import org.joda.time.chrono.ISOChronology; diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java similarity index 61% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java index edb25d411..5f55cac20 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/RmiFactoryProvider.java @@ -1,10 +1,10 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import java.rmi.dgc.VMID; import java.rmi.server.UID; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; public final class RmiFactoryProvider implements FactoryProvider { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ClassAccessor.java similarity index 96% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ClassAccessor.java index e19fde95d..905184334 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ClassAccessor.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/FieldModifier.java similarity index 95% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/FieldModifier.java index 0b91e5f87..546236fd3 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifier.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/FieldModifier.java @@ -1,13 +1,13 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; import java.lang.reflect.Field; import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; public final class FieldModifier { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessor.java similarity index 90% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessor.java index c9cf1c573..68089fdf8 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessor.java @@ -1,11 +1,11 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import java.lang.reflect.Field; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.Instantiator; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ObjectAccessor.java similarity index 95% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ObjectAccessor.java index 480e30224..9fe79aa2c 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/ObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ObjectAccessor.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import java.util.LinkedHashSet; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.RecordsHelper; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessor.java similarity index 93% rename from equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java rename to equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessor.java index c1f63ea44..425d46da6 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordObjectAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/RecordObjectAccessor.java @@ -1,14 +1,14 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import java.lang.reflect.Field; import java.util.LinkedHashSet; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.FieldProbe; import nl.jqno.equalsverifier.internal.reflection.RecordProbe; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.objenesis.Objenesis; /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java index 455a786e5..28856ac6f 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldCache.java @@ -1,7 +1,7 @@ package nl.jqno.equalsverifier.internal.reflection; import java.util.*; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; /** Contains a cache for values connected to specific fields, for {@link SubjectCreator}. */ public class FieldCache { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java deleted file mode 100644 index c81cda452..000000000 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/FactoryProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; - -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; - -public interface FactoryProvider { - FactoryCache getFactoryCache(); -} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java index d7d7a5591..6081356d3 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Context.java @@ -1,10 +1,13 @@ package nl.jqno.equalsverifier.internal.util; import nl.jqno.equalsverifier.internal.SuppressFBWarnings; -import nl.jqno.equalsverifier.internal.reflection.*; -import nl.jqno.equalsverifier.internal.reflection.instantiation.SubjectCreator; -import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; +import nl.jqno.equalsverifier.internal.instantiation.ValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.reflection.ClassProbe; +import nl.jqno.equalsverifier.internal.reflection.FieldCache; import org.objenesis.Objenesis; public final class Context { diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java index 5bc2dcdf1..ece4b6740 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/Validations.java @@ -3,16 +3,13 @@ import static nl.jqno.equalsverifier.internal.util.ListBuilders.listContainsDuplicates; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import nl.jqno.equalsverifier.Warning; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.FieldIterable; import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache; import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; public final class Validations { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java index b7461f4e9..014186834 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/architecture/ArchitectureTest.java @@ -5,16 +5,10 @@ import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchRule; -import nl.jqno.equalsverifier.internal.reflection.FactoryCacheTest; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProviderCreatorTest; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProviderTest; -import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor; -import nl.jqno.equalsverifier.internal.reflection.vintage.FieldModifier; -import nl.jqno.equalsverifier.internal.reflection.vintage.ObjectAccessor; -import nl.jqno.equalsverifier.internal.util.Context; -import nl.jqno.equalsverifier.internal.util.PrefabValuesApi; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.reflection.ClassAccessor; +import nl.jqno.equalsverifier.internal.instantiation.vintage.reflection.FieldModifier; +import nl.jqno.equalsverifier.internal.instantiation.vintage.reflection.ObjectAccessor; import nl.jqno.equalsverifier.testhelpers.FactoryCacheFactory; @AnalyzeClasses(packages = "nl.jqno.equalsverifier") @@ -23,22 +17,19 @@ public final class ArchitectureTest { @ArchTest public static final ArchRule ONLY_VINTAGE_INSTANTIATORS_CAN_USE_VINTAGE_REFLECTION = noClasses() .that() + .resideOutsideOfPackage("nl.jqno.equalsverifier.internal.instantiation.vintage..") + .and() .doNotBelongToAnyOf( - VintageValueProvider.class, - Context.class, - PrefabValuesApi.class, JavaApiPrefabValues.class, // 👇 Test classes - FactoryCacheFactory.class, - FactoryCacheTest.class, - VintageValueProviderTest.class, - VintageValueProviderCreatorTest.class + FactoryCacheFactory.class ) - .and() - .resideOutsideOfPackage("nl.jqno.equalsverifier.internal.reflection.vintage..") .should() .accessClassesThat() - .resideInAPackage("nl.jqno.equalsverifier.internal.reflection.vintage.."); + .resideInAPackage("nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues..") + .orShould() + .accessClassesThat() + .resideInAPackage("nl.jqno.equalsverifier.internal.instantiation.vintage.reflection.."); @ArchTest public static final ArchRule DONT_USE_VINTAGE_REFLECTION_DIRECTLY = noClasses() @@ -83,7 +74,7 @@ public final class ArchitectureTest { ); private static final String FACTORYPROVIDER_PATTERN = - "nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.."; + "nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders.."; private static final String TEST_CLASS_PATTERN = ".*Test(\\$.*)?$"; private ArchitectureTest() { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/InstanceCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/InstanceCreatorTest.java similarity index 96% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/InstanceCreatorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/InstanceCreatorTest.java index 4cd563b6f..0ca65bbe0 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/InstanceCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/InstanceCreatorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java similarity index 99% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java index e62ebfd13..46a603f0c 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/SubjectCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/SubjectCreatorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/FactoryCacheTest.java similarity index 89% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/FactoryCacheTest.java index 90801ea0a..a91e73794 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/FactoryCacheTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/FactoryCacheTest.java @@ -1,9 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection; +package nl.jqno.equalsverifier.internal.instantiation.vintage; import static org.junit.jupiter.api.Assertions.*; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.SimpleFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.SimpleFactory; import org.junit.jupiter.api.Test; public class FactoryCacheTest { diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/PrefabValuesApiTest.java similarity index 81% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/PrefabValuesApiTest.java index cae0f474d..33d789da6 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/PrefabValuesApiTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/PrefabValuesApiTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.util; +package nl.jqno.equalsverifier.internal.instantiation.vintage; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderCreatorTest.java similarity index 96% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderCreatorTest.java index 45bba76bc..934543a92 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderCreatorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderCreatorTest.java @@ -1,10 +1,9 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation.vintage; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.*; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; import nl.jqno.equalsverifier.internal.reflection.TypeTag; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.testhelpers.FactoryCacheFactory; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java similarity index 96% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java index 03cde5c19..b51060445 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/instantiation/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java @@ -1,6 +1,6 @@ -package nl.jqno.equalsverifier.internal.reflection.instantiation; +package nl.jqno.equalsverifier.internal.instantiation.vintage; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultEquals; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -8,10 +8,9 @@ import static org.junit.jupiter.api.Assertions.fail; import java.util.*; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; import nl.jqno.equalsverifier.testhelpers.types.Point; import nl.jqno.equalsverifier.testhelpers.types.ThrowingInitializer; import org.junit.jupiter.api.BeforeEach; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java similarity index 90% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java index e0a2263fd..84d0d7e92 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/AbstractGenericFactoryTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static nl.jqno.equalsverifier.internal.reflection.Util.classes; import static nl.jqno.equalsverifier.internal.reflection.Util.objects; @@ -6,9 +6,9 @@ import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.ReflectionException; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FactoriesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FactoriesTest.java similarity index 75% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FactoriesTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FactoriesTest.java index 98337dd5a..17a113e7d 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FactoriesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FactoriesTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static nl.jqno.equalsverifier.internal.testhelpers.Util.coverThePrivateConstructor; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java similarity index 93% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java index af6902890..bb5d11a95 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/FallbackFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/FallbackFactoryTest.java @@ -1,6 +1,6 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultEquals; import static nl.jqno.equalsverifier.internal.testhelpers.Util.defaultHashCode; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -9,10 +9,10 @@ import java.util.LinkedHashSet; import nl.jqno.equalsverifier.internal.exceptions.RecursionException; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.Node; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.NodeArray; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/MapFactoryTest.java similarity index 93% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/MapFactoryTest.java index afd23e9d7..da1f220e7 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/MapFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/MapFactoryTest.java @@ -1,14 +1,14 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.testhelpers.types.TypeHelper.OneElementEnum; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java similarity index 89% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactoryTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java index 3adabc58f..7eec1bf30 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleFactoryTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java similarity index 93% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java index ff5f32d6e..7f7ba2b29 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/SimpleGenericFactoryTest.java @@ -1,13 +1,13 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.LinkedHashSet; import java.util.Optional; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.testhelpers.types.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java similarity index 86% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java index 06681caeb..ec5218593 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factoryproviders/JavaFxFactoryProviderTest.java @@ -1,16 +1,16 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders; +package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; import java.util.Map; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.PrefabValueFactory; +import nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factoryproviders.JavaFxFactoryProvider.PropertyFactory; import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.PrefabValueFactory; -import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factoryproviders.JavaFxFactoryProvider.PropertyFactory; import nl.jqno.equalsverifier.testhelpers.types.Point; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ClassAccessorTest.java similarity index 92% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ClassAccessorTest.java index 3fbfcb6cb..912287180 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/ClassAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/ClassAccessorTest.java @@ -1,15 +1,15 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.LinkedHashSet; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.testhelpers.types.PointContainer; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.TwoStepNodeA; import nl.jqno.equalsverifier.testhelpers.types.RecursiveTypeHelper.TwoStepNodeB; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/FieldModifierTest.java similarity index 95% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/FieldModifierTest.java index e0b2562b2..7746c1702 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FieldModifierTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/FieldModifierTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java similarity index 97% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java index a224280df..5ec8b577a 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorCopyingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorCopyingTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorScramblingTest.java similarity index 93% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorScramblingTest.java index a6775ab59..8a826a5d5 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorScramblingTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorScramblingTest.java @@ -1,6 +1,6 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; import static org.junit.jupiter.api.Assertions.*; import java.text.AttributedString; @@ -8,10 +8,10 @@ import java.util.LinkedHashSet; import java.util.List; import nl.jqno.equalsverifier.internal.exceptions.ModuleException; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; -import nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.JavaApiPrefabValues; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException; import nl.jqno.equalsverifier.testhelpers.types.Point; import nl.jqno.equalsverifier.testhelpers.types.Point3D; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorTest.java similarity index 91% rename from equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java rename to equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorTest.java index 85152215a..77a4a7c52 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/InPlaceObjectAccessorTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorTest.java @@ -1,4 +1,4 @@ -package nl.jqno.equalsverifier.internal.reflection.vintage; +package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java index 9f9871c6e..b8f31e641 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/FactoryCacheFactory.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.testhelpers; -import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; +import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.values; -import nl.jqno.equalsverifier.internal.reflection.FactoryCache; +import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; public final class FactoryCacheFactory { diff --git a/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java b/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java index 2da2a26f3..3c21c6a96 100644 --- a/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java +++ b/equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/helper/JarAsserter.java @@ -23,7 +23,7 @@ public JarAsserter(JarReader reader) { public void assertPresenceOfCoreClasses() { assertPresenceOf( EV + "/EqualsVerifier.class", - EV + "/internal/reflection/vintage/ClassAccessor.class", + EV + "/internal/reflection/ClassProbe.class", EV + "/internal/checkers/HierarchyChecker.class" ); }