Interface TypedGenerator<T>

Type Parameters:
T - The type of objects to be generated. Can be any Java type including primitives, objects, collections, and custom types. The actual constraints on the type depend on the specific implementation.
All Known Implementing Classes:
BlindTextGenerator, CityGenerator, CollectionGenerator, DecoratorGenerator, DistinguishedNamesGenerator, EmailGenerator, FloatObjectGenerator, FullNameGenerator, LocalDateGenerator, LocalDateTimeGenerator, LocalTimeGenerator, MailSubjectGenerator, NonBlankStringGenerator, NumberGenerator, PersonGenerator, PhoneNumberGenerator, QuickCheckGeneratorAdapter, ShortObjectGenerator, StreetGenerator, StreetNameGenerator, URLGenerator, UUIDGenerator, UUIDStringGenerator, ZipCodeGenerator, ZonedDateTimeGenerator, ZoneOffsetGenerator

public interface TypedGenerator<T>
A generator creates instances of type T for testing purposes. Implementations must ensure thread-safety and handle null values appropriately.

The method getType() provides a default implementation using next() and reading the concrete Class of the returned element. This approach assumes that next() returns a non-null value at least once. If your generator may return null values, you should override getType() to provide the correct type information.

Usage example from tests:

 
 // Create a generator
 TypedGenerator<String> generator = Generators.nonEmptyStrings();
 
 // Generate values
 String value = generator.next();
 
 // Get type information
 Class<String> type = generator.getType();
 
 
Since:
1.0
Author:
Oliver Wolff
  • Method Summary

    Modifier and Type
    Method
    Description
    default Class<T>
    Provides type information about what kind of objects this generator creates.
    Generates the next instance based on the generator's configuration.
  • Method Details

    • getType

      default Class<T> getType()
      Provides type information about what kind of objects this generator creates. The default implementation uses the first non-null result from next() to determine the type.

      Note: If your generator may return null values or the generated type differs from the actual instance type, you should override this method.

      Returns:
      The class information indicating which type this generator is responsible for.
      Throws:
      IllegalStateException - if the generator cannot determine the type, for example if next() consistently returns null
    • next

      T next()
      Generates the next instance based on the generator's configuration. Implementations must ensure thread-safety.
      Returns:
      A newly created instance. May be null if the generator explicitly supports null value generation.