use of com.github.stephanenicolas.afterburner.inserts.InsertableConstructor 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.InsertableConstructor in project afterburner by stephanenicolas.
the class InsertableConstructorBuilderTest method testCheckAllFields_should_succeed_with_all_fields_defined_using_class.
@Test
public void testCheckAllFields_should_succeed_with_all_fields_defined_using_class() throws Exception {
//GIVEN
String body = "";
Class<?> classToInsertInto = String.class;
;
//WHEN
InsertableConstructor constructor = builder.insertIntoClass(classToInsertInto).withBody(body).createInsertableConstructor();
//THEN
assertNotNull(constructor);
assertEquals(ClassPool.getDefault().get(String.class.getName()), constructor.getClassToInsertInto());
assertEquals(body, constructor.getConstructorBody(null));
assertTrue(constructor.acceptParameters(null));
}
use of com.github.stephanenicolas.afterburner.inserts.InsertableConstructor 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);
}
use of com.github.stephanenicolas.afterburner.inserts.InsertableConstructor in project afterburner by stephanenicolas.
the class InsertableConstructorBuilderTest method testCheckAllFields_should_succeed_with_all_fields_defined.
@Test
public void testCheckAllFields_should_succeed_with_all_fields_defined() throws AfterBurnerImpossibleException {
//GIVEN
CtClass classToInsertInto = CtClass.intType;
String body = "";
//WHEN
InsertableConstructor constructor = builder.insertIntoClass(classToInsertInto).withBody(body).createInsertableConstructor();
//THEN
assertNotNull(constructor);
assertEquals(classToInsertInto, constructor.getClassToInsertInto());
assertEquals(body, constructor.getConstructorBody(null));
assertTrue(constructor.acceptParameters(null));
}
Aggregations