Search in sources :

Example 1 with SimpleInsertableConstructor

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();
}
Also used : CtField(javassist.CtField) InsertableConstructor(com.github.stephanenicolas.afterburner.inserts.InsertableConstructor) SimpleInsertableConstructor(com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor) SimpleInsertableConstructor(com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor) Test(org.junit.Test)

Example 2 with SimpleInsertableConstructor

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);
}
Also used : CtField(javassist.CtField) InsertableConstructor(com.github.stephanenicolas.afterburner.inserts.InsertableConstructor) SimpleInsertableConstructor(com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor) SimpleInsertableConstructor(com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor) Test(org.junit.Test)

Aggregations

InsertableConstructor (com.github.stephanenicolas.afterburner.inserts.InsertableConstructor)2 SimpleInsertableConstructor (com.github.stephanenicolas.afterburner.inserts.SimpleInsertableConstructor)2 CtField (javassist.CtField)2 Test (org.junit.Test)2