Package rife.bld.extension.testing
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
TestInstantiationAwareExtension.ExtensionContextScope
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
postProcessTestInstance
(Object testInstance, ExtensionContext context) Processes fields of the test instance annotated withRandomRange
.resolveParameter
(ParameterContext parameterContext, ExtensionContext extensionContext) Resolves a parameter by generating a random integer within the specified range.boolean
supportsParameter
(ParameterContext parameterContext, ExtensionContext extensionContext) Determines if this resolver can resolve a parameter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
RandomRangeResolver
public RandomRangeResolver()
-
-
Method Details
-
postProcessTestInstance
Processes fields of the test instance annotated withRandomRange
.Enables field injection for random ints. The field must be of type
int
.- Specified by:
postProcessTestInstance
in interfaceTestInstancePostProcessor
- Parameters:
testInstance
- the test class instancecontext
- 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 interfaceParameterResolver
- Parameters:
parameterContext
- the context for the parameter to be resolvedextensionContext
- 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 interfaceParameterResolver
- Parameters:
parameterContext
- the context for the parameter to be resolvedextensionContext
- the extension context for the test being executed- Returns:
- a random integer within the specified range
- Throws:
ParameterResolutionException
- ifmin
>max
- See Also:
-