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 Details

    • AnnotatedMethodGenerator

      public AnnotatedMethodGenerator()
      Creates a new instance.
  • Method Details

    • supports

      public boolean supports(@NotNull @NotNull Class<?> type)
      Checks if values of the specified type can be generated by this instance.
      Specified by:
      supports in interface Generator
      Parameters:
      type - The type to check.
      Returns:
      If values of the specified type can be generated.
    • assertSupported

      protected void assertSupported(@NotNull @NotNull Class<?> type)
      Verifies that the specified type is supported by this instance. If test fails throws an IllegalArgumentException exception as documented in defaultValue(Class), nullableDefaultValue(Class), randomValue(Class) and nullableRandomValue(Class).
      Parameters:
      type - The requested value type.
      Throws:
      UnsupportedValueTypeException - If the specified type is not supported.
    • defaultValue

      @NotNull public <T> T defaultValue(@NotNull @NotNull Class<T> type)
      Returns the default value for the specified type.
      Specified by:
      defaultValue in interface Generator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      The default value for the specified type.
    • nullableDefaultValue

      public <T> T nullableDefaultValue(@NotNull @NotNull Class<T> type)
      Description copied from interface: Generator
      Returns the default value for the specified type allowing null values.

      This method should return null except for native types.

      Specified by:
      nullableDefaultValue in interface Generator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      The nullable default value for the specified type.
    • randomValue

      @NotNull public <T> T randomValue(@NotNull @NotNull Class<T> type)
      Returns a random value of the specified type.
      Specified by:
      randomValue in interface Generator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      A random value for the specified type.
    • nullableRandomValue

      public <T> T nullableRandomValue(@NotNull @NotNull Class<T> type)
      Description copied from interface: Generator
      Returns a random value of the specified type allowing null values.

      The returned value has a probability of be null except for native types. If not null behaves as randomValue().

      Specified by:
      nullableRandomValue in interface Generator
      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

      protected Generator getAnnotatedGenerator(@NotNull @NotNull Class<?> targetType)
      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

      protected void clearCache(@NotNull @NotNull Class<?> targetType)
      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 with GeneratorMethod in the specified target class.
      Parameters:
      targetType - The target class
      Returns:
      The found annotated generator, or null
    • findDeclaredConstructor

      protected <T> ExecutableGenerator<T> findDeclaredConstructor(@NotNull @NotNull Class<T> targetType)
      Finds a constructor annotated with GeneratorMethod 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

      protected <T> ExecutableGenerator<T> findDeclaredMethod(@NotNull @NotNull Class<T> targetType)
      Finds a method annotated with GeneratorMethod 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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object