The generator system has different facets, therefore combines different concepts and technologies. It sits on top of cui-test-generator
An important aspect is a typed generator system for most Java-default types that is capable of creating a generator for nearly any of the given types automatically. This is essential for Value-Object-Testing that relies on automatic creation of arbitrary objects with random data.
In addition, there are hooks within the Value-Object-Testing to interact configure the generators as needed.
de.cuioss.test.valueobjects.generator.TypedGeneratorRegistry
.
Is the central element of the automatic Generator system. It creates generator for most of the types passed to it
In order to be used there are two methods essential:
// Initializes the basic java-types
TypedGeneratorRegistry.registerBasicTypes();
// Clears the registry
TypedGeneratorRegistry.clear();
In the context of Junit-5-tests the setup and clearing is done by the extension de.cuioss.test.valueobjects.junit5.extension.GeneratorRegistryController
what is already present for the base-classes de.cuioss.test.valueobjects.MapperTest<M, S, T>
and de.cuioss.test.valueobjects.ValueObjectTest
If setup is correctly obtaining a generator for a type is done by calling:
public static <T> Optional<TypedGenerator<T>> getGenerator(final Class<T> type)
Although returning an Optional
for most of the case it will return a valid generator for the given type.
Depending on the given type there is a different quality regarding entropy of the instances. For Standard Java-Types, Enum
-classes, value-objects with constructor having primitive types it is very high.
Types with a default Constructor, abstract-types / Interfaces have no entropy, because of the mechanism used to create them. They are useful for fulfilling a parameter contract for some other type.