See: Description
| Interface | Description |
|---|---|
| Charger |
A utility interface:
can extend producer classes with the functionality to fill classic mutable Java data objects* with (typically)
random values.
|
| Generator |
A utility interface:
represents an interface of a basic arbitrary generator that defines methods for primitive values as well as
values of some other basic types, including
enum types, String and BigInteger. |
| Initiator |
A utility interface: can extend producer classes with the functionality to create instances of types composed
(essentially) of properties and constructed like a record (as defined with Java 17).
|
| Exception | Description |
|---|---|
| UnfitConditionException |
A
RuntimeException reflecting the unfit condition of a component involved in an operation. |
In a typical use case, a producer class is defined in the "test area" of a project, which is intended to
generate the data required in the tests, including complex ones, with arbitrary values.
The class can simply use or extend Random*, for example, and also implements the
Generator interface, which makes other basic methods available.
Based on this, methods are then defined there in order to generate data of context-specific types. Example:
public class Producer implements Generator, Charger, Initiator {
private final Random random = new Random();
@Override
public final BigInteger anyBits(final int numBits) {
return new BigInteger(numBits, random);
}
public final Person anyPerson() {
return initiate(Person.class);
}
public final Customer anyCustomer() {
return charge(new Customer());
}
public final Employee anyEmployee() {
return charge(new Employee());
}
}
In this example, the Charger and
Initiator interfaces are used to charge/initiate the complex,
contextual types (Person, Customer, Employee, ...) with random content.
Copyright © 2023 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.