BMScripts scriptsAnnotation = method.getAnnotation(BMScripts.class);
if (scriptsAnnotation == null) {
return statement;
} else {
BMScript[] scriptAnnotations = scriptsAnnotation.scripts();
Statement result = statement;
// 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 Statement nextStatement = result;
// ensure we always have an actual name here instead of null because using
// null will clash with the name used for looking up rules when the clas
// has a BMRules annotation
final String name = computeBMRulesName(scriptAnnotation.value(), method);
final String loadDirectory = computeLoadDirectory(scriptAnnotation.dir(), this.loadDirectory);
result = new Statement() {
public void evaluate() throws Throwable {
BMUnit.loadScriptFile(testKlazz, name, loadDirectory);
try {
nextStatement.evaluate();
} finally {
BMUnit.unloadScriptFile(testKlazz, name);
}
}
};