Class OptionalGenerator

java.lang.Object
com.pholser.junit.quickcheck.generator.Generator<T>
com.pholser.junit.quickcheck.generator.ComponentizedGenerator<com.google.common.base.Optional>
com.pholser.junit.quickcheck.guava.generator.OptionalGenerator
All Implemented Interfaces:
Gen<com.google.common.base.Optional>, Shrink<com.google.common.base.Optional>

public class OptionalGenerator extends ComponentizedGenerator<com.google.common.base.Optional>
Produces values of type Optional.
  • Constructor Details

    • OptionalGenerator

      public OptionalGenerator()
  • Method Details

    • generate

      public com.google.common.base.Optional<?> 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
    • doShrink

      public List<com.google.common.base.Optional> doShrink(SourceOfRandomness random, com.google.common.base.Optional 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<com.google.common.base.Optional>
      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.
    • numberOfNeededComponents

      public int numberOfNeededComponents()
      Description copied from class: Generator

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

      Overrides:
      numberOfNeededComponents in class Generator<com.google.common.base.Optional>
      Returns:
      how many component generators this generator needs
      See Also:
    • 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<com.google.common.base.Optional>
      Parameters:
      value - the value to assess
      Returns:
      a measure of the given value's magnitude
      See Also: