Class AbstractParameterExtractionHandler
- java.lang.Object
-
- io.testomat.junit.extractor.strategy.handlers.AbstractParameterExtractionHandler
-
- All Implemented Interfaces:
ParameterExtractionHandler
- Direct Known Subclasses:
ArgumentsSourceHandler,CsvFileSourceHandler,CsvSourceHandler,EmptySourceHandler,EnumSourceHandler,MethodSourceHandler,NullAndEmptySourceHandler,NullSourceHandler,ValueSourceHandler
public abstract class AbstractParameterExtractionHandler extends java.lang.Object implements ParameterExtractionHandler
Abstract base class for parameter extraction handlers that provides common functionality and eliminates code duplication across different annotation-specific handlers. This class implements the Template Method pattern, providing a standardized flow for parameter extraction while allowing concrete implementations to define annotation-specific parsing logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractParameterExtractionHandler.ParseResult
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlogger
-
Constructor Summary
Constructors Constructor Description AbstractParameterExtractionHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.String,java.lang.Object>createGenericParameterMap(java.lang.Object value)Creates a generic parameter map when method information is not available.protected java.util.Map<java.lang.String,java.lang.Object>createMultiParameterMap(java.lang.Object[] values, ParameterExtractionContext context)Creates a parameter map for multiple parameter values.protected java.util.Map<java.lang.String,java.lang.Object>createSingleParameterMap(java.lang.Object value, ParameterExtractionContext context)Creates a parameter map for a single parameter value.protected abstract java.lang.ObjectextractFromAnnotation(ParameterExtractionContext context)Extracts parameter values from the annotation as a fallback.protected AbstractParameterExtractionHandler.ParseResultextractFromDisplayNameWithResult(ParameterExtractionContext context)Extracts parameter values from the test display name using regex pattern matching.java.lang.ObjectextractParameters(ParameterExtractionContext context)Extracts parameters from the test method using this strategy's specific logic.protected java.lang.ObjectformatParameters(java.lang.Object value, ParameterExtractionContext context)Formats the extracted parameter values into the final result format.protected abstract java.lang.ObjectparseDisplayNameValue(java.lang.String valueStr, ParameterExtractionContext context)Parses the value from the display name specific to this handler type.protected java.lang.ObjectparseTypedValue(java.lang.String value)Parses a string value into its appropriate type with common type conversions.protected java.lang.StringremoveQuotes(java.lang.String value)Removes surrounding quotes from a string value.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.testomat.junit.extractor.strategy.handlers.ParameterExtractionHandler
getStrategyName
-
-
-
-
Method Detail
-
extractParameters
public final java.lang.Object extractParameters(ParameterExtractionContext context)
Description copied from interface:ParameterExtractionHandlerExtracts parameters from the test method using this strategy's specific logic.- Specified by:
extractParametersin interfaceParameterExtractionHandler- Parameters:
context- the parameter extraction context containing test method and annotations- Returns:
- extracted parameter value (single value for simple params, Map for multiple params), or null if extraction fails
-
extractFromDisplayNameWithResult
protected AbstractParameterExtractionHandler.ParseResult extractFromDisplayNameWithResult(ParameterExtractionContext context)
Extracts parameter values from the test display name using regex pattern matching.- Parameters:
context- the parameter extraction context- Returns:
- ParseResult containing the extracted values or failure indicator
-
formatParameters
protected java.lang.Object formatParameters(java.lang.Object value, ParameterExtractionContext context)Formats the extracted parameter values into the final result format.- Parameters:
value- the extracted valuescontext- the parameter extraction context- Returns:
- formatted parameter map with proper parameter names
-
createMultiParameterMap
protected java.util.Map<java.lang.String,java.lang.Object> createMultiParameterMap(java.lang.Object[] values, ParameterExtractionContext context)Creates a parameter map for multiple parameter values.- Parameters:
values- the parameter valuescontext- the parameter extraction context- Returns:
- parameter map with named parameters
-
createSingleParameterMap
protected java.util.Map<java.lang.String,java.lang.Object> createSingleParameterMap(java.lang.Object value, ParameterExtractionContext context)Creates a parameter map for a single parameter value.- Parameters:
value- the parameter valuecontext- the parameter extraction context- Returns:
- parameter map with named parameter
-
createGenericParameterMap
protected java.util.Map<java.lang.String,java.lang.Object> createGenericParameterMap(java.lang.Object value)
Creates a generic parameter map when method information is not available.- Parameters:
value- the parameter value or values- Returns:
- generic parameter map with default parameter names
-
parseTypedValue
protected java.lang.Object parseTypedValue(java.lang.String value)
Parses a string value into its appropriate type with common type conversions.- Parameters:
value- the string value to parse- Returns:
- the parsed typed value (Boolean, Integer, Long, Double, or String)
-
removeQuotes
protected java.lang.String removeQuotes(java.lang.String value)
Removes surrounding quotes from a string value.- Parameters:
value- the value to unquote- Returns:
- the unquoted value
-
parseDisplayNameValue
protected abstract java.lang.Object parseDisplayNameValue(java.lang.String valueStr, ParameterExtractionContext context)Parses the value from the display name specific to this handler type.- Parameters:
valueStr- the value string from the display namecontext- the parameter extraction context- Returns:
- the parsed values
- Throws:
java.lang.RuntimeException- if parsing fails and fallback to annotation is required
-
extractFromAnnotation
protected abstract java.lang.Object extractFromAnnotation(ParameterExtractionContext context)
Extracts parameter values from the annotation as a fallback.- Parameters:
context- the parameter extraction context- Returns:
- the extracted values from the annotation
-
-