Package dev.orne.test.rnd.params
Class ExecutableGenerator<T>
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.AbstractTypedGenerator<T>
dev.orne.test.rnd.params.ExecutableGenerator<T>
- Type Parameters:
T
- The type of generated values
- All Implemented Interfaces:
Generator
,TypedGenerator<T>
- Direct Known Subclasses:
ConstructorGenerator
,FactoryMethodGenerator
@API(status=EXPERIMENTAL,
since="0.1")
public abstract class ExecutableGenerator<T>
extends AbstractTypedGenerator<T>
Abstract generator that calls an executable 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
ExecutableGenerator
(@NotNull Class<T> type, @NotNull Executable executable, @NotNull TargetedGenerator<?>[] paramGenerators) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the default instance of the target type.boolean
protected abstract T
Calls the executable to create a new instance of the target type.@NotNull Executable
Returns the executable to call.@NotNull TargetedGenerator<?>[]
Returns the generator for the executable parameters.int
hashCode()
static <T> FactoryMethodGenerator<T>
Creates a new instance that will call the specified factory method.static <T> ConstructorGenerator<T>
of
(@NotNull Constructor<T> constructor) Creates a new instance that will call the specified constructor.Returns a random instance of the target type.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
-
ExecutableGenerator
protected ExecutableGenerator(@NotNull @NotNull Class<T> type, @NotNull @NotNull Executable executable, @NotNull @NotNull TargetedGenerator<?>[] paramGenerators) Creates a new instance.- Parameters:
type
- The type of generated valuesexecutable
- The executable to callparamGenerators
- The generator for the executable parameters
-
-
Method Details
-
of
Creates a new instance that will call the specified constructor.- Type Parameters:
T
- The type of the generated instance- Parameters:
constructor
- The constructor to call- Returns:
- The created generator
-
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 generated values- Parameters:
type
- The type of generated valuesmethod
- The factory method to call- Returns:
- The created generator
-
getExecutable
Returns the executable to call.- Returns:
- The executable to call
-
getParameterGenerators
Returns the generator for the executable parameters.- Returns:
- The generator for the executable parameters
-
defaultValue
Returns the default instance of the target type.- Returns:
- The default instance
-
randomValue
Returns a random instance of the target type.- Returns:
- A random instance
-
generate
Calls the executable to create a new instance of the target type.- Parameters:
params
- The parameters to use when calling the executable- Returns:
- The created instance
-
hashCode
public int hashCode()- Overrides:
hashCode
in classAbstractTypedGenerator<T>
-
equals
- Overrides:
equals
in classAbstractTypedGenerator<T>
-