use of com.github.stephanenicolas.afterburner.inserts.SimpleInsertableMethod in project afterburner by stephanenicolas.
the class AfterBurnerTest method testInsertMethod_after.
@Test
public void testInsertMethod_after() throws Exception {
// GIVEN
target.addMethod(CtNewMethod.make("public void bar() { }", target));
target.addMethod(CtNewMethod.make("public boolean foo() { bar(); return false; }", target));
target.addField(new CtField(CtClass.intType, "foo", target));
InsertableMethod insertableMethod = new SimpleInsertableMethod(target, "foo", null, "bar", "foo = 2;", null);
// WHEN
afterBurner.addOrInsertMethod(insertableMethod);
// THEN
targetClass = target.toClass();
targetInstance = targetClass.newInstance();
assertHasFooMethodWithReturnValue(target, false);
assertHasFooFieldWithValue(target, 2);
}
use of com.github.stephanenicolas.afterburner.inserts.SimpleInsertableMethod in project afterburner by stephanenicolas.
the class AfterBurnerTest method testInsertMethod_before.
@Test
public void testInsertMethod_before() throws Exception {
// GIVEN
target.addMethod(CtNewMethod.make("public void bar() { }", target));
target.addMethod(CtNewMethod.make("public boolean foo() { bar(); return false; }", target));
target.addField(new CtField(CtClass.intType, "foo", target));
InsertableMethod insertableMethod = new SimpleInsertableMethod(target, "foo", "bar", null, "foo = 2;", null);
// WHEN
afterBurner.addOrInsertMethod(insertableMethod);
// THEN
targetClass = target.toClass();
targetInstance = targetClass.newInstance();
assertHasFooMethodWithReturnValue(target, false);
assertHasFooFieldWithValue(target, 2);
}
use of com.github.stephanenicolas.afterburner.inserts.SimpleInsertableMethod in project afterburner by stephanenicolas.
the class AfterBurnerTest method testAddMethod.
@Test
public void testAddMethod() throws Exception {
// GIVEN
InsertableMethod insertableMethod = new SimpleInsertableMethod(target, "foo", null, null, null, "public boolean foo() { return true; }");
// WHEN
afterBurner.addOrInsertMethod(insertableMethod);
// THEN
targetClass = target.toClass();
targetInstance = targetClass.newInstance();
assertHasFooMethodWithReturnValue(target, true);
}
use of com.github.stephanenicolas.afterburner.inserts.SimpleInsertableMethod in project afterburner by stephanenicolas.
the class AfterBurnerTest method testInsertMethod_not_before_not_after.
@Test(expected = AfterBurnerImpossibleException.class)
public void testInsertMethod_not_before_not_after() throws Exception {
// GIVEN
target.addMethod(CtNewMethod.make("public void bar() { }", target));
target.addMethod(CtNewMethod.make("public boolean foo() { bar(); return false; }", target));
target.addField(new CtField(CtClass.intType, "foo", target));
InsertableMethod insertableMethod = new SimpleInsertableMethod(target, "foo", null, null, "foo = 2;", null);
// WHEN
afterBurner.addOrInsertMethod(insertableMethod);
// THEN
fail();
}
Aggregations