Module nl.jqno.equalsverifier
Class SubjectCreator<T>
java.lang.Object
nl.jqno.equalsverifier.internal.valueproviders.SubjectCreator<T>
Creates a subject, i.e. an instance of the class that is currently being tested by EqualsVerifier.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configuration<T> private final booleanprivate final Instantiator<? extends T> private final org.objenesis.Objenesisprivate final TypeTagprivate final ValueProvider -
Constructor Summary
ConstructorsConstructorDescriptionSubjectCreator(Configuration<T> config, ValueProvider valueProvider, org.objenesis.Objenesis objenesis, boolean forceFinalMeansFinal) Constructor. -
Method Summary
Modifier and TypeMethodDescription<S extends T>
ScopyIntoSubclass(T original, Class<S> subType, InstanceFactory<S> subclassFactory, String methodName) Creates a new instance of the given subclass of the current class, with all fields that also exist in the current class set to the same value as their counterparts fromoriginal.copyIntoSuperclass(T original, InstanceFactory<?> superclassFactory) Creates a new instance of the superclass of the current class, with all fields that exist within that superclass set to the same value as their counterparts fromoriginal.private TcreateInstance(Map<Field, Object> givens) determineValues(Map<Field, Object> givens) empty()private FieldIterablefields()private FieldIterableplain()Creates an instance with all values set with prefab values assigned to their respective field names or types, or, if no prefab values are given, values created by theValueProvider.private Tuple<?> Creates aplain()instance, but with all fields set to another value.Creates an instance with all values set to their type's default value: null for object references, 0 for numbers, false for booleans.Creates an instance with all values set to their type's default value: null for object references, 0 for numbers, false for booleans; except for the given field which is set to itsplain()value.Creates aplain()instance, but with all fields that are declared in the current class set to another value.withAllMatchingFieldsDefaulted(Predicate<Field> predicate) Creates an instance with all fields matching the predicate set to their type's default value: null for object references, 0 for numbers, false for booleans, except for fields that don't match the predicate, which will get aplain()value.withFieldChanged(Field field) Creates aplain()instance, but with the given field set to another value.withFieldDefaulted(Field field) Creates aplain()instance, but with the given field set to its type's default value: null for object references, 0 for numbers, false for booleans.withFieldSetTo(Field field, Object value) Creates aplain()instance, but with the given field set to the given value.
-
Field Details
-
typeTag
-
type
-
actualType
-
config
-
valueProvider
-
objenesis
private final org.objenesis.Objenesis objenesis -
instantiator
-
forceFinalMeansFinal
private final boolean forceFinalMeansFinal
-
-
Constructor Details
-
SubjectCreator
public SubjectCreator(Configuration<T> config, ValueProvider valueProvider, org.objenesis.Objenesis objenesis, boolean forceFinalMeansFinal) Constructor.- Parameters:
config- A configuration object.valueProvider- To provide values for the fields of the subject.objenesis- Needed by InstanceCreator to instantiate non-record classes.forceFinalMeansFinal- Force "final means final" (JEP 500) mode.
-
-
Method Details
-
plain
Creates an instance with all values set with prefab values assigned to their respective field names or types, or, if no prefab values are given, values created by theValueProvider.- Returns:
- A plain instance.
-
withFieldDefaulted
Creates aplain()instance, but with the given field set to its type's default value: null for object references, 0 for numbers, false for booleans.- Parameters:
field- The field to default.- Returns:
- A plain instance with a field defaulted.
-
withAllFieldsDefaulted
Creates an instance with all values set to their type's default value: null for object references, 0 for numbers, false for booleans.- Returns:
- An instance with all fields defaulted.
-
withAllMatchingFieldsDefaulted
Creates an instance with all fields matching the predicate set to their type's default value: null for object references, 0 for numbers, false for booleans, except for fields that don't match the predicate, which will get aplain()value.- Parameters:
predicate- A predicate to determine if the field should be defaulted.- Returns:
- An instance with all matching fields defaulted and all non-matching fields set to their
plain()value.
-
withAllFieldsDefaultedExcept
Creates an instance with all values set to their type's default value: null for object references, 0 for numbers, false for booleans; except for the given field which is set to itsplain()value.- Parameters:
field- The field that should not be defaulted.- Returns:
- An instance with all fields defaulted except for
field.
-
withFieldSetTo
Creates aplain()instance, but with the given field set to the given value.- Parameters:
field- The field to assign the given value.value- The value to assign to the given field.- Returns:
- A plain instance with one field assigned the given value.
-
withFieldChanged
Creates aplain()instance, but with the given field set to another value.- Parameters:
field- The field to change.- Returns:
- A plain instance with a field changed.
-
withAllFieldsChanged
Creates aplain()instance, but with all fields set to another value.- Returns:
- A plain instance with all fields changed.
-
withAllFieldsShallowlyChanged
Creates aplain()instance, but with all fields that are declared in the current class set to another value. Fields coming from the superclasses get theirplain()value.- Returns:
- A plain instance with all non-inherited fields changed.
-
copyIntoSuperclass
Creates a new instance of the superclass of the current class, with all fields that exist within that superclass set to the same value as their counterparts fromoriginal.- Parameters:
original- The instance to copy.superclassFactory- A factory to instantiate the supertype. May be null.- Returns:
- An instance of the givenoriginal's superclass, but otherwise a copy of the original.
-
copyIntoSubclass
public <S extends T> S copyIntoSubclass(T original, Class<S> subType, InstanceFactory<S> subclassFactory, String methodName) Creates a new instance of the given subclass of the current class, with all fields that also exist in the current class set to the same value as their counterparts fromoriginal. All fields declared in the subclass are set to theirplain()values.- Type Parameters:
S- A subtype of original's type.- Parameters:
original- The instance to copy.subType- A subtype of original's type. May be null if subclassFactory is not.subclassFactory- A factory to instantiate the subtype. May be null if subclass is not.methodName- The name of the method whose overload we need to call to provide a factory. Used in the error message.- Returns:
- An instance of the given subType, but otherwise a copy of the given original.
-
createInstance
-
determineValues
-
empty
-
with
-
fields
-
nonSuperFields
-
valuesFor
-