Skip to content

Modifiers

Samuel Beausoleil edited this page Mar 22, 2022 · 3 revisions

Modifiers modify a new object before it is returned to the caller. There are two modifiers provided out of the box:

  • FieldMod
  • MethodMod
  • MixedMultiMod

Note that you may add as many modifiers, one after the other, to a generate() call. If you generate multiple objects at the same time, all the modifiers will be applied to all the objects.

City city = new CityGenerator().generate(new FieldMod("nCitizens", 5), new MethodMod("setName", "Toronto"));

Note that modifiers are usually applied after the object has been created.

FieldMod

A FieldMod works by specifying a path to a field to modify and then the value to replace it with.

// Make this city have 15k citizens
City city = cityGenerator.generate(new FieldMod("nCitizens", 15_000L));

It can also follow a path to find a field within any number of objects. Just give it the name of the fields to enter one after the other separated by a '.'.

// Make the city of this address have 15k citizens
Address address = addressGenerator.generate(new FieldMod("city.nCitizens", 15_000L));

Clone this wiki locally