Package de.cuioss.test.generator.impl
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>
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<Integer> baseGenerator = Generators.integers(1, 100);
var decorator = new DecoratorGenerator<>(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
-
DecoratorGenerator
public DecoratorGenerator()
-
-
Method Details
-
next
Description copied from interface:TypedGeneratorGenerates the next instance based on the generator's configuration. Implementations must ensure thread-safety.- Specified by:
nextin interfaceTypedGenerator<T>- Returns:
- A newly created instance. May be null if the generator explicitly supports null value generation.
-