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());
}
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());
}
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());
}
Aggregations