-
Notifications
You must be signed in to change notification settings - Fork 233
Key APIs
Mahmoud Ben Hassine edited this page Mar 9, 2016
·
21 revisions
The key API of Random Beans is the EnhancedRandom
abstract class:
public abstract class EnhancedRandom extends Random {
/**
* Generate a random instance of the given type.
*
* @param type the type for which an instance will be generated
* @param excludedFields the name of fields to exclude
* @param <T> the actual type of the target object
* @return a random instance of the given type
* @throws ObjectGenerationException when unable to populate an instance of the given type
*/
public abstract <T> T nextObject(final Class<T> type, final String... excludedFields);
}
You can generate a random instance any Java type using the nextObject()
method. Random Beans will introspect your object type hierarchy, generate an instance for each nested bean and populate it with random data.
Random Beans comes with a default implementation of the EnhancedRandom
interface that you can create using the EnhancedRandomBuilder
API :
EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder().build();
Easy Random is created by Mahmoud Ben Hassine with the help of some awesome contributors!