The order in which builder parts are executed is very important. Looking at this TodoList example we have 3 builder parts:
- UserBuilderPart that creates users
- TodoListBuilderPart that creates todo lists
- TaskBuilderPart that creates tasks inside a todo list
A good idea is to create an enum
for an easy order management:
public enum BuilderPartOrder {
USERS,
TODO_LISTS,
TASKS
}
The enum defines from top to bottom in which order the builder parts are executed. In each builder part class, you can then just define the position in the enum declaration as order:
public class UserBuilderPart implements ScenarioBuilderPart<GivenTodoScenario> {
@Override
public int getOrder() {
return BuilderPartOrder.USERS.ordinal();
}
// ...
}