java.lang.Object
com.pholser.junit.quickcheck.generator.Generator<T>
com.pholser.junit.quickcheck.generator.Ctor<T>
Type Parameters:
T - the type of objects generated
All Implemented Interfaces:
Gen<T>, Shrink<T>

public class Ctor<T> extends Generator<T>

Produces instances of a class by generating values for the parameters of one of the constructors on the class, and invoking the constructor.

If a constructor parameter is marked with an annotation that influences the generation of a given kind of value, that annotation will be applied to the generation of values for that parameter.

This generator is intended to be used with From, and not to be available via the ServiceLoader mechanism.

  • Field Details

  • Constructor Details

    • Ctor

      public Ctor(Class<T> type)
      Reflects the given type for a single accessible constructor to be used to generate values of that type.
      Parameters:
      type - the type of objects to be generated
    • Ctor

      public Ctor(Constructor<T> ctor)
      Uses the given constructor to generate values of the declaring type.
      Parameters:
      ctor - the constructor to reflect on to generate constructor parameter values
  • Method Details

    • generate

      public T generate(SourceOfRandomness random, GenerationStatus status)
      Description copied from interface: Gen
      Generates a value, possibly influenced by a source of randomness and metadata about the generation.
      Parameters:
      random - source of randomness to be used when generating the value
      status - an object that can be used to influence the generated value. For example, generating lists can use the size method to generate lists with a given number of elements.
      Returns:
      the generated value
    • provide

      public void provide(Generators provided)
      Description copied from class: Generator

      Supplies the available generators to this one.

      This is intended for use only by junit-quickcheck itself, and not by creators of custom generators.

      Overrides:
      provide in class Generator<T>
      Parameters:
      provided - repository of available generators
    • configure

      public void configure(AnnotatedType annotatedType)
      Description copied from class: Generator

      Configures this generator using annotations from a given annotated type.

      This method considers only annotations that are themselves marked with GeneratorConfiguration.

      By default, the generator will configure itself using this procedure:

      • For each of the given annotations:
        • Find a public method on the generator named configure, that accepts a single parameter of the annotation type
        • Invoke the configure method reflectively, passing the annotation as the argument
      Overrides:
      configure in class Generator<T>
      Parameters:
      annotatedType - a type usage
    • copy

      public Ctor<T> copy()
      Description copied from class: Generator
      Used by the framework to make a copy of the receiver.
      Overrides:
      copy in class Generator<T>
      Returns:
      a copy of the receiver
    • arguments

      private Object[] arguments(SourceOfRandomness random, GenerationStatus status)