InsertableConstructorBuilder { public StateTargetClassSet insertIntoClass(Class<?> clazzToInsertInto) throws NotFoundException { this.classToInsertInto = ClassPool.getDefault().get(clazzToInsertInto.getName()); return new StateTargetClassSet(); } InsertableConstructorBuilder(AfterBurner afterBurner); StateTargetClassSet insertIntoClass(Class<?> clazzToInsertInto); StateTargetClassSet insertIntoClass(CtClass clazzToInsertInto);  }
@Test public void testDoIt_calls_afterburner() throws CannotCompileException, AfterBurnerImpossibleException, NotFoundException { afterBurnerMock = EasyMock.createMock(AfterBurner.class); afterBurnerMock.insertConstructor((InsertableConstructor) EasyMock.anyObject()); EasyMock.replay(afterBurnerMock); builder = new InsertableConstructorBuilder(afterBurnerMock); CtClass classToInsertInto = CtClass.intType; String body = ""; builder .insertIntoClass(classToInsertInto) .withBody(body) .doIt(); EasyMock.verify(afterBurnerMock); }
@Test public void testCheckAllFields_should_succeed_with_all_fields_defined() throws AfterBurnerImpossibleException { CtClass classToInsertInto = CtClass.intType; String body = ""; InsertableConstructor constructor = builder .insertIntoClass(classToInsertInto) .withBody(body) .createInsertableConstructor(); assertNotNull(constructor); assertEquals(classToInsertInto, constructor.getClassToInsertInto()); assertEquals(body, constructor.getConstructorBody(null)); assertTrue(constructor.acceptParameters(null)); }
@Test public void testCheckAllFields_should_succeed_with_all_fields_defined_using_class() throws Exception { String body = ""; Class<?> classToInsertInto = String.class; ; InsertableConstructor constructor = builder .insertIntoClass(classToInsertInto ) .withBody(body) .createInsertableConstructor(); assertNotNull(constructor); assertEquals(ClassPool.getDefault().get(String.class.getName()), constructor.getClassToInsertInto()); assertEquals(body, constructor.getConstructorBody(null)); assertTrue(constructor.acceptParameters(null)); }