001: package abbot.script;
002:
003: import java.lang.reflect.Method;
004:
005: import junit.extensions.abbot.*;
006:
007: public class CallTest extends ResolverFixture {
008:
009: private class TargetedCall extends Call {
010: public Object target;
011:
012: public TargetedCall(Resolver r, String d, String c, String m,
013: String[] args) {
014: super (r, d, c, m, args);
015: }
016:
017: protected Object getTarget(Method m) throws Throwable {
018: return target = getTargetClass().newInstance();
019: }
020: }
021:
022: public void testResolveInheritedMethods() throws Throwable {
023: TargetedCall call = new TargetedCall(getResolver(),
024: "Test Call", CallTestClass.class.getName(),
025: "whichClass", new String[0]);
026:
027: call.run();
028: assertEquals("Wrong method invoked for whichClass",
029: CallTestClass.class.getName(),
030: ((CallTestClass) call.target).which);
031: }
032:
033: public void testResolveDuplicateMethods() throws Throwable {
034: TargetedCall call = new TargetedCall(getResolver(),
035: "Test Call", CallTestClass.class.getName(),
036: "someMethodDuplicated", new String[] { "1" });
037: // Invoke the int version
038: call.run();
039: // Invoke the string version
040: call.setArguments("string arg");
041: call.run();
042: }
043:
044: public void testCall() throws Throwable {
045: TargetedCall call = new TargetedCall(getResolver(),
046: "Test Call", CallTestClass.class.getName(),
047: "someMethod", new String[0]);
048: call.run();
049: assertTrue("Flag should be set after to invocation",
050: ((CallTestClass) call.target).derivedWasCalled);
051: }
052:
053: public void testReturnType() throws Throwable {
054: TargetedCall call = new TargetedCall(getResolver(),
055: "Test Call", CallTestClass.class.getName(),
056: "intReturningMethod", new String[0]);
057: call.run();
058: assertTrue("Flag should be set after to invocation",
059: ((CallTestClass) call.target).derivedWasCalled);
060: }
061:
062: public static class CallTestBase {
063: public boolean baseWasCalled = false;
064: public String which = null;
065:
066: public String whichClass() {
067: return which = CallTestBase.class.getName();
068: }
069: }
070:
071: public static class CallTestClass extends CallTestBase {
072: public boolean derivedWasCalled = false;
073:
074: public void someMethod() {
075: derivedWasCalled = true;
076: }
077:
078: public int someMethodDuplicated(int arg) {
079: return 0;
080: }
081:
082: public String someMethodDuplicated(String arg) {
083: return "String";
084: }
085:
086: public Object someMethodDuplicated(Object arg) {
087: return new Object();
088: }
089:
090: public int intReturningMethod() {
091: derivedWasCalled = true;
092: return 1;
093: }
094:
095: public String whichClass() {
096: return which = CallTestClass.class.getName();
097: }
098: }
099:
100: public static void main(String[] args) {
101: TestHelper.runTests(args, CallTest.class);
102: }
103: }
|