use of spoon.test.replace.testclasses.Tacos in project spoon by INRIA.
the class ReplaceTest method testReplaceExecutableReferenceByAnotherOne.
@Test
public void testReplaceExecutableReferenceByAnotherOne() throws Exception {
// contract: replace an executable reference to another one in an invocation.
final Factory factory = build(Tacos.class);
final CtType<Tacos> aTacos = factory.Type().get(Tacos.class);
final CtInvocation inv = aTacos.getMethodsByName("m3").get(0).getElements(new TypeFilter<>(CtInvocation.class)).get(0);
final CtExecutableReference oldExecutable = inv.getExecutable();
final CtExecutableReference<Object> newExecutable = factory.Executable().createReference("void java.io.PrintStream#print(java.lang.String)");
assertSame(oldExecutable, inv.getExecutable());
oldExecutable.replace(newExecutable);
assertSame(newExecutable, inv.getExecutable());
assertEquals("print(java.lang.String)", inv.getExecutable().toString());
assertEquals("java.io.PrintStream", inv.getExecutable().getDeclaringType().toString());
// contract: replace of single value by multiple values in single value field must fail
try {
newExecutable.replace(Arrays.asList(oldExecutable, null));
fail();
} catch (InvalidReplaceException e) {
// OK
}
}
use of spoon.test.replace.testclasses.Tacos in project spoon by INRIA.
the class ParentTest method testParentOfCtExecutableReference.
@Test
public void testParentOfCtExecutableReference() throws Exception {
// contract: parent of a executable reference is the element which call getExecutable().
final Factory factory = build(Tacos.class);
final CtType<Tacos> aTacos = factory.Type().get(Tacos.class);
final CtInvocation inv = aTacos.getMethodsByName("m3").get(0).getElements(new TypeFilter<>(CtInvocation.class)).get(0);
final CtExecutableReference oldExecutable = inv.getExecutable();
assertNotNull(oldExecutable.getParent());
assertEquals(inv, oldExecutable.getParent());
}
Aggregations