Package dev.orne.test.rnd.params
Class FactoryMethodGenerator<T>
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.AbstractTypedGenerator<T>
dev.orne.test.rnd.params.ExecutableGenerator<T>
dev.orne.test.rnd.params.FactoryMethodGenerator<T>
- Type Parameters:
T
- The type of generated values
- All Implemented Interfaces:
Generator
,TypedGenerator<T>
@API(status=EXPERIMENTAL,
since="0.1")
public class FactoryMethodGenerator<T>
extends ExecutableGenerator<T>
Generator that calls a static factory method with generated parameters to
generate values of the target type.
- Since:
- 0.1
- Version:
- 1.0, 2022-12
- Author:
- (w) Iker Hernaez
-
Field Summary
Fields inherited from class dev.orne.test.rnd.AbstractGenerator
DEFAULT_NULL_PROBABILITY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
FactoryMethodGenerator
(@NotNull Class<T> type, @NotNull Method method, @NotNull TargetedGenerator<?>[] paramGenerators) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected T
Calls the executable to create a new instance of the target type.Returns the executable to call.static <T> FactoryMethodGenerator<T>
Creates a new instance that will call the specified factory method.Methods inherited from class dev.orne.test.rnd.params.ExecutableGenerator
defaultValue, equals, getParameterGenerators, hashCode, of, randomValue
Methods inherited from class dev.orne.test.rnd.AbstractTypedGenerator
defaultValue, getValueType, nullableDefaultValue, nullableRandomValue, randomValue, supports
Methods inherited from class dev.orne.test.rnd.AbstractGenerator
assertSupported, getNullProbability, nullableDefaultValue, nullableRandomValue, randomNull, setNullProbability, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.orne.test.rnd.Generator
asParameterizable, getPriority, nullableDefaultValue, nullableRandomValue
-
Constructor Details
-
FactoryMethodGenerator
protected FactoryMethodGenerator(@NotNull @NotNull Class<T> type, @NotNull @NotNull Method method, @NotNull @NotNull TargetedGenerator<?>[] paramGenerators) Creates a new instance.- Parameters:
type
- The type of generated valuesmethod
- The factory method to callparamGenerators
- The parameter generators
-
-
Method Details
-
of
public static <T> FactoryMethodGenerator<T> of(@NotNull @NotNull Class<T> type, @NotNull @NotNull Method method) Creates a new instance that will call the specified factory method.- Type Parameters:
T
- The type of the generated instance- Parameters:
type
- The type of generated valuesmethod
- The factory method to call- Returns:
- The created generator
-
getExecutable
Returns the executable to call.- Overrides:
getExecutable
in classExecutableGenerator<T>
- Returns:
- The executable to call
-
generate
Calls the executable to create a new instance of the target type.- Specified by:
generate
in classExecutableGenerator<T>
- Parameters:
params
- The parameters to use when calling the executable- Returns:
- The created instance
-