Interface ObjectProvider<T>

Type Parameters:
T - the type being tested.
All Known Subinterfaces:
CollectionProvider<E,I>, DoubleNumberProvider<T>, IntegerNumberProvider<T>, NumberProvider<T>
All Known Implementing Classes:
DoubleProvider, FloatProvider, FunctionalCollectionProvider, FunctionalProvider, IntegerProvider, LongProvider, ShortProvider, StringProvider

public interface ObjectProvider<T>
Provides Object instances for use in testing.
Since:
1.0.0
Author:
evanbergstrom
Implementation Requirements:

Implementations of this interface must provide two methods:

  • Method Details

    • defaultInstance

      @NotNull T defaultInstance()
      Creates a single instance of class being tested using the default constructor.
      Returns:
      an instance of class.
    • createInstance

      @NotNull T createInstance(int seed)
      Creates a single instance of class being tested based upon an integer seed value.
      Parameters:
      seed - an integer seed to use to create and instance of the class.
      Returns:
      an instance of class.
      Implementation Requirements:
      Calls to this method with different seed values should return objects with different values.
    • copyInstance

      @NotNull T copyInstance(@NotNull T other)
      Copies an instance of the class being tested. The copy will satisfy equality semantics with the original instance being copied.
      Parameters:
      other - the instance to copy.
      Returns:
      a copy of the instance.
      Throws:
      NullPointerException - if the argument is a null value.
      Implementation Requirements:
      The copy of the object should satisfy the equality semantics with the original object (i.e. for o1 and o2, o1.equals(o2) should return true and o1.hashCode() == o2.hashCode() should evaluate to true.
      Complexity:
      constant time.
    • createInstance

      @NotNull default T createInstance()
      Creates a single instance of class being tested.
      Returns:
      an instance of class.
      Implementation Requirements:
      Each call must return a valid object instance, but there is no requirement that successive calls to the method return instances that satisfy equality semantics, or that they be unique. The default implementation is the same as calling createInstance(0).
      Complexity:
      constant time.
    • uniqueSizeLimit

      default int uniqueSizeLimit()
      Returns the number of unique instances of the class that can be created.
      Returns:
      the maximum number of unique instances that can be created.
      Implementation Requirements:
      The default implementation returns Integer.MAX_VALUE. This should be overridden for enumerations or any classes that have a bounded number of unique values.
      Complexity:
      constant time.
    • equalInstanceSupplier

      @NotNull default @NotNull Supplier<T> equalInstanceSupplier()
      Creates a Supplier that will generate equal instances of the class being provided.
      Returns:
      A supplier the returns instances of the class that are equal.
      Implementation Requirements:
      The supplier should produce equal instances of the class for each the call to get().
      Implementation Note:
      The default implementation will call createInstance(0) to create each instance.
      Complexity:
      constant time.
    • uniqueInstanceSupplier

      @NotNull default @NotNull Supplier<T> uniqueInstanceSupplier()
      Creates a Supplier that will generate unique instances of the class being provided. Uniqueness will be guaranteed for all instances created by this supplier. Instances may not be unique from multiple suppliers.
      Returns:
      A supplier the returns instances of the class that are unique.
      Throws:
      IllegalStateException - if get is called on the supplier more than uniqueSizeLimit times.
      Implementation Requirements:
      The supplier should produce unique instances of the class for each the call to get(), and it should be callable a number of times up to the value returned by uniqueSizeLimit(). If it is called more that uniqueSizeLimit times, it should throw an IllegalStateException.
      Implementation Note:
      The default implementation will call createInstance(int) with successive integers starting with 0.
      Complexity:
      constant time.
    • uniqueInstanceSupplier

      @NotNull default @NotNull Supplier<T> uniqueInstanceSupplier(int seed)
      Creates a Supplier that will generate unique instances of the class being provided. Uniqueness will be guaranteed for all instances created by this supplier. Instances may not be unique from multiple suppliers.
      Parameters:
      seed - the seed to use to create elements.
      Returns:
      A supplier the returns instances of the class that are unique.
      Throws:
      IllegalStateException - if get is called on the supplier more than uniqueSizeLimit times.
      Implementation Requirements:
      The supplier should produce unique instances of the class for each the call to get(), and it should be callable a number of times up to the value returned by uniqueSizeLimit(). If it is called more that uniqueSizeLimit times, it should throw an IllegalStateException.
      Implementation Note:

      The default implementation will call createInstance(int) with successive integers starting with 0.

      param seed the initial seed to use to crate the first instance.

      Complexity:
      constant time.
    • randomInstanceSupplier

      @NotNull default @NotNull Supplier<T> randomInstanceSupplier()
      Creates a Supplier that will generate random instances of the class being provided. This should be used where the individual values of the instances is not important, such here we are testing for performance of some part of the implementation, but where creating instances with successive seed values might bias the algorithm (e.g. hash code distribution). In most cases, the methods uniqueInstanceSupplier() should be preferred so that the test data is stable across executions.
      Returns:
      A supplier the returns random instances of the class.
      Implementation Requirements:
      The supplier should produce random instances of the class for each the call to get(). The order of the objects created should be stable across instances of the supplier.
      Implementation Note:
      The default implementation will call createInstance(int) with random integers between 0 and the value returned by upperUniqueLimit().
    • createEqualObjects

      @NotNull default @NotNull List<T> createEqualObjects(int size)
      Creates s list of instances that are equal to each other.
      Parameters:
      size - The number of equal instances to create.
      Returns:
      A list of equal instances.
      Complexity:
      linear time based upon the number of instance (the size argument).
    • createUniqueInstances

      @NotNull default @NotNull List<T> createUniqueInstances(int size)
      Creates multiple instances of class being tested with unique values.
      Parameters:
      size - the number of instances to create.
      Returns:
      a list of the created instances.
      Throws:
      IllegalArgumentException - if size is greater than uniqueSizeLimit()
      Complexity:
      linear time based upon the number of instance (the size argument).
    • createUniqueInstances

      @NotNull default @NotNull List<T> createUniqueInstances(int size, int seed)
      Creates multiple instances of class being tested with unique values.
      Parameters:
      size - the number of instances to create.
      seed - the seed to use to create elements.
      Returns:
      a list of the created instances.
      Throws:
      IllegalArgumentException - if size is greater than uniqueSizeLimit()
      Complexity:
      linear time based upon the number of instance (the size argument).
    • createRandoInstances

      @NotNull default @NotNull List<T> createRandoInstances(int size)
      Creates multiple instances of class being tested with random values. This should be used where the individual values of the instances is not important, such as here we are testing for performance of some part of the implementation (e.g. hash code distribution). In most cases, the method createUniqueInstances(int) should be preferred so that the test data is stable across executions.
      Parameters:
      size - the number of instances to create.
      Returns:
      a list of the created instances.
      Complexity:
      linear time based upon the number of instance (the size argument).