Class AbstractStringGenerator

java.lang.Object
com.pholser.junit.quickcheck.generator.Generator<String>
com.pholser.junit.quickcheck.generator.java.lang.AbstractStringGenerator
All Implemented Interfaces:
Gen<String>, Shrink<String>
Direct Known Subclasses:
Encoded, StringGenerator

public abstract class AbstractStringGenerator extends Generator<String>

Base class for generators of values of type String.

The generated values will have String.length() decided by GenerationStatus.size().

  • Constructor Details

    • AbstractStringGenerator

      protected AbstractStringGenerator()
  • Method Details

    • generate

      public String 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<String>
      Parameters:
      larger - the "larger" value
      Returns:
      whether this generator can participate in "shrinking" the larger value
    • doShrink

      public List<String> doShrink(SourceOfRandomness random, String 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<String>
      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.
    • 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<String>
      Parameters:
      value - the value to assess
      Returns:
      a measure of the given value's magnitude
      See Also:
    • nextCodePoint

      protected abstract int nextCodePoint(SourceOfRandomness random)
    • codePointInRange

      protected abstract boolean codePointInRange(int codePoint)
    • codePointsInRange

      private boolean codePointsInRange(String s)
    • removals

      private List<String> removals(List<Integer> codePoints)
    • convert

      private String convert(List<Integer> codePoints)