use of spoon.test.filters.testclasses.Tostada in project spoon by INRIA.
the class FilterTest method testOverridingMethodFromSubClassOfAbstractClass.
@Test
public void testOverridingMethodFromSubClassOfAbstractClass() throws Exception {
// contract: When we ask all overriding methods from an overriding method, we must returns all methods
// below and not above (including the 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 CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
TreeSet<CtMethod<?>> ts = new TreeSet<CtMethod<?>>(new DeepRepresentationComparator());
List<CtMethod<?>> elements = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aTostada.getMethodsByName("prepare").get(0)));
ts.addAll(elements);
final List<CtMethod<?>> overridingMethods = Arrays.asList(ts.toArray(new CtMethod[0]));
assertEquals(3, overridingMethods.size());
assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(2).getParent(CtClass.class).getQualifiedName());
assertEquals(SubTostada.class, overridingMethods.get(1).getParent(CtClass.class).getActualClass());
assertEquals("spoon.test.filters.testclasses.Tostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
final CtClass<SubTostada> aSubTostada = launcher.getFactory().Class().get(SubTostada.class);
assertEquals(0, Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aSubTostada.getMethodsByName("prepare").get(0))).size());
}
use of spoon.test.filters.testclasses.Tostada in project spoon by INRIA.
the class FilterTest method testOverridingMethodFromSubClassOfInterface.
@Test
public void testOverridingMethodFromSubClassOfInterface() throws Exception {
// contract: When we ask all overriding methods from an overriding method, we must returns all methods
// below and not above (including the 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 CtClass<AbstractTostada> anAbstractTostada = launcher.getFactory().Class().get(AbstractTostada.class);
List<CtMethod<?>> overridingMethods = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(anAbstractTostada.getMethodsByName("make").get(0)));
assertEquals(2, overridingMethods.size());
assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
assertEquals(Tostada.class, overridingMethods.get(1).getParent(CtClass.class).getActualClass());
final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
overridingMethods = Query.getElements(launcher.getFactory(), new OverridingMethodFilter(aTostada.getMethodsByName("make").get(0)));
assertEquals(1, overridingMethods.size());
assertEquals("spoon.test.filters.testclasses.AbstractTostada$1", overridingMethods.get(0).getParent(CtClass.class).getQualifiedName());
}
use of spoon.test.filters.testclasses.Tostada 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.Tostada in project spoon by INRIA.
the class FilterTest method testOverriddenMethodFromSubClassOfInterface.
@Test
public void testOverriddenMethodFromSubClassOfInterface() throws Exception {
// contract: When we ask all overridden methods from an overriding method, we must returns all methods
// above and not below.
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> anAbstractTostada = launcher.getFactory().Class().get(AbstractTostada.class);
final List<CtMethod<?>> overriddenMethods = Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(anAbstractTostada.getMethodsByName("make").get(0)));
assertEquals(1, overriddenMethods.size());
assertEquals(ITostada.class, overriddenMethods.get(0).getParent(CtInterface.class).getActualClass());
final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
OverriddenMethodFilter filter = new OverriddenMethodFilter(aTostada.getMethodsByName("make").get(0));
final List<CtMethod<?>> overriddenMethodsFromSub = Query.getElements(launcher.getFactory(), filter);
assertEquals(2, overriddenMethodsFromSub.size());
assertEquals(AbstractTostada.class, overriddenMethodsFromSub.get(0).getParent(CtType.class).getActualClass());
assertEquals(ITostada.class, overriddenMethodsFromSub.get(1).getParent(CtType.class).getActualClass());
}
use of spoon.test.filters.testclasses.Tostada in project spoon by INRIA.
the class FilterTest method testOverriddenMethodsFromSubClassOfAbstractClass.
@Test
public void testOverriddenMethodsFromSubClassOfAbstractClass() throws Exception {
// contract: When we ask all overridden methods from an overriding method, we must returns all methods
// above and not below.
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<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
final List<CtMethod<?>> overridenMethods = Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(aTostada.getMethodsByName("prepare").get(0)));
assertEquals(1, overridenMethods.size());
assertEquals(AbstractTostada.class, overridenMethods.get(0).getParent(CtClass.class).getActualClass());
final CtClass<SubTostada> aSubTostada = launcher.getFactory().Class().get(SubTostada.class);
final List<CtMethod<?>> overridenMethodsFromSub = Query.getElements(launcher.getFactory(), new OverriddenMethodFilter(aSubTostada.getMethodsByName("prepare").get(0)));
assertEquals(2, overridenMethodsFromSub.size());
assertEquals(AbstractTostada.class, overridenMethodsFromSub.get(0).getParent(CtClass.class).getActualClass());
assertEquals(Tostada.class, overridenMethodsFromSub.get(1).getParent(CtClass.class).getActualClass());
}
Aggregations