Class RandomRangeResolver

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

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

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

Resolution Priority:

When both parameter-level and method-level @RandomRange annotations are present, the parameter-level annotation takes precedence.

If only a method-level annotation exists, its configuration applies to all int parameters in that method.

The resolver validates that:

  • The parameter is annotated with @RandomRange or the method is annotated with @RandomRange
  • The parameter type is int
  • The minimum value is not greater than the maximum value
Since:
1.0
Author:
Erik C. Thauvin
See Also:
  • Constructor Details

    • RandomRangeResolver

      public RandomRangeResolver()
  • Method Details

    • postProcessTestInstance

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

      Enables field injection for random ints. The field must be of type int.

      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 int parameters annotated with RandomRange at parameter or method level.

      Specified by:
      supportsParameter in interface ParameterResolver
      Parameters:
      parameterContext - the context for the parameter to be resolved
      extensionContext - the extension context for the test being executed
      Returns:
      true if this resolver can resolve the parameter, false otherwise
      Throws:
      ParameterResolutionException - if an error occurs while determining support
    • resolveParameter

      public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
      Resolves a parameter by generating a random integer within the specified range.

      Priority: Parameter-level > Method-level > Default (0-100, for safety).

      Specified by:
      resolveParameter in interface ParameterResolver
      Parameters:
      parameterContext - the context for the parameter to be resolved
      extensionContext - the extension context for the test being executed
      Returns:
      a random integer within the specified range
      Throws:
      ParameterResolutionException - if min > max
      See Also: