Mapping impl code to modular steps

Suppose the activity in the previous scenario is created using the following code:

01 var testActivity = ActivityBuilder()
02 	.withPriority(Priority.TC_URGENT)
03	 .withDueInDaysFromNow(7)
04 	.create(bundleObj) 

The impl code appears as a single block. However, the impl code may need to spread across several methods. This is because scenario steps are designed to be usable in a variety of combinations. For example, some activity scenarios may specify the activity priority, but others may not. Therefore, each line of code must be assigned to a different method. The following table lists the scenario steps for the previous example and the impl methods that could be created to execute each step.

Scenario step Impl methods
When I create an activity
function createActivity() {
  ...
  var testActivity = ActivityBuilder()
  ...
}
And the activity priority is "Urgent"
function setActivityPriority() {
  ...
    .withPriority(Priority.TC_URGENT)
  ...
}
And the activity is due in "7" days
function setActivityDueDate() {
  ...
    .withDueInDaysFromNow(7)
  ...
}
  ...
    .create(bundleObj)
  ...
And I assign the activity using automated assignment
function assignActivityUsingRules() {
  ...
  testActivity.autoAssign()
  ...
}
Then the activity is assigned to my supervisor (not relevant to the creation of test data)

The modularity of scenario steps can impose a requirement on impl methods. In some cases, multiple impl methods must share a common builder. Furthermore, the object must not be created from the builder until after all of the set-up values have been specified.