Package dev.orne.test.rnd.generators
Class AnnotatedMethodGenerator
java.lang.Object
dev.orne.test.rnd.generators.AnnotatedMethodGenerator
- All Implemented Interfaces:
Generator
@API(status=EXPERIMENTAL,
since="0.1")
@Priority(-500)
public class AnnotatedMethodGenerator
extends Object
implements Generator
Generator of beans annotated with
Currency.- Since:
- 0.1
- Version:
- 1.0, 2022-12
- Author:
- (w) Iker Hernaez
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertSupported(@NotNull Class<?> type) Verifies that the specified type is supported by this instance.protected voidClears the cache of discovered generators.protected voidclearCache(@NotNull Class<?> targetType) Removes the cache of discovered generator for the specified class.<T> TdefaultValue(@NotNull Class<T> type) Returns the default value for the specified type.protected @NotNull GeneratordiscoverAnnotatedGenerator(@NotNull Class<?> targetType) Finds a constructor or static method annotated withGeneratorMethodin the specified target class.booleanprotected <T> ExecutableGenerator<T>findDeclaredConstructor(@NotNull Class<T> targetType) Finds a constructor annotated withGeneratorMethodin the specified target class.protected <T> ExecutableGenerator<T>findDeclaredMethod(@NotNull Class<T> targetType) Finds a method annotated withGeneratorMethodin the specified target class.protected GeneratorgetAnnotatedGenerator(@NotNull Class<?> targetType) Returns annotated generator to be used to create random instances of the specified target class.inthashCode()<T> TnullableDefaultValue(@NotNull Class<T> type) Returns the default value for the specified type allowingnullvalues.<T> TnullableRandomValue(@NotNull Class<T> type) Returns a random value of the specified type allowingnullvalues.<T> TrandomValue(@NotNull Class<T> type) Returns a random value of the specified type.booleanChecks if values of the specified type can be generated by this instance.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.orne.test.rnd.Generator
asParameterizable, getPriority
-
Constructor Details
-
AnnotatedMethodGenerator
public AnnotatedMethodGenerator()Creates a new instance.
-
-
Method Details
-
supports
Checks if values of the specified type can be generated by this instance. -
assertSupported
Verifies that the specified type is supported by this instance. If test fails throws anIllegalArgumentExceptionexception as documented indefaultValue(Class),nullableDefaultValue(Class),randomValue(Class)andnullableRandomValue(Class).- Parameters:
type- The requested value type.- Throws:
UnsupportedValueTypeException- If the specified type is not supported.
-
defaultValue
Returns the default value for the specified type.- Specified by:
defaultValuein interfaceGenerator- Type Parameters:
T- The requested value type.- Parameters:
type- The requested value type.- Returns:
- The default value for the specified type.
-
nullableDefaultValue
Description copied from interface:GeneratorReturns the default value for the specified type allowingnullvalues.This method should return
nullexcept for native types.- Specified by:
nullableDefaultValuein interfaceGenerator- Type Parameters:
T- The requested value type.- Parameters:
type- The requested value type.- Returns:
- The nullable default value for the specified type.
-
randomValue
Returns a random value of the specified type.- Specified by:
randomValuein interfaceGenerator- Type Parameters:
T- The requested value type.- Parameters:
type- The requested value type.- Returns:
- A random value for the specified type.
-
nullableRandomValue
Description copied from interface:GeneratorReturns a random value of the specified type allowingnullvalues.The returned value has a probability of be
nullexcept for native types. If notnullbehaves asrandomValue().- Specified by:
nullableRandomValuein interfaceGenerator- Type Parameters:
T- The requested value type.- Parameters:
type- The requested value type.- Returns:
- A random nullable value for the specified type.
- See Also:
-
getAnnotatedGenerator
Returns annotated generator to be used to create random instances of the specified target class.This method caches the generator (found or not) for further calls.
- Parameters:
targetType- The target class- Returns:
- The found annotated generator, or
null
-
clearCache
protected void clearCache()Clears the cache of discovered generators. -
clearCache
Removes the cache of discovered generator for the specified class.- Parameters:
targetType- The target class
-
discoverAnnotatedGenerator
@NotNull protected @NotNull Generator discoverAnnotatedGenerator(@NotNull @NotNull Class<?> targetType) Finds a constructor or static method annotated withGeneratorMethodin the specified target class.- Parameters:
targetType- The target class- Returns:
- The found annotated generator, or
null
-
findDeclaredConstructor
Finds a constructor annotated withGeneratorMethodin the specified target class. The method must be public and return an instance of the class.- Type Parameters:
T- The target class- Parameters:
targetType- The target class- Returns:
- The found annotated generator, or
null
-
findDeclaredMethod
Finds a method annotated withGeneratorMethodin the specified target class. The method must be public, static and return an instance of the class.- Type Parameters:
T- The target class- Parameters:
targetType- The target class- Returns:
- The found annotated generator, or
null
-
hashCode
public int hashCode() -
equals
-