Package rife.bld.extension.testing
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
TestInstantiationAwareExtension.ExtensionContextScope -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidpostProcessTestInstance(Object testInstance, ExtensionContext context) Processes fields of the test instance annotated withRandomString.resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) Resolves the parameter by generating a random string based on annotation configuration.booleansupportsParameter(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, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
RandomStringResolver
public RandomStringResolver()
-
-
Method Details
-
postProcessTestInstance
Processes fields of the test instance annotated withRandomString.Enables field injection for random strings. Field must be of type
String.- Specified by:
postProcessTestInstancein 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 String parameters annotated with
RandomStringat parameter or method level.- Specified by:
supportsParameterin interfaceParameterResolver- Parameters:
parameterContext- information about the parameter to be resolvedextensionContext- the current extension context- Returns:
trueif the parameter can be resolved by this extension,falseotherwise
-
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:
resolveParameterin interfaceParameterResolver- Parameters:
parameterContext- information about the parameter to be resolvedextensionContext- the current extension context- Returns:
- a randomly generated string matching the annotation specifications
- Throws:
IllegalArgumentException- if the annotation specifies invalid parameters
-