Substages
It is often the case that one uses multiple builders inside a single stage. In that case it would be convenient it these builders could directly be used in the scenario instead of having to write additional wrapper methods in the stage.
Example of current situation:
Scenario:
@Test
public void customers_can_be_built() {
given().a_customer()
.with().name("John");
}
Stage:
public MyStage<SELF extends MyStage<?>> extends Stage<SELF> {
MyCustomerBuilder customerBuilder;
public SELF a_customer() {
customerBuilder = new MyCustomerBuilder();
return self();
}
public SELF name( String name ) {
customerBuilder.name(name);
return self();
}
}
Desired Situation:
Stage:
public MyStage<SELF extends MyStage<?>> extends Stage<SELF> {
MyCustomerBuilder customerBuilder;
public MyCustomerBuilder a_customer() {
return new MyCustomerBuilder();
}
}
Scenario:
@Test
public void customers_can_be_built() {
given().a_customer()
.with().name("John");
}
Open Questions
Should Substages have lifecycle methods? How could this be realized?
How to get back to the parent stage in the Scenario?
Example:
@Test
public void customers_can_be_built() {
given().a_customer()
.with().name("John").end(); // end() must return parent stage
.and().a_product();
}
How should substages be created?
This feature would be brilliant. For the moment one of the things we're thinking about is this:
given().a_customer(customer().withName("John"))
where
MyStage.java
public MyStage a_customer(MyCustomerBuilder myCustomerBuilder) {
this.customer = myCustomerBuilder.build();
return self();
}
...
MyCustomerBuilder.java
public static MyCustomerBuilder customer() {
return new MyCustomerBuilder();
}
public MyCustomerBuilder withName(String name) {
this.name = name;
description.append("with name "+name); //or work out the method name with reflection
return this;
}
@Override
public String toString() {
return description;
}
and every method in MyCustomerBuilder appends something to a StringBuilder and then the toString() method collates it to be displayed in the report. It's a bit rudimentary but looks nice.
The problem is in parametrised tests, where the whole builder is put in the table as a massive single parameter
Hi the #202 is nice but you disabled intercepting methods of nested stages. Can we have an option to not disable description of substage methods, so that we dont have to maintain a description variable and also a toString method just for this purpose?
BTW, we will take care of adding MyCustomerBuilder also as a stage by calling the addStage() api. Currently, if we do that it does not work because the intercepting does not work