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 Summary
Modifier and TypeMethodDescriptioncopyInstance
(T other) Copies an instance of the class being tested.createEqualObjects
(int size) Creates s list of instances that are equal to each other.default T
Creates a single instance of class being tested.createInstance
(int seed) Creates a single instance of class being tested based upon an integer seed value.createRandoInstances
(int size) Creates multiple instances of class being tested with random values.createUniqueInstances
(int size) Creates multiple instances of class being tested with unique values.createUniqueInstances
(int size, int seed) Creates multiple instances of class being tested with unique values.Creates a single instance of class being tested using the default constructor.Creates aSupplier
that will generate equal instances of the class being provided.Creates aSupplier
that will generate random instances of the class being provided.Creates aSupplier
that will generate unique instances of the class being provided.uniqueInstanceSupplier
(int seed) Creates aSupplier
that will generate unique instances of the class being provided.default int
Returns the number of unique instances of the class that can be created.
-
Method Details
-
defaultInstance
Creates a single instance of class being tested using the default constructor.- Returns:
- an instance of class.
-
createInstance
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
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
ando2
,o1.equals(o2)
should returntrue
ando1.hashCode() == o2.hashCode()
should evaluate totrue
. - Complexity:
- constant time.
-
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
Creates aSupplier
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
Creates aSupplier
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
- ifget
is called on the supplier more thanuniqueSizeLimit
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 byuniqueSizeLimit()
. If it is called more thatuniqueSizeLimit
times, it should throw anIllegalStateException
. - Implementation Note:
- The default implementation will call
createInstance(int)
with successive integers starting with 0. - Complexity:
- constant time.
-
uniqueInstanceSupplier
Creates aSupplier
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
- ifget
is called on the supplier more thanuniqueSizeLimit
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 byuniqueSizeLimit()
. If it is called more thatuniqueSizeLimit
times, it should throw anIllegalStateException
. - 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
Creates aSupplier
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 methodsuniqueInstanceSupplier()
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 byupperUniqueLimit()
.
-
createEqualObjects
-
createUniqueInstances
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 thanuniqueSizeLimit()
- Complexity:
- linear time based upon the number of instance (the
size
argument).
-
createUniqueInstances
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 thanuniqueSizeLimit()
- Complexity:
- linear time based upon the number of instance (the
size
argument).
-
createRandoInstances
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 methodcreateUniqueInstances(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).
-