Package de.team33.patterns.arbitrary.mimas


package de.team33.patterns.arbitrary.mimas
This module, consisting of this package and the classes/interfaces defined in it, provides tools to generate arbitrary data of virtually any type, mainly for testing purpose.

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.

See Also:
  • Class
    Description
    A utility interface: can extend producer classes with the functionality to fill classic mutable Java data objects* with (typically) random values.
    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.
    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).
    A RuntimeException reflecting the unfit condition of a component involved in an operation.