// note we iterate down here because we generate statements by wraparound
// which means the the outer statement gets executed first
for (int i = scriptAnnotations.length; i> 0; i--) {
BMScript scriptAnnotation= scriptAnnotations[i - 1];
final String name = BMRunnerUtil.computeBMScriptName(scriptAnnotation.value());
final RunNotifier fnotifier = notifier;
final Description description = Description.createTestDescription(testKlazz, getName(), scriptAnnotation);
final String loadDirectory = BMRunnerUtil.normaliseLoadDirectory(scriptAnnotation);
final Statement nextStatement = result;
result = new Statement() {
public void evaluate() throws Throwable {
try {
BMUnit.loadScriptFile(testKlazz, name, loadDirectory);
try {
nextStatement.evaluate();
} finally {
try {
BMUnit.unloadScriptFile(testKlazz, name);
} catch (Exception e) {
fnotifier.fireTestFailure(new Failure(description, e));
}
}
} catch (Exception e) {
fnotifier.fireTestFailure(new Failure(description, e));
}
}
};
}
return result;