Class AbstractTypedGeneratorArgumentsProvider
java.lang.Object
de.cuioss.test.generator.junit.parameterized.AbstractTypedGeneratorArgumentsProvider
- All Implemented Interfaces:
org.junit.jupiter.params.provider.ArgumentsProvider
- Direct Known Subclasses:
CompositeTypeGeneratorArgumentsProvider,GeneratorsSourceArgumentsProvider,TypeGeneratorArgumentsProvider,TypeGeneratorFactoryArgumentsProvider
public abstract class AbstractTypedGeneratorArgumentsProvider
extends Object
implements org.junit.jupiter.params.provider.ArgumentsProvider
Abstract base class for TypedGenerator-based ArgumentsProviders.
Contains common functionality for seed management and generator handling.
- Since:
- 2.0
- Author:
- Oliver Wolff
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TypedGenerator<?> createGeneratorInstance(Class<? extends TypedGenerator<?>> generatorClass) Creates an instance of the specified generator class using its no-args constructor.protected longdetermineSeed(org.junit.jupiter.api.extension.ExtensionContext context) Determines the seed to use for the generator based on the following priority: 1.findMethod(Class<?> clazz, String methodName) Finds a method in the given class that returns a TypedGenerator and takes no parameters.protected List<org.junit.jupiter.params.provider.Arguments> generateArguments(TypedGenerator<?> generator) Generates arguments from a TypedGenerator.protected abstract intgetCount()Gets the count of values to generate.protected abstract longgetSeed()Gets the seed value specified for this provider.Stream<? extends org.junit.jupiter.params.provider.Arguments> provideArguments(org.junit.jupiter.api.extension.ExtensionContext context) Provides arguments for the parameterized test.protected abstract Stream<? extends org.junit.jupiter.params.provider.Arguments> provideArgumentsForGenerators(org.junit.jupiter.api.extension.ExtensionContext context) Template method to be implemented by subclasses to provide arguments.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.params.provider.ArgumentsProvider
provideArguments
-
Field Details
-
IN_CLASS
Common error message part for method not found exceptions.- See Also:
-
-
Constructor Details
-
AbstractTypedGeneratorArgumentsProvider
-
-
Method Details
-
provideArguments
public Stream<? extends org.junit.jupiter.params.provider.Arguments> provideArguments(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception Provides arguments for the parameterized test.- Specified by:
provideArgumentsin interfaceorg.junit.jupiter.params.provider.ArgumentsProvider- Parameters:
context- the extension context- Returns:
- a stream of arguments
- Throws:
Exception- if an error occurs
-
provideArgumentsForGenerators
protected abstract Stream<? extends org.junit.jupiter.params.provider.Arguments> provideArgumentsForGenerators(org.junit.jupiter.api.extension.ExtensionContext context) Template method to be implemented by subclasses to provide arguments.- Parameters:
context- the extension context- Returns:
- a stream of arguments
-
getSeed
Gets the seed value specified for this provider.- Returns:
- the seed value, or -1 if not specified
-
getCount
Gets the count of values to generate.- Returns:
- the count
-
generateArguments
protected List<org.junit.jupiter.params.provider.Arguments> generateArguments(TypedGenerator<?> generator) Generates arguments from a TypedGenerator.- Parameters:
generator- the generator to use- Returns:
- a list of Arguments
-
determineSeed
Determines the seed to use for the generator based on the following priority: 1. Seed specified in the annotation (if not -1) 2. Seed from @GeneratorSeed on the test method 3. Seed from @GeneratorSeed on the test class 4. Current global seed from RandomConfiguration- Parameters:
context- the extension context- Returns:
- the seed to use
-
createGeneratorInstance
protected TypedGenerator<?> createGeneratorInstance(Class<? extends TypedGenerator<?>> generatorClass) Creates an instance of the specified generator class using its no-args constructor.- Parameters:
generatorClass- the generator class to instantiate- Returns:
- a new instance of the generator
- Throws:
org.junit.platform.commons.JUnitException- if the generator cannot be instantiated
-
findMethod
Finds a method in the given class that returns a TypedGenerator and takes no parameters.- Parameters:
clazz- the class to search inmethodName- the method name to find- Returns:
- an Optional containing the method, or empty if not found
-