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
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 Summary
ConstructorsModifierConstructorDescriptionprotected
Create an instance of this collection provider that uses the methods and element provider specified in the arguments for its implementation.FunctionalProvider
(@NotNull Supplier<T> defaultConstructor, @NotNull Function<T, T> copyConstructor, @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. -
Method Summary
Modifier and TypeMethodDescriptioncopyInstance
(T o) Copies an instance of the class being tested.createInstance
(int seed) Creates a single instance of class being tested based upon an integer seed value.Creates a single instance of class being tested using the default constructor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.soliscode.test.provider.ObjectProvider
createEqualObjects, createInstance, createRandoInstances, createUniqueInstances, createUniqueInstances, equalInstanceSupplier, randomInstanceSupplier, uniqueInstanceSupplier, uniqueInstanceSupplier, uniqueSizeLimit
-
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 arenull
-
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 arenull
-
-
Method Details
-
defaultInstance
Description copied from interface:ObjectProvider
Creates a single instance of class being tested using the default constructor.- Specified by:
defaultInstance
in interfaceObjectProvider<T>
- Returns:
- an instance of class.
-
copyInstance
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 interfaceObjectProvider<T>
- Parameters:
o
- the instance to copy.- Returns:
- a copy of the instance.
-
createInstance
Description copied from interface:ObjectProvider
Creates a single instance of class being tested based upon an integer seed value.- Specified by:
createInstance
in interfaceObjectProvider<T>
- Parameters:
seed
- an integer seed to use to create and instance of the class.- Returns:
- an instance of class.
-