Class MultipleTypeEqualsVerifierApi

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

public class MultipleTypeEqualsVerifierApi extends Object implements EqualsVerifierApi<Void>
Helps to construct an EqualsVerifier test for several types at once with a fluent API.
Since:
3.2
  • Field Details

  • Constructor Details

    • MultipleTypeEqualsVerifierApi

      public MultipleTypeEqualsVerifierApi(List<Class<?>> types, ConfiguredEqualsVerifier ev)
      Constructor.
      Parameters:
      types - The classes for which the equals method should be tested.
      ev - A configuration that can be used for each class.
      Since:
      3.2
  • Method Details

    • suppress

      public MultipleTypeEqualsVerifierApi 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 MultipleTypeEqualsVerifierApi 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> MultipleTypeEqualsVerifierApi 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> MultipleTypeEqualsVerifierApi 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> MultipleTypeEqualsVerifierApi 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> MultipleTypeEqualsVerifierApi 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> MultipleTypeEqualsVerifierApi 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 MultipleTypeEqualsVerifierApi 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 MultipleTypeEqualsVerifierApi withFieldnameToGetterConverter(Function<String,String> converter)
      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.
    • verify

      public void verify()
      Performs the verification of the contracts for equals and hashCode and throws an AssertionError if there is a problem.
      Throws:
      AssertionError - If one of the contracts is not met, or if EqualsVerifier's preconditions do not hold.
      Since:
      0.1
    • report

      public List<EqualsVerifierReport> report()
      Performs the verifications of the contracts for equals and hashCode and returns a List of EqualsVerifierReport with the results of the verifications.
      Returns:
      A List of EqualsVerifierReport that indicates whether the contracts are met and whether EqualsVerifier's preconditions hold.
      Since:
      3.0