OK, so I had to try myself, then...
When.the(quant).attempts_to(view_backtest_results());
When.the(quant).attempts_to(view_backtest_results().with_instrument(FTSE).with_currency(GBP).with_bartype(Hourly));
When.the(admin).attempts_to(view_backtest_results().with_instrument(FTSE).with_currency(GBP).with_bartype(Hourly).with_username(QUANT));
When.the(quant).attempts_to(view_backtest_results().with_instrument(FTSE).with_currency(GBP).with_bartype(Hourly).with_username(QUANT).with_start_date(utc(2010, 01, 30)).with_end_date(utc(2010, 01, 30)));
I don't mind the verbosity too much (although there are other variants in tests that I haven't converted yet), and I like the common view_backtest_results() method. And, especially, it removes some duplication from the old view_backtest_results_with_XXX() methods.
I do find it annoying having to introduce not only a special action builder, but also a method that does nothing but instantiate it. I don't see how I can make it simpler, though.
private ViewBacktestResults view_backtest_results() {
return new ViewBacktestResults();
}
private final class ViewBacktestResults implements Action<Object, Quant> {
@Override
public void performFor(Quant actor) {
String url = ... ; // assemble parameters
actor.tool().logInThenBeginAt(actor.getUserName(), actor.getPassword(), url);
}
// 50 lines of code of with_... methods
}
Ideas to make that simpler:
- make ViewBacktestResults a public static class. That allows me to statically import the class (import static MyTest.ViewBacktestResults.*), so I can move the view_backtest_results() method in it. Drawback: it makes ViewBacktestResults visible from other classes and also Eclipse won't tell me when I stop referring to that class.
- instanciate a ViewBacktestResults as a test field. I would then use it like this: When.the(quant).attempts_to(view_backtest_results.with_instrument(FTSE).with_currency(GBP).with_bartype(Hourly)). I don't like the idea of adding more things in the fields, but that might be a good compromise.
Eric