Search in sources :

Example 1 with Bar

use of spoon.test.api.testclasses.Bar in project spoon by INRIA.

the class APITest method testAddProcessorMethodInSpoonAPI.

@Test
public void testAddProcessorMethodInSpoonAPI() throws Exception {
    final SpoonAPI launcher = new Launcher();
    launcher.addInputResource("./src/test/java/spoon/test/api/testclasses");
    launcher.setSourceOutputDirectory("./target/spooned");
    final AwesomeProcessor processor = new AwesomeProcessor();
    launcher.addProcessor(processor);
    launcher.run();
    assertEquals(1, processor.getElements().size());
    final CtClass<Bar> actual = processor.getElements().get(0);
    assertEquals(2, actual.getMethods().size());
    assertNotNull(actual.getMethodsByName("prepareMojito").get(0));
    assertNotNull(actual.getMethodsByName("makeMojito").get(0));
}
Also used : Bar(spoon.test.api.testclasses.Bar) Launcher(spoon.Launcher) SpoonAPI(spoon.SpoonAPI) Test(org.junit.Test)

Example 2 with Bar

use of spoon.test.api.testclasses.Bar in project spoon by INRIA.

the class APITest method testInvalidateCacheOfCompiler.

@Test
public void testInvalidateCacheOfCompiler() throws Exception {
    final Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/api/testclasses/Bar.java");
    spoon.setSourceOutputDirectory("./target/api");
    spoon.getEnvironment().setNoClasspath(true);
    spoon.run();
    assertTrue(spoon.getModelBuilder().compile());
    final CtClass<Bar> aClass = spoon.getFactory().Class().get(Bar.class);
    final CtMethod aMethod = spoon.getFactory().Core().createMethod();
    aMethod.setSimpleName("foo");
    aMethod.setType(spoon.getFactory().Type().BOOLEAN_PRIMITIVE);
    aMethod.setBody(spoon.getFactory().Core().createBlock());
    aClass.addMethod(aMethod);
    assertFalse(spoon.getModelBuilder().compile());
    aClass.removeMethod(aMethod);
    assertTrue(spoon.getModelBuilder().compile());
}
Also used : Bar(spoon.test.api.testclasses.Bar) Launcher(spoon.Launcher) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Launcher (spoon.Launcher)2 Bar (spoon.test.api.testclasses.Bar)2 SpoonAPI (spoon.SpoonAPI)1 CtMethod (spoon.reflect.declaration.CtMethod)1