Class GeneratorRepository
- All Implemented Interfaces:
Generators
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateGeneratorRepository(SourceOfRandomness random, Map<Class<?>, Set<Generator<?>>> generators) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidapplyComponentGenerators(Generator<?> generator, List<Generator<?>> componentGenerators) private Generator<?>compose(ParameterTypeContext parameter, List<Generator<?>> matches) private Generator<?>composeWeighted(ParameterTypeContext parameter, List<Weighted<Generator<?>>> matches) <U> Generator<U>constructor(Class<U> type, Class<?>... argumentTypes) Gives a generator that can produce an instance of the type described by a constructor of a given type that accepts the given types of arguments.Generator<?>Gives a generator that can produce an instance of the type described by the field with the given name and containing type.Generator<?>Gives a generator that can produce instances of the type of the given reflected field.<U> Generator<U>Gives a generator that can produce an instance of the given type by reflecting the class's fields on up its class hierarchy and generating random values for them.Generator<?>generatorFor(ParameterTypeContext parameter) private Generator<?>generatorForArrayType(ParameterTypeContext parameter) generatorsFor(ParameterTypeContext parameter) private booleanhasGeneratorsFor(ParameterTypeContext parameter) private static booleanhasNullableAnnotation(AnnotatedElement element) private static booleanisPrimitiveType(Type type) final <T extends Generator<?>>
TMakes a new generator of the given type, provides it with access to other available generators, configures it with any configuration annotations present on the generator type, and supplies it any component generators it needs.matchingGenerators(ParameterTypeContext parameter) private voidmaybeAddGeneratorByNamingConvention(ParameterTypeContext parameter, List<Generator<?>> matches) private voidmaybeAddGeneratorsFor(ParameterTypeContext parameter, List<Generator<?>> matches) private voidmaybeAddLambdaGenerator(ParameterTypeContext parameter, List<Generator<?>> matches) private voidmaybeAddMarkerInterfaceGenerator(ParameterTypeContext parameter, List<Generator<?>> matches) private voidmaybeRegisterGeneratorForType(Class<?> type, Generator<?> generator) final <T> Generator<T>Gives a generator that can produce instances of one of a given set of related types on every generation.final <T> Generator<T>Gives a generator that can produce instances of one of a given set of related types on every generation.Generator<?>Gives a generator that can produce instances of the type of the given reflected method parameter.Generator<?>produceGenerator(ParameterTypeContext parameter) private voidregisterGeneratorForType(Class<?> type, Generator<?> generator) private voidregisterHierarchy(Class<?> type, Generator<?> generator) private voidregisterTypes(Generator<?> generator) <T> Generator<T>Gives a generator that can produce values of the given type, parameterized by the given "component" types.final GeneratorswithRandom(SourceOfRandomness other) Makes a generator access point just like the receiver, but which uses the given source of randomness for making random choices.
-
Field Details
-
NULLABLE_ANNOTATIONS
-
random
-
generators
-
-
Constructor Details
-
GeneratorRepository
-
GeneratorRepository
-
-
Method Details
-
register
-
register
-
registerTypes
-
registerHierarchy
-
maybeRegisterGeneratorForType
-
registerGeneratorForType
-
field
Description copied from interface:GeneratorsGives a generator that can produce an instance of the type described by the field with the given name and containing type.
If the field is marked with an annotation that influences the generation of a given kind of value, that annotation will be applied to the resulting generator's values.
- Specified by:
fieldin interfaceGenerators- Parameters:
type- containing type for a fieldfieldName- name of a field- Returns:
- generator that can produce values of the field's type
-
constructor
Description copied from interface:GeneratorsGives a generator that can produce an instance of the type described by a constructor of a given type that accepts the given types of arguments. It will generate values for the parameters of the given constructor, and then invoke the constructor.
If the constructor's parameters are marked with annotations that influence the generation of a given kind of value, those annotations will be applied to the generators that will produce values to be used as arguments to the constructor.
- Specified by:
constructorin interfaceGenerators- Type Parameters:
U- type of objects produced by the resulting generator- Parameters:
type- containing type for a constructorargumentTypes- types of arguments to the constructor- Returns:
- generator that can produce values using the constructor
-
fieldsOf
Description copied from interface:GeneratorsGives a generator that can produce an instance of the given type by reflecting the class's fields on up its class hierarchy and generating random values for them.
The given type must have an accessible zero-arg constructor.
If a field of the given type 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 field.
- Specified by:
fieldsOfin interfaceGenerators- Type Parameters:
U- type of objects produced by the resulting generator- Parameters:
type- a type- Returns:
- generator that can produce values of that type
-
type
Description copied from interface:GeneratorsGives a generator that can produce values of the given type, parameterized by the given "component" types.
- Specified by:
typein interfaceGenerators- Type Parameters:
T- type of objects produced by the resulting generator- Parameters:
type- a typecomponentTypes- types for the "components" of the type, if any- Returns:
- generator that can produce values of that type
- See Also:
-
parameter
Description copied from interface:GeneratorsGives a generator that can produce instances of the type of the given reflected method parameter.
If the parameter is marked with an annotation that influences the generation of its value, that annotation will be applied to the generation of values for that parameter's type.
- Specified by:
parameterin interfaceGenerators- Parameters:
parameter- a reflected method parameter- Returns:
- generator that can produce values of the parameter's type
-
field
Description copied from interface:GeneratorsGives a generator that can produce instances of the type of the given reflected field.
If the field is marked with an annotation that influences the generation of its value, that annotation will be applied to the generation of values for that field's type.
- Specified by:
fieldin interfaceGenerators- Parameters:
field- a reflected field- Returns:
- generator that can produce values of the field's type
-
oneOf
@SafeVarargs public final <T> Generator<T> oneOf(Class<? extends T> first, Class<? extends T>... rest) Description copied from interface:GeneratorsGives a generator that can produce instances of one of a given set of related types on every generation.
On each generation, one of the available generators that can produce one of the named types will be chosen with (approximately) equal probability.
- Specified by:
oneOfin interfaceGenerators- Type Parameters:
T- type of objects produced by the resulting generator- Parameters:
first- first type of generated valuerest- other (related) types of generated values- Returns:
- generator that can produce values of the given types
-
oneOf
@SafeVarargs public final <T> Generator<T> oneOf(Generator<? extends T> first, Generator<? extends T>... rest) Description copied from interface:GeneratorsGives a generator that can produce instances of one of a given set of related types on every generation.
On each generation, one of the given generators will be called upon with (approximately) equal probability.
- Specified by:
oneOfin interfaceGenerators- Type Parameters:
T- type of objects produced by the resulting generator- Parameters:
first- first generatorrest- other generators- Returns:
- generator that can produce values using the given generators
-
make
Description copied from interface:GeneratorsMakes a new generator of the given type, provides it with access to other available generators, configures it with any configuration annotations present on the generator type, and supplies it any component generators it needs.
- Specified by:
makein interfaceGenerators- Type Parameters:
T- type of objects produced by the resulting generator- Parameters:
genType- type of generator to createcomponents- any generators for components of the type- Returns:
- a generator for producing values
- See Also:
-
withRandom
Description copied from interface:GeneratorsMakes a generator access point just like the receiver, but which uses the given source of randomness for making random choices.
Intended for use by junit-quickcheck.
- Specified by:
withRandomin interfaceGenerators- Parameters:
other- a source of randomness- Returns:
- a generator access point that has the source of randomness available to it
-
produceGenerator
-
generatorFor
-
generatorForArrayType
-
matchingGenerators
-
maybeAddGeneratorByNamingConvention
private void maybeAddGeneratorByNamingConvention(ParameterTypeContext parameter, List<Generator<?>> matches) -
maybeAddLambdaGenerator
-
maybeAddMarkerInterfaceGenerator
private void maybeAddMarkerInterfaceGenerator(ParameterTypeContext parameter, List<Generator<?>> matches) -
maybeAddGeneratorsFor
-
compose
-
composeWeighted
private Generator<?> composeWeighted(ParameterTypeContext parameter, List<Weighted<Generator<?>>> matches) -
applyComponentGenerators
-
generatorsFor
-
hasGeneratorsFor
-
isPrimitiveType
-
hasNullableAnnotation
-