Class ConfiguredEqualsVerifier

java.lang.Object
nl.jqno.equalsverifier.api.ConfiguredEqualsVerifier
All Implemented Interfaces:
EqualsVerifierApi<Void>

public final class ConfiguredEqualsVerifier extends Object implements EqualsVerifierApi<Void>
Keeps a re-usable configuration for EqualsVerifier.
Since:
3.0
  • Field Details

    • warningsToSuppress

      private final EnumSet<Warning> warningsToSuppress
    • modesToSet

      private final Set<Mode> modesToSet
    • userPrefabs

      private final UserPrefabValueCaches userPrefabs
    • usingGetClass

      private boolean usingGetClass
    • fieldnameToGetter

      private Function<String,String> fieldnameToGetter
    • objenesis

      private final org.objenesis.Objenesis objenesis
  • Constructor Details

    • ConfiguredEqualsVerifier

      public ConfiguredEqualsVerifier()
      Constructor.
      Since:
      3.0
    • ConfiguredEqualsVerifier

      private ConfiguredEqualsVerifier(EnumSet<Warning> warningsToSuppress, Set<Mode> modes, UserPrefabValueCaches userPrefabs, boolean usingGetClass, Function<String,String> fieldnameToGetter)
      Private constructor. For internal use only.
  • Method Details

    • copy

      public ConfiguredEqualsVerifier copy()
      Returns a copy of the configuration.
      Returns:
      a copy of the configuration.
      Since:
      3.2
    • suppress

      public ConfiguredEqualsVerifier suppress(Warning... warnings)
      Suppresses warnings given by EqualsVerifier. See Warning to see what warnings can be suppressed.
      Specified by:
      suppress in interface EqualsVerifierApi<Void>
      Parameters:
      warnings - A list of warnings to suppress in EqualsVerifier.
      Returns:
      this, for easy method chaining.
    • set

      public ConfiguredEqualsVerifier set(Mode... modes)
      Sets modes that influence how EqualsVerifier operates.}
      Specified by:
      set in interface EqualsVerifierApi<Void>
      Parameters:
      modes - A list of modes to influence how EqualsVerifier operates.
      Returns:
      this, for easy method chaining.
    • withPrefabValues

      public <S> ConfiguredEqualsVerifier withPrefabValues(Class<S> otherType, S red, S blue)
      Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself. This overload will attempt to copy red. If that fails, use the other overload.
      Specified by:
      withPrefabValues in interface EqualsVerifierApi<Void>
      Type Parameters:
      S - The class of the prefabricated values.
      Parameters:
      otherType - The class of the prefabricated values.
      red - An instance of S.
      blue - Another instance of S, not equal to red.
      Returns:
      this, for easy method chaining.
    • withPrefabValues

      public <S> ConfiguredEqualsVerifier withPrefabValues(Class<S> otherType, S red, S blue, S redCopy)
      Adds prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself.
      Specified by:
      withPrefabValues in interface EqualsVerifierApi<Void>
      Type Parameters:
      S - The class of the prefabricated values.
      Parameters:
      otherType - The class of the prefabricated values.
      red - An instance of S.
      blue - Another instance of S, not equal to red.
      redCopy - A copy of red.
      Returns:
      this, for easy method chaining.
    • withResettablePrefabValues

      public <S> ConfiguredEqualsVerifier withResettablePrefabValues(Class<S> otherType, Supplier<S> red, Supplier<S> blue)
      Adds Suppliers for resettable prefabricated values for instance fields of classes that EqualsVerifier cannot instantiate by itself. Resettable values are values that are created new every time a new instance of T is constructed within EqualsVerifier. This can be useful when T mutates its instances of S.
      Specified by:
      withResettablePrefabValues in interface EqualsVerifierApi<Void>
      Type Parameters:
      S - The class of the prefabricated values.
      Parameters:
      otherType - The class of the prefabricated values.
      red - An instance of S.
      blue - Another instance of S, not equal to red.
      Returns:
      this, for easy method chaining.
    • withGenericPrefabValues

      public <S> ConfiguredEqualsVerifier withGenericPrefabValues(Class<S> otherType, Func.Func1<?,S> factory)
      Adds a factory to generate prefabricated values for instance fields of classes with 1 generic type parameter that EqualsVerifier cannot instantiate by itself.
      Specified by:
      withGenericPrefabValues in interface EqualsVerifierApi<Void>
      Type Parameters:
      S - The class of the prefabricated values.
      Parameters:
      otherType - The class of the prefabricated values.
      factory - A factory to generate an instance of S, given a value of its generic type parameter.
      Returns:
      this, for easy method chaining.
    • withGenericPrefabValues

      public <S> ConfiguredEqualsVerifier withGenericPrefabValues(Class<S> otherType, Func.Func2<?,?,S> factory)
      Adds a factory to generate prefabricated values for instance fields of classes with 2 generic type parameters that EqualsVerifier cannot instantiate by itself.
      Specified by:
      withGenericPrefabValues in interface EqualsVerifierApi<Void>
      Type Parameters:
      S - The class of the prefabricated values.
      Parameters:
      otherType - The class of the prefabricated values.
      factory - A factory to generate an instance of S, given a value of each of its generic type parameters.
      Returns:
      this, for easy method chaining.
    • usingGetClass

      public ConfiguredEqualsVerifier usingGetClass()
      Signals that getClass is used in the implementation of the equals method, instead of an instanceof check.
      Specified by:
      usingGetClass in interface EqualsVerifierApi<Void>
      Returns:
      this, for easy method chaining.
      See Also:
    • withFieldnameToGetterConverter

      public ConfiguredEqualsVerifier withFieldnameToGetterConverter(Function<String,String> converter)
      Description copied from interface: EqualsVerifierApi
      Determines how a getter name can be derived from a field name. The default behavior is to uppercase the field's first letter and prepend 'get'. For instance, a field name 'employee' would correspond to getter name 'getEmployee'. This method can be used if your project has a different naming convention.
      Specified by:
      withFieldnameToGetterConverter in interface EqualsVerifierApi<Void>
      Parameters:
      converter - A function that converts from field name to getter name.
      Returns:
      this, for easy method chaining.
    • forClass

      public <T> SingleTypeEqualsVerifierApi<T> forClass(Class<T> type)
      Factory method. For general use.
      Type Parameters:
      T - The type.
      Parameters:
      type - The class for which the equals method should be tested.
      Returns:
      A fluent API for EqualsVerifier.
      Since:
      3.0
    • forExamples

      public <T> SingleTypeEqualsVerifierApi<T> forExamples(T red, T blue)
      Factory method. For general use.
      Type Parameters:
      T - The type.
      Parameters:
      red - An example of T.
      blue - An example of T where all fields have different values than red.
      Returns:
      A fluent API for EqualsVerifier.
      Since:
      4.0
    • forClasses

      public MultipleTypeEqualsVerifierApi forClasses(Iterable<Class<?>> classes)
      Factory method. For general use.
      Parameters:
      classes - An iterable containing the classes for which equals method should be tested.
      Returns:
      A fluent API for EqualsVerifier.
      Since:
      3.3
    • forClasses

      public MultipleTypeEqualsVerifierApi forClasses(Class<?> first, Class<?> second, Class<?>... more)
      Factory method. For general use.
      Parameters:
      first - A class for which the equals method should be tested.
      second - Another class for which the equals method should be tested.
      more - More classes for which the equals method should be tested.
      Returns:
      A fluent API for EqualsVerifier.
      Since:
      3.2
    • forPackage

      public MultipleTypeEqualsVerifierApi forPackage(String packageName, ScanOption... options)
      Factory method. For general use.

      Note that this operation may be slow. If the test is too slow, use forClasses(Class, Class, Class...) instead.

      Parameters:
      packageName - A package for which each class's equals should be tested.
      options - Modifications to the standard package scanning behaviour.
      Returns:
      A fluent API for EqualsVerifier.
      Since:
      3.2 / 3.19