Class CompositeGenerator

java.lang.Object
com.pholser.junit.quickcheck.generator.Generator<Object>
com.pholser.junit.quickcheck.internal.generator.CompositeGenerator
All Implemented Interfaces:
Gen<Object>, Shrink<Object>

public class CompositeGenerator extends Generator<Object>
  • Field Details

  • Constructor Details

  • Method Details

    • generate

      public Object 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
    • canShrink

      public boolean canShrink(Object larger)
      Description copied from class: Generator

      Tells whether this generator is allowed to participate in the Shrink process for the given "larger" value.

      Unless overridden, the only criterion for whether a generator is allowed to participate in shrinking a value is if the value can be safely cast to the type of values the generator produces.

      Overrides:
      canShrink in class Generator<Object>
      Parameters:
      larger - the "larger" value
      Returns:
      whether this generator can participate in "shrinking" the larger value
    • doShrink

      public List<Object> doShrink(SourceOfRandomness random, Object larger)
      Description copied from class: Generator

      Gives some objects that are "smaller" than a given "larger" object.

      Unless overridden, a generator will produce an empty list of "smaller" values.

      Overrides:
      doShrink in class Generator<Object>
      Parameters:
      random - source of randomness to use in shrinking, if desired
      larger - the larger object
      Returns:
      objects that are "smaller" than the larger object. Smaller objects should be provided before bigger objects to make shrinking process faster.
    • composed

      Generator<?> composed(int index)
    • numberOfComposedGenerators

      int numberOfComposedGenerators()
    • 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<Object>
      Parameters:
      provided - repository of available generators
    • magnitude

      public BigDecimal magnitude(Object value)
      Description copied from class: Generator

      Gives a hint to the shrinking process as to the magnitude of the given value. The shrinking process will prefer trying values of greater magnitude before values of lesser magnitude. If not overridden, this implementation returns "one".

      Note to generator writers: Do not worry about normalizing a magnitude to a positive value; the shrinking mechanism will take care of it.

      Overrides:
      magnitude in class Generator<Object>
      Parameters:
      value - the value to assess
      Returns:
      a measure of the given value's magnitude
      See Also:
    • 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<Object>
      Parameters:
      annotatedType - a type usage
    • configure

      public void configure(AnnotatedElement element)
      Overrides:
      configure in class Generator<Object>
      Parameters:
      element - an annotated program element
    • addComponentGenerators

      public void addComponentGenerators(List<Generator<?>> newComponents)
      Description copied from class: Generator

      Adds component generators to this generator.

      Some generators need component generators to create proper values. For example, list generators require a single component generator in order to generate elements that have the type of the list parameter's type argument.

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

      Overrides:
      addComponentGenerators in class Generator<Object>
      Parameters:
      newComponents - component generators to add
    • installCandidates

      private void installCandidates(List<Weighted<Generator<?>>> candidates, AnnotatedElement element)
    • candidateGeneratorDescriptions

      private String candidateGeneratorDescriptions()
    • configurationAnnotationNames

      private static List<String> configurationAnnotationNames(AnnotatedElement element)