Search in sources :

Example 1 with ITostada

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

the class FilterTest method testgetTopDefinitions.

@Test
public void testgetTopDefinitions() throws Exception {
    // contract: getTopDefinitions returns the correct number of definitions
    final Launcher launcher = new Launcher();
    launcher.setArgs(new String[] { "--output-type", "nooutput" });
    launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
    launcher.run();
    // start with ToStatda
    final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
    List<CtMethod<?>> methods;
    methods = orderByName(aTostada.getMethodsByName("make").get(0).getTopDefinitions());
    assertEquals(2, methods.size());
    assertEquals("AbstractTostada", methods.get(0).getDeclaringType().getSimpleName());
    assertEquals("ITostada", methods.get(1).getDeclaringType().getSimpleName());
    methods = orderByName(aTostada.getMethodsByName("prepare").get(0).getTopDefinitions());
    assertEquals(1, methods.size());
    assertEquals("AbstractTostada", methods.get(0).getDeclaringType().getSimpleName());
    methods = orderByName(aTostada.getMethodsByName("toString").get(0).getTopDefinitions());
    assertEquals(1, methods.size());
    assertEquals("Object", methods.get(0).getDeclaringType().getSimpleName());
    methods = orderByName(aTostada.getMethodsByName("honey").get(0).getTopDefinitions());
    assertEquals(2, methods.size());
    assertEquals("AbstractTostada", methods.get(0).getDeclaringType().getSimpleName());
    assertEquals("Honey", methods.get(1).getDeclaringType().getSimpleName());
    methods = orderByName(aTostada.getMethodsByName("foo").get(0).getTopDefinitions());
    assertEquals(0, methods.size());
}
Also used : Tostada(spoon.test.filters.testclasses.Tostada) ITostada(spoon.test.filters.testclasses.ITostada) AbstractTostada(spoon.test.filters.testclasses.AbstractTostada) SubTostada(spoon.test.filters.testclasses.SubTostada) Launcher(spoon.Launcher) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 2 with ITostada

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

the class FilterTest method testOverriddenMethodFromInterface.

@Test
public void testOverriddenMethodFromInterface() throws Exception {
    // contract: When we declare a method in an interface, we must return an empty list
    // when we ask all overridden methods from this declaration.
    final Launcher launcher = new Launcher();
    launcher.setArgs(new String[] { "--output-type", "nooutput" });
    launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
    launcher.run();
    final CtInterface<ITostada> aITostada = launcher.getFactory().Interface().get(ITostada.class);
    OverriddenMethodFilter filter = new OverriddenMethodFilter(aITostada.getMethodsByName("make").get(0));
    List<CtMethod<?>> overridingMethods = Query.getElements(launcher.getFactory(), filter);
    assertEquals(0, overridingMethods.size());
    List<CtMethod> overridingMethods2 = aITostada.getMethodsByName("make").get(0).map(new OverriddenMethodQuery()).list(CtMethod.class);
    assertEquals(0, overridingMethods2.size());
}
Also used : OverriddenMethodFilter(spoon.reflect.visitor.filter.OverriddenMethodFilter) OverriddenMethodQuery(spoon.reflect.visitor.filter.OverriddenMethodQuery) Launcher(spoon.Launcher) ITostada(spoon.test.filters.testclasses.ITostada) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with ITostada

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

the class FilterTest method testOverridingMethodFromInterface.

@Test
public void testOverridingMethodFromInterface() throws Exception {
    // contract: When we declare a method in an interface, 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 CtInterface<ITostada> aITostada = launcher.getFactory().Interface().get(ITostada.class);
    TreeSet<CtMethod<?>> ts = new TreeSet<CtMethod<?>>(new DeepRepresentationComparator());
    List<CtMethod<?>> elements = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aITostada.getMethodsByName("make").get(0)));
    ts.addAll(elements);
    final List<CtMethod<?>> overridingMethods = Arrays.asList(ts.toArray(new CtMethod[0]));
    assertEquals(4, overridingMethods.size());
    assertEquals(AbstractTostada.class, overridingMethods.get(3).getParent(CtType.class).getParent(CtClass.class).getActualClass());
    assertEquals("spoon.test.filters.testclasses.AbstractTostada", overridingMethods.get(1).getParent(CtClass.class).getQualifiedName());
    assertEquals(Tostada.class, overridingMethods.get(0).getParent(CtClass.class).getActualClass());
    assertEquals(Tacos.class, overridingMethods.get(2).getParent(CtClass.class).getActualClass());
}
Also used : DeepRepresentationComparator(spoon.support.comparator.DeepRepresentationComparator) CtType(spoon.reflect.declaration.CtType) TreeSet(java.util.TreeSet) Launcher(spoon.Launcher) ITostada(spoon.test.filters.testclasses.ITostada) CtMethod(spoon.reflect.declaration.CtMethod) OverridingMethodFilter(spoon.reflect.visitor.filter.OverridingMethodFilter) Test(org.junit.Test)

Aggregations

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