use of com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor in project afterburner by stephanenicolas.
the class AfterBurnerTest method testInsertConstructor_with_no_constructor.
@Test(expected = AfterBurnerImpossibleException.class)
public void testInsertConstructor_with_no_constructor() throws Exception {
// GIVEN
target.addConstructor(CtNewConstructor.make("public Target() {}", target));
target.addField(new CtField(CtClass.intType, "foo", target));
InsertableConstructor insertableConstructor = new SimpleInsertableConstructor(target, "foo = 2;", false);
// WHEN
afterBurner.insertConstructor(insertableConstructor);
// THEN
fail();
}
use of com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor in project afterburner by stephanenicolas.
the class AfterBurnerTest method testInsertConstructor.
@Test
public void testInsertConstructor() throws Exception {
// GIVEN
target.addConstructor(CtNewConstructor.make("public Target() {}", target));
target.addField(new CtField(CtClass.intType, "foo", target));
InsertableConstructor insertableConstructor = new SimpleInsertableConstructor(target, "foo = 2;", true);
// WHEN
afterBurner.insertConstructor(insertableConstructor);
// THEN
targetClass = target.toClass();
targetInstance = targetClass.newInstance();
assertHasFooFieldWithValue(target, 2);
}
Aggregations