-
Notifications
You must be signed in to change notification settings - Fork 0
Base Data Providers in v1.0.0
RandomGen comes with some Data Providers baked in. Below is a comprehensive list.
.returning(ENUM_VALUE)
Returns a valid enum value at random. ENUM_VALUE
can be any of the values of the desired enum to be used. The actual value chosen does not matter and will not affect the returned values.
RandomGen<Transformer> randomGen = new RandomGen.Builder<>(new RandomGen.InstanceProvider<Transformer>() {
@Override
public Transformer provideInstance() {
return new Transformer();
}
})
.withField("alignment")
.returning(EnumType.AUTOBOT)
.build();
Usage:
> randomGen.generate();
Transformer { alignment: EnumType.AUTOBOT }
> randomGen.generate();
Transformer { alignment: EnumType.UNKNOWN }
> randomGen.generate();
Transformer { alignment: EnumType.DECEPTICON }
.returning(List<ANY_VALUE>)
Returns a random value out of the provided list of values. ANY_VALUE
can be of any type.
RandomGen<Locator> randomGen = new RandomGen.Builder<>(new RandomGen.InstanceProvider<Locator>() {
@Override
public Locator provideInstance() {
return new Locator();
}
})
.withField("location")
.returning(Arrays.asList("Home", "Away", "Unknown"))
.build();
Usage:
> randomGen.generate();
Locator { location: "Unknown" }
> randomGen.generate();
Locator { location: "Home" }
> randomGen.generate();
Locator { location: "Away" }
.returning(DATA_PROVIDER)
Uses the provided DATA_PROVIDER
to generate custom values. Use this method when you want to create complex data structures, such as new instances of any classes.
RandomGen<Employee> employeeRandomGen = new RandomGen.Builder<>(new RandomGen.InstanceProvider<Employee>() {
@Override
public ObjectClass provideInstance() {
return new Employee();
}
})
.withField("name")
.returning(Arrays.asList("James", "Michael", "David"))
.build();
RandomGen<Job> jobRandomGen = new RandomGen.Builder<>(new RandomGen.InstanceProvider<Job>() {
@Override
public ObjectClass provideInstance() {
return new Job();
}
})
.withField("employee")
.returning(employeeRandomGen)
.build();
Usage:
> jobRandomGen.generate();
Job { employee: { name: "James" } }
> jobRandomGen.generate();
Job { employee: { name: "David" } }
> jobRandomGen.generate();
Job { employee: { name: "Michael" } }
returning(DATA_PROVIDER, INSTANCES_COUNT)
.returning(DATA_PROVIDER, MIN_INSTANCES_COUNT, MAX_INSTANCES_COUNT)
.returningBoolean()
.returningByte()
.returningByte()
.returningBytes(SIZE)
.returningBytes(MIN_SIZE, MAX_SIZE)
.returningDouble()
.returningExplicitly(ANY_VALUE)
Returns the same value every time. ANY_VALUE
can be a value of any type.
.returningFloat()
.returningInteger()
.returningLong()
.returning(MIN_DOUBLE, MAX_DOUBLE)
.returning(MIN_FLOAT, MAX_FLOAT)
.returning(MIN_INT, MAX_INT)
.returning(MIN_LONG, MAX_LONG)
.returningSequentialInteger()
.returningUuid()
.returningRGB(WITH_ALPHA)
.returningLoremIpsum()
.returningLoremIpsum(LENGTH)
.returningLoremIpsum(MIN_LENGTH, MAX_LENGTH)
.returningLoremIpsum(MIN_LENGTH, MAX_LENGTH, PARAGRAPH_DELIMITER)