Class RandomStringResolver

java.lang.Object
rife.bld.extension.testing.RandomStringResolver
All Implemented Interfaces:
Extension, ParameterResolver, TestInstancePostProcessor, TestInstantiationAwareExtension

public class RandomStringResolver extends Object implements ParameterResolver, TestInstancePostProcessor
Parameter and field resolver for the RandomString annotation.

This resolver automatically injects random string values into test method parameters that are annotated with @RandomString or are part of test methods annotated with @RandomString at the method level.

Resolution Priority:

Parameter-level annotation takes precedence over method-level.

Security:

Uses SecureRandom for cryptographically strong random number generation.

Default Configuration:

  • Length: 10 characters
  • Character Set: Alphanumeric (A-Z, a-z, 0-9)
Since:
1.0
Author:
Erik C. Thauvin
See Also:
  • Constructor Details

    • RandomStringResolver

      public RandomStringResolver()
  • Method Details

    • postProcessTestInstance

      public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception
      Processes fields of the test instance annotated with RandomString.

      Enables field injection for random strings. Field must be of type String.

      Specified by:
      postProcessTestInstance in interface TestInstancePostProcessor
      Parameters:
      testInstance - the test class instance
      context - the current extension context
      Throws:
      Exception
    • supportsParameter

      public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
      Determines if this resolver can resolve a parameter.

      Supports String parameters annotated with RandomString at parameter or method level.

      Specified by:
      supportsParameter in interface ParameterResolver
      Parameters:
      parameterContext - information about the parameter to be resolved
      extensionContext - the current extension context
      Returns:
      true if the parameter can be resolved by this extension, false otherwise
    • resolveParameter

      public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
      Resolves the parameter by generating a random string based on annotation configuration.

      Priority: Parameter-level > Method-level > Default (10, alphanumeric).

      Specified by:
      resolveParameter in interface ParameterResolver
      Parameters:
      parameterContext - information about the parameter to be resolved
      extensionContext - the current extension context
      Returns:
      a randomly generated string matching the annotation specifications
      Throws:
      IllegalArgumentException - if the annotation specifies invalid parameters