Generate mock objects
One of the most frustrating operation in ActionScript is to create an Array of mock objects, in order to make the life of our developer easier we put in place a class to generate random objects.
You can define the following point of each mock:
- random properties (the properties that have to be random in your mock)
- empty properties (the properties that have to contain null values)
- the number of mock you need
- the range of specific random properties (the value is forced between two values)
- the predefined values (the values you want for a specific set of properties expressed as paired values)
- the class you want to instantiate when a specific interface has been found in the mock
- additional class paths in which you can find value objects nested in the mock
The syntax is quite simple, the class used to generate a mock follow the Builder design patter
// The fixed values you want for the properties id and kind
var pairs:Vector.<Pair> = new Vector.<Pair>();
pairs[0] = new Pair("id", 1);
pairs[1] = new Pair("kind", 'xft');
// The target of the mock
var info:MockInfo = new MockInfo(MockInfo.FOR_FLEX);
// Additional class path to avoid composition errors
info.addClassPath("com.gnstudio.rikorda.core.model.canvas.vo.");
// The class you want to map to a specific interface
info.mapInterfaceTo(IRule, ImageRule);
// The random values with a range for the properties height and width
var randoms:Vector.<RandomProperty> = new Vector.<RandomProperty>()
randoms[0] = new RandomProperty("height", new NumberRange(60, 100));
randoms[1] = new RandomProperty("width", new NumberRange(60, 140));
var mocker:Array = new Mocker(CanvasObject, info).giveMe(10).withRandomProperties(["frames", "height", "width"]).withRanges(randoms).withEmptyProperties(["effects"]).withTheseValues(pairs).create();
In the next days we'll update and improve the class adding the support for
- Default values configuration for specific nested VO
- Tests of methods
- Random with range for Arrays, Strings and uint
The result you get sounds like
Attachments
- mocker.png (129.1 KB) - added by GiorgioNatili 5 months ago.
