System | Status |
---|---|
Dependency | |
This modules aims to provide a universal mechanism to create random test dummies of java objects.
The com.namics.commons.random.RandomData util provides a lot of convenience methods to create basic random values.
Use the generic method com.namics.commons.random.RandomData.random(Class<?> type) to create random instance of the object.
This works for types with available generators
Integer random = RandomData.random(Integer.class);
But also for Java beans:
public class Demo { public static class Person{ private String name; public String getName() {return name;} public void setName(String name) {this.name = name;} } @Test public void simplePerson() throws Exception { Person person = RandomData.random(Person.class); System.out.println(person.getName()); // Leonel Bowers } }
This requires a registered instance of com.namics.commons.random.generator.RandomGenerator<SupportedType> for the requested type. There is a basic list of generators registered by default to support most basic type. See basic generators for complete list.
There is a basic support for Collections.
There are several ways to register custom RandomGenerator<SupportedType>s: