org.meanbean.factories.basic.RandomFactoryBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of meanbean Show documentation
Show all versions of meanbean Show documentation
Mean Bean is an open source Java test library that tests equals and hashCode contract compliance, as well as JavaBean/POJO getter and setter methods.
package org.meanbean.factories.basic;
import java.io.Serializable;
import org.meanbean.lang.Factory;
import org.meanbean.util.RandomValueGenerator;
import org.meanbean.util.RandomValueGeneratorProvider;
import org.meanbean.util.SimpleValidationHelper;
import org.meanbean.util.ValidationHelper;
/**
* Abstract base class for a Factory that creates random objects of the specified type.
*
* @author Graham Williamson
* @param
* The data type of the object this Factory creates.
*/
public abstract class RandomFactoryBase implements Factory, RandomValueGeneratorProvider, Serializable {
/** Unique version ID of this Serializable class. */
private static final long serialVersionUID = 1L;
/** Input validation helper. */
protected final ValidationHelper validationHelper = new SimpleValidationHelper();
/** Random number generator used by the factory to generate random values. */
private final RandomValueGenerator randomValueGenerator;
/**
* Construct a new Factory.
*
* @param randomValueGenerator
* A random value generator used by the Factory to generate random values.
*
* @throws IllegalArgumentException
* If the specified randomValueGenerator is deemed illegal. For example, if it is null.
*/
public RandomFactoryBase(RandomValueGenerator randomValueGenerator) throws IllegalArgumentException {
validationHelper.ensureExists("randomValueGenerator", "construct Factory", randomValueGenerator);
this.randomValueGenerator = randomValueGenerator;
}
/**
* Get the random value generator.
*
* @return A random value generator.
*/
public final RandomValueGenerator getRandomValueGenerator() {
return randomValueGenerator;
}
/**
* Create a new object of the specified type.
*
* @return A new object of the specified type.
*/
public abstract T create();
}