Class Generators


  • public class Generators
    extends Object
    This class provides access to built-in generators.

    It can be used to customise random values generated by built-in generators. This includes numeric, collection sizes, string lengths, etc.

    • Method Detail

      • getApiMethod

        public static String getApiMethod​(Class<?> generatorSpec)
        Returns the public API method for the given generator spec class.
        Parameters:
        generatorSpec - whose API method to return
        Returns:
        the public API method, for example array() for the array generator
      • math

        public MathGenerators math()
        Return generators for java.math classes.
        Returns:
        built-in generators for java.math classes.
      • oneOf

        @SafeVarargs
        public final <T> OneOfArrayGeneratorSpec<T> oneOf​(T... choices)
        Picks a random value from the given choices.
        Type Parameters:
        T - element type
        Parameters:
        choices - to choose from
        Returns:
        generator for making a selection
      • oneOf

        public final <T> OneOfCollectionGeneratorSpec<T> oneOf​(Collection<T> choices)
        Picks a random value from the given choices.
        Type Parameters:
        T - element type
        Parameters:
        choices - to choose from
        Returns:
        generator for making a selection
      • array

        public <T> ArrayGeneratorSpec<T> array()
        Customises generated arrays.
        Type Parameters:
        T - array component type
        Returns:
        customised generator
      • collection

        public <T> CollectionGeneratorSpec<T> collection()
        Customises generated collections.
        Type Parameters:
        T - element type
        Returns:
        customised generator
      • map

        public <K,​V> MapGeneratorSpec<K,​V> map()
        Customises generated maps.
        Type Parameters:
        K - key type
        V - value type
        Returns:
        customised generator
      • atomic

        public AtomicGenerators atomic()
        Provides access to atomic generators.
        Returns:
        built-in atomic generators
      • temporal

        public TemporalGenerators temporal()
        Provides access to temporal generators.
        Returns:
        built-in temporal generators
      • text

        public TextGenerators text()
        Provides access to text generators.
        Returns:
        built-in text generators