Skip navigation links

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.

See: Description

Package de.team33.patterns.arbitrary.mimas Description

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:
Mimas
Skip navigation links

Copyright © 2024 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.