Class DecoratorGenerator<T>

java.lang.Object
de.cuioss.test.generator.impl.DecoratorGenerator<T>
Type Parameters:
T - The type of elements to be generated
All Implemented Interfaces:
TypedGenerator<T>

public class DecoratorGenerator<T> extends Object implements TypedGenerator<T>
A decorator pattern implementation for TypedGenerator that allows wrapping and enhancing existing generators. This is particularly useful for testing corner cases and special scenarios.

Features:

  • Wraps any existing TypedGenerator
  • Preserves type safety through generic type parameter
  • Provides explicit type information via TypedGenerator.getType()
  • Thread-safe if the decorated generator is thread-safe

Example usage:

 
 // Create a decorator for integer generation
 TypedGenerator&lt;Integer&gt; baseGenerator = Generators.integers(1, 100);
 var decorator = new DecoratorGenerator&lt;>(Integer.class, baseGenerator);
 
 // Use the decorated generator
 Integer value = decorator.next();
 
 

Common use cases include:

  • Adding validation or transformation logic
  • Logging or monitoring generator behavior
  • Implementing special case handling
  • Combining multiple generators
Author:
Oliver Wolff
See Also:
  • Constructor Details

  • Method Details

    • next

      public T next()
      Description copied from interface: TypedGenerator
      Generates the next instance based on the generator's configuration. Implementations must ensure thread-safety.
      Specified by:
      next in interface TypedGenerator<T>
      Returns:
      A newly created instance. May be null if the generator explicitly supports null value generation.