Search in sources :

Example 6 with AbstractTostada

use of spoon.test.filters.testclasses.AbstractTostada in project spoon by INRIA.

the class FilterTest method testOverridingMethodFromAbstractClass.

@Test
public void testOverridingMethodFromAbstractClass() throws Exception {
    // contract: When we declare an abstract method on an abstract class, we must return all overriding
    // methods in sub classes and anonymous classes.
    final Launcher launcher = new Launcher();
    launcher.setArgs(new String[] { "--output-type", "nooutput" });
    launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
    launcher.run();
    final CtClass<AbstractTostada> aClass = launcher.getFactory().Class().get(AbstractTostada.class);
    TreeSet<CtMethod<?>> ts = new TreeSet<CtMethod<?>>(new DeepRepresentationComparator());
    List<CtMethod<?>> elements = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aClass.getMethodsByName("prepare").get(0)));
    ts.addAll(elements);
    assertEquals(5, elements.size());
    final List<CtMethod<?>> overridingMethods = Arrays.asList(ts.toArray(new CtMethod[0]));
    assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(3).getParent(CtClass.class).getQualifiedName());
    assertEquals(Antojito.class, overridingMethods.get(1).getParent(CtClass.class).getActualClass());
    assertEquals(SubTostada.class, overridingMethods.get(2).getParent(CtClass.class).getActualClass());
    assertEquals("spoon.test.filters.testclasses.Tostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
    assertEquals(Tostada.class, overridingMethods.get(4).getParent(CtClass.class).getActualClass());
}
Also used : AbstractTostada(spoon.test.filters.testclasses.AbstractTostada) DeepRepresentationComparator(spoon.support.comparator.DeepRepresentationComparator) TreeSet(java.util.TreeSet) Launcher(spoon.Launcher) CtMethod(spoon.reflect.declaration.CtMethod) OverridingMethodFilter(spoon.reflect.visitor.filter.OverridingMethodFilter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Launcher (spoon.Launcher)6 AbstractTostada (spoon.test.filters.testclasses.AbstractTostada)6 CtMethod (spoon.reflect.declaration.CtMethod)4 ITostada (spoon.test.filters.testclasses.ITostada)4 SubTostada (spoon.test.filters.testclasses.SubTostada)4 Tostada (spoon.test.filters.testclasses.Tostada)4 OverriddenMethodFilter (spoon.reflect.visitor.filter.OverriddenMethodFilter)2 OverridingMethodFilter (spoon.reflect.visitor.filter.OverridingMethodFilter)2 TreeSet (java.util.TreeSet)1 CtType (spoon.reflect.declaration.CtType)1 OverriddenMethodQuery (spoon.reflect.visitor.filter.OverriddenMethodQuery)1 DeepRepresentationComparator (spoon.support.comparator.DeepRepresentationComparator)1 SubInheritanceHierarchyResolver (spoon.support.visitor.SubInheritanceHierarchyResolver)1