Search in sources :

Example 1 with TemplateWithFieldsAndMethods_Wrong

use of spoon.test.template.testclasses.constructors.TemplateWithFieldsAndMethods_Wrong in project spoon by INRIA.

the class TemplateTest method testTemplateWithWrongUsedStringParam.

@Test
public void testTemplateWithWrongUsedStringParam() throws Exception {
    Launcher spoon = new Launcher();
    Factory factory = spoon.createFactory();
    spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/java/spoon/test/template/testclasses/constructors/C1.java"), SpoonResourceHelper.resources("./src/test/java/spoon/test/template/testclasses/constructors/TemplateWithFieldsAndMethods_Wrong.java")).build();
    CtClass<?> c1 = factory.Class().get(C1.class);
    new TemplateWithFieldsAndMethods_Wrong("testparam").apply(c1);
    CtMethod<?> m = c1.getMethod("methodToBeInserted");
    assertNotNull(m);
    // contract: printing of code which contains invalid field reference, fails with nice exception
    try {
        m.getBody().getStatement(0).toString();
    } catch (SpoonException e) {
        assertTrue("The error description doesn't contain name of invalid field. There is:\n" + e.getMessage(), e.getMessage().indexOf("testparam") >= 0);
    }
}
Also used : SpoonException(spoon.SpoonException) TemplateWithFieldsAndMethods_Wrong(spoon.test.template.testclasses.constructors.TemplateWithFieldsAndMethods_Wrong) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 SpoonException (spoon.SpoonException)1 Factory (spoon.reflect.factory.Factory)1 TemplateWithFieldsAndMethods_Wrong (spoon.test.template.testclasses.constructors.TemplateWithFieldsAndMethods_Wrong)1