use of abs.backend.tests.AbsASTBuilderUtil.ModifyClassModifierNamePredicate in project abstools by abstools.
the class ABSUnitTestCaseBuilder method initialiseDeltaForTestClass.
/**
* Initialise (create if necessary) a delta to modify the given test class.
* In particular it ensures the delta contains a class modifier for the
* given test class and within that modifier, a method modifier for the given
* method name.
*
* @param testClass
* @param setOrAssertMethodForTest
* @return the method block of the method modifier.
*/
Block initialiseDeltaForTestClass(ClassDecl testClass, String setOrAssertMethodForTest) {
String testClassName = testClass.getName();
DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
if (delta == null) {
delta = deltaBuilder.createDeltaFor(testClass);
}
ModifyClassModifier modifier = findClassOrIfaceModifier(delta, ModifyClassModifier.class, new ModifyClassModifierNamePredicate(testClassName));
if (modifier == null) {
modifier = new ModifyClassModifier();
modifier.setName(testClassName);
delta.addModuleModifier(modifier);
}
MethodSig sig = new MethodSig();
sig.setName(setOrAssertMethodForTest);
sig.setReturnType(getUnit());
// add an empty method to be modified
MethodImpl setOrAssertMethodForObjectImpl = new MethodImpl(sig, new Block(), false);
testClass.addMethod(setOrAssertMethodForObjectImpl);
ModifyMethodModifier mmm = new ModifyMethodModifier(setOrAssertMethodForObjectImpl.treeCopyNoTransform());
Block modifyBlock = mmm.getMethodImpl().getBlock();
modifier.addModifier(mmm);
return modifyBlock;
}
Aggregations