Class FunctionalProvider<T>

java.lang.Object
org.soliscode.test.provider.FunctionalProvider<T>
Type Parameters:
T - the provided type.
All Implemented Interfaces:
ObjectProvider<T>
Direct Known Subclasses:
FunctionalCollectionProvider

public class FunctionalProvider<T> extends Object implements ObjectProvider<T>

An provider that uses a set of functions to construct instances of the class. There are two elements required to create a collection provider using this class:

  • Default constructor function
  • Copy constructor function

For example, to create a provider for Integer objects:

    Provider<Integer> provider = FunctionalProvider<Integer>(Integer;:new, Integer::new);
Since:
1.0
Author:
evanbergstrom
  • Constructor Details

    • FunctionalProvider

      public FunctionalProvider(@NotNull @NotNull Supplier<T> defaultConstructor, @NotNull @NotNull Function<T,T> copyConstructor, @NotNull @NotNull Function<Integer,T> seedConstructor)
      Create an instance of this collection provider that uses the methods and element provider specified in the arguments for its implementation.
      Parameters:
      defaultConstructor - the supplier to use to create default instances of the collection.
      copyConstructor - the function to use to create a copy of the collection.
      seedConstructor - the function to use to create an instance of the class from an integer seed value.
      Throws:
      NullPointerException - if any of the arguments are null
    • FunctionalProvider

      protected FunctionalProvider(@NotNull @NotNull Supplier<T> defaultConstructor, @NotNull @NotNull Function<T,T> copyConstructor)
      Create an instance of this collection provider that uses the methods and element provider specified in the arguments for its implementation.
      Parameters:
      defaultConstructor - the supplier to use to create default instances of the collection.
      copyConstructor - the function to use to create a copy of the collection.
      Throws:
      NullPointerException - if any of the arguments are null
  • Method Details

    • defaultInstance

      @NotNull public T defaultInstance()
      Description copied from interface: ObjectProvider
      Creates a single instance of class being tested using the default constructor.
      Specified by:
      defaultInstance in interface ObjectProvider<T>
      Returns:
      an instance of class.
    • copyInstance

      @NotNull public T copyInstance(@NotNull T o)
      Description copied from interface: ObjectProvider
      Copies an instance of the class being tested. The copy will satisfy equality semantics with the original instance being copied.
      Specified by:
      copyInstance in interface ObjectProvider<T>
      Parameters:
      o - the instance to copy.
      Returns:
      a copy of the instance.
    • createInstance

      @NotNull public T createInstance(int seed)
      Description copied from interface: ObjectProvider
      Creates a single instance of class being tested based upon an integer seed value.
      Specified by:
      createInstance in interface ObjectProvider<T>
      Parameters:
      seed - an integer seed to use to create and instance of the class.
      Returns:
      an instance of class.