Annotation Interface TypeGeneratorFactorySource


@TypeGeneratorFactorySource is an ArgumentsSource that provides access to values from a TypedGenerator created by a factory class for parameterized tests.

This annotation allows you to use a factory class to create a TypedGenerator for your parameterized tests. The factory class must have a static method that returns a TypedGenerator instance. The method can optionally take parameters specified in the annotation.

Example Usage

 
 @ParameterizedTest
 @TypeGeneratorFactorySource(
     factoryClass = StringGeneratorFactory.class,
     factoryMethod = "createNonEmptyStringGenerator",
     count = 5
 )
 void testWithFactoryGeneratedStrings(String value) {
     assertNotNull(value);
     assertFalse(value.isEmpty());
 }
 
 // With parameters
 @ParameterizedTest
 @TypeGeneratorFactorySource(
     factoryClass = IntegerGeneratorFactory.class,
     factoryMethod = "createRangeGenerator",
     methodParameters = {"1", "100"},
     count = 10
 )
 void testWithParameterizedFactory(Integer value) {
     assertNotNull(value);
     assertTrue(value >= 1 && value <= 100);
 }
 
 

Factory class example:

 
 public class IntegerGeneratorFactory {
     public static TypedGenerator<Integer> createRangeGenerator(String min, String max) {
         return Generators.integers(Integer.parseInt(min), Integer.parseInt(max));
     }
 }
 
 
Since:
2.0
Author:
Oliver Wolff
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The factory class that will create the TypedGenerator.
    The name of the factory method to invoke.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    Number of instances to generate.
    Optional parameters to pass to the factory method.
  • Element Details

    • factoryClass

      The factory class that will create the TypedGenerator.
      Returns:
      the factory class
    • factoryMethod

      The name of the factory method to invoke. The method must be static and return a TypedGenerator.
      Returns:
      the factory method name
    • methodParameters

      Optional parameters to pass to the factory method. All parameters are passed as strings, and the factory method is responsible for parsing them to the appropriate types.
      Returns:
      the method parameters as strings
      Default:
      {}
    • count

      int count
      Number of instances to generate.
      Returns:
      the number of instances to generate, defaults to 1
      Default:
      1