java.lang.Object
nl.jqno.equalsverifier.internal.valueproviders.SubjectCreator<T>

public class SubjectCreator<T> extends Object
Creates a subject, i.e. an instance of the class that is currently being tested by EqualsVerifier.
  • Field Details

    • typeTag

      private final TypeTag typeTag
    • type

      private final Class<T> type
    • actualType

      private final Class<T> actualType
    • config

      private final Configuration<T> config
    • valueProvider

      private final ValueProvider valueProvider
    • objenesis

      private final org.objenesis.Objenesis objenesis
    • instantiator

      private final Instantiator<? extends T> 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

      public T 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 the ValueProvider.
      Returns:
      A plain instance.
    • withFieldDefaulted

      public T withFieldDefaulted(Field field)
      Creates a plain() 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

      public T 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

      public T 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 a plain() 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

      public T withAllFieldsDefaultedExcept(Field field)
      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 its plain() value.
      Parameters:
      field - The field that should not be defaulted.
      Returns:
      An instance with all fields defaulted except for field.
    • withFieldSetTo

      public T withFieldSetTo(Field field, Object value)
      Creates a plain() 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

      public T withFieldChanged(Field field)
      Creates a plain() 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

      public T withAllFieldsChanged()
      Creates a plain() instance, but with all fields set to another value.
      Returns:
      A plain instance with all fields changed.
    • withAllFieldsShallowlyChanged

      public T withAllFieldsShallowlyChanged()
      Creates a plain() instance, but with all fields that are declared in the current class set to another value. Fields coming from the superclasses get their plain() value.
      Returns:
      A plain instance with all non-inherited fields changed.
    • copyIntoSuperclass

      public Object 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 from original.
      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 from original. All fields declared in the subclass are set to their plain() 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

      private T createInstance(Map<Field,Object> givens)
    • determineValues

      private Map<Field,Object> determineValues(Map<Field,Object> givens)
    • empty

      private Map<Field,Object> empty()
    • with

      private Map<Field,Object> with(Field f, Object v)
    • fields

      private FieldIterable fields()
    • nonSuperFields

      private FieldIterable nonSuperFields()
    • valuesFor

      private Tuple<?> valuesFor(Field f)