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
    Modifier and Type
    Field
    Description
    protected static final String
    Common error message part for method not found exceptions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected TypedGenerator<?>
    createGeneratorInstance(Class<? extends TypedGenerator<?>> generatorClass)
    Creates an instance of the specified generator class using its no-args constructor.
    protected long
    determineSeed(org.junit.jupiter.api.extension.ExtensionContext context)
    Determines the seed to use for the generator based on the following priority: 1.
    protected Optional<Method>
    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>
    Generates arguments from a TypedGenerator.
    protected abstract int
    Gets the count of values to generate.
    protected abstract long
    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, wait

    Methods inherited from interface org.junit.jupiter.params.provider.ArgumentsProvider

    provideArguments
  • Field Details

  • Constructor Details

  • 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:
      provideArguments in interface org.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

      protected abstract long getSeed()
      Gets the seed value specified for this provider.
      Returns:
      the seed value, or -1 if not specified
    • getCount

      protected abstract int 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

      protected long determineSeed(org.junit.jupiter.api.extension.ExtensionContext context)
      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

      protected Optional<Method> findMethod(Class<?> clazz, String methodName)
      Finds a method in the given class that returns a TypedGenerator and takes no parameters.
      Parameters:
      clazz - the class to search in
      methodName - the method name to find
      Returns:
      an Optional containing the method, or empty if not found