Search in sources :

Example 1 with Foo

use of spoon.test.trycatch.testclasses.Foo in project spoon by INRIA.

the class TryCatchTest method testMultiTryCatchWithCustomExceptions.

@Test
public void testMultiTryCatchWithCustomExceptions() throws Exception {
    final Launcher launcher = new Launcher();
    final SpoonModelBuilder compiler = launcher.createCompiler();
    compiler.addInputSource(new File("./src/test/java/spoon/test/trycatch/testclasses/"));
    compiler.build();
    Factory factory = compiler.getFactory();
    final CtClass<?> foo = (CtClass<?>) factory.Type().get(Foo.class);
    final CtCatch ctCatch = foo.getElements(new AbstractFilter<CtCatch>(CtCatch.class) {

        @Override
        public boolean matches(CtCatch element) {
            return true;
        }
    }).get(0);
    final String expected = "catch (spoon.test.trycatch.testclasses.internal.MyException | spoon.test.trycatch.testclasses.internal.MyException2 ignore) {" + System.lineSeparator() + "}";
    assertEquals(expected, ctCatch.toString());
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) CtClass(spoon.reflect.declaration.CtClass) AbstractFilter(spoon.reflect.visitor.filter.AbstractFilter) Foo(spoon.test.trycatch.testclasses.Foo) Launcher(spoon.Launcher) ModelUtils.createFactory(spoon.testing.utils.ModelUtils.createFactory) Factory(spoon.reflect.factory.Factory) CtCatch(spoon.reflect.code.CtCatch) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 SpoonModelBuilder (spoon.SpoonModelBuilder)1 CtCatch (spoon.reflect.code.CtCatch)1 CtClass (spoon.reflect.declaration.CtClass)1 Factory (spoon.reflect.factory.Factory)1 AbstractFilter (spoon.reflect.visitor.filter.AbstractFilter)1 Foo (spoon.test.trycatch.testclasses.Foo)1 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)1