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 void
assertSupported
(@NotNull Class<?> type) Verifies that the specified type is supported by this instance.protected void
Clears the cache of discovered generators.protected void
clearCache
(@NotNull Class<?> targetType) Removes the cache of discovered generator for the specified class.<T> T
defaultValue
(@NotNull Class<T> type) Returns the default value for the specified type.protected @NotNull Generator
discoverAnnotatedGenerator
(@NotNull Class<?> targetType) Finds a constructor or static method annotated withGeneratorMethod
in the specified target class.boolean
protected <T> ExecutableGenerator<T>
findDeclaredConstructor
(@NotNull Class<T> targetType) Finds a constructor annotated withGeneratorMethod
in the specified target class.protected <T> ExecutableGenerator<T>
findDeclaredMethod
(@NotNull Class<T> targetType) Finds a method annotated withGeneratorMethod
in the specified target class.protected Generator
getAnnotatedGenerator
(@NotNull Class<?> targetType) Returns annotated generator to be used to create random instances of the specified target class.int
hashCode()
<T> T
nullableDefaultValue
(@NotNull Class<T> type) Returns the default value for the specified type allowingnull
values.<T> T
nullableRandomValue
(@NotNull Class<T> type) Returns a random value of the specified type allowingnull
values.<T> T
randomValue
(@NotNull Class<T> type) Returns a random value of the specified type.boolean
Checks 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, wait
Methods 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 anIllegalArgumentException
exception 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:
defaultValue
in 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:Generator
Returns the default value for the specified type allowingnull
values.This method should return
null
except for native types.- Specified by:
nullableDefaultValue
in 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:
randomValue
in 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:Generator
Returns a random value of the specified type allowingnull
values.The returned value has a probability of be
null
except for native types. If notnull
behaves asrandomValue()
.- Specified by:
nullableRandomValue
in 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 withGeneratorMethod
in the specified target class.- Parameters:
targetType
- The target class- Returns:
- The found annotated generator, or
null
-
findDeclaredConstructor
Finds a constructor annotated withGeneratorMethod
in 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 withGeneratorMethod
in 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
-