Skip to content

Commit

Permalink
Merge pull request #1028 from jqno/revert-valueproviders
Browse files Browse the repository at this point in the history
Revert valueproviders
  • Loading branch information
jqno authored Dec 6, 2024
2 parents 489677a + 92025ef commit 509239e
Show file tree
Hide file tree
Showing 99 changed files with 1,107 additions and 1,467 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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.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.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;
Expand All @@ -19,26 +18,24 @@ public class RecordFallbackFactoryTest {

private FallbackFactory<?> factory;
private VintageValueProvider valueProvider;
private Attributes attributes;
private LinkedHashSet<TypeTag> 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
public void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenticalInRedAndRedCopy() {
Tuple<?> tuple = factory.createValues(
new TypeTag(GenericRecordContainer.class),
valueProvider,
attributes
typeStack
);

assertEquals(tuple.getRed(), tuple.getRedCopy());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection.vintage.mutation;
package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
package nl.jqno.equalsverifier.internal.reflection.vintage.mutation;
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 nl.jqno.equalsverifier.internal.reflection.JavaApiPrefabValues;
import java.util.LinkedHashSet;
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.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 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<TypeTag> 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
Expand Down Expand Up @@ -67,7 +57,7 @@ private <T> RecordObjectAccessor<T> create(T object) {
}

private ObjectAccessor<Object> 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) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package nl.jqno.equalsverifier.internal.reflection.vintage.mutation;
package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection;

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.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.CachedValueProvider;
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes;
import nl.jqno.equalsverifier.internal.reflection.vintage.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;
import org.objenesis.ObjenesisStd;

public class RecordObjectAccessorTest {

private static final Attributes EMPTY_ATTRIBUTES = Attributes.unlabeled();
private static final LinkedHashSet<TypeTag> EMPTY_TYPE_STACK = new LinkedHashSet<>();
private Objenesis objenesis;
private Object recordInstance;

Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.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.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;
Expand All @@ -20,26 +19,24 @@ public class SealedTypesFallbackFactoryTest {

private FallbackFactory<?> factory;
private VintageValueProvider valueProvider;
private Attributes attributes;
private LinkedHashSet<TypeTag> 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
public void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsField() {
Tuple<?> tuple = factory.createValues(
new TypeTag(SealedParentWithFinalChild.class),
valueProvider,
attributes
typeStack
);

assertEquals(tuple.getRed(), tuple.getRedCopy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import nl.jqno.equalsverifier.api.EqualsVerifierApi;
import nl.jqno.equalsverifier.api.MultipleTypeEqualsVerifierApi;
import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi;
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.reflection.vintage.FactoryCache;
import nl.jqno.equalsverifier.internal.reflection.vintage.PrefabValuesApi;
import nl.jqno.equalsverifier.internal.util.ListBuilders;
import nl.jqno.equalsverifier.internal.util.Validations;
import org.objenesis.Objenesis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
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.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;
import org.objenesis.Objenesis;
Expand All @@ -32,14 +32,14 @@ public class SingleTypeEqualsVerifierApi<T> implements EqualsVerifierApi<T> {
private boolean hasRedefinedSuperclass = false;
private Class<? extends T> redefinedSubclass = null;
private FactoryCache factoryCache = new FactoryCache();
private FieldCache fieldCache = new FieldCache();
private CachedHashCodeInitializer<T> cachedHashCodeInitializer =
CachedHashCodeInitializer.passthrough();
private Function<String, String> fieldnameToGetter = null;
private Set<String> allExcludedFields = new HashSet<>();
private Set<String> allIncludedFields = new HashSet<>();
private Set<String> nonnullFields = new HashSet<>();
private Set<String> ignoredAnnotationClassNames = new HashSet<>();
private Set<String> prefabbedFieldNames = new HashSet<>();
private List<T> equalExamples = new ArrayList<>();
private List<T> unequalExamples = new ArrayList<>();
private final Objenesis objenesis;
Expand Down Expand Up @@ -76,10 +76,6 @@ public SingleTypeEqualsVerifierApi(Class<T> 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<T> type,
EnumSet<Warning> warningsToSuppress,
Expand All @@ -90,7 +86,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;
}
Expand Down Expand Up @@ -148,15 +144,7 @@ public <S> SingleTypeEqualsVerifierApi<T> 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;
}
Expand Down Expand Up @@ -444,7 +432,7 @@ private void performVerification() {
Validations.validateClassCanBeVerified(type);

Configuration<T> config = buildConfig();
Context<T> context = new Context<>(config, factoryCache, objenesis);
Context<T> context = new Context<>(config, factoryCache, fieldCache, objenesis);
Validations.validateProcessedAnnotations(
type,
config.getAnnotationCache(),
Expand All @@ -463,7 +451,7 @@ private Configuration<T> buildConfig() {
allExcludedFields,
allIncludedFields,
nonnullFields,
prefabbedFieldNames,
fieldCache.getFieldNames(),
cachedHashCodeInitializer,
hasRedefinedSuperclass,
redefinedSubclass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +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.reflection.instantiation.ValueProvider.Attributes;
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<T> implements Checker {
Expand Down Expand Up @@ -64,7 +60,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();
Expand All @@ -73,9 +69,9 @@ private void checkAbstractDelegationInFields() {
}
}

private <U> Tuple<U> safelyGetTuple(TypeTag tag, String fieldName) {
private <U> Tuple<U> safelyGetTuple(TypeTag tag) {
try {
return valueProvider.provideOrThrow(tag, Attributes.labeled(fieldName));
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> implements Checker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> implements Checker {
Expand Down
Loading

0 comments on commit 509239e

Please sign in to comment.