1
|
|
package abbot.script;
|
2
|
|
|
3
|
|
import java.lang.reflect.Method;
|
4
|
|
|
5
|
|
import junit.extensions.abbot.*;
|
6
|
|
|
7
|
|
public class CallTest extends ResolverFixture {
|
8
|
|
|
9
|
|
private class TargetedCall extends Call {
|
10
|
|
public Object target;
|
11
|
4
|
public TargetedCall(Resolver r, String d,
|
12
|
|
String c, String m, String[] args) {
|
13
|
4
|
super(r, d, c, m, args);
|
14
|
|
}
|
15
|
10
|
protected Object getTarget(Method m) throws Throwable {
|
16
|
10
|
return target = getTargetClass().newInstance();
|
17
|
|
}
|
18
|
|
}
|
19
|
|
|
20
|
1
|
public void testResolveInheritedMethods() throws Throwable {
|
21
|
1
|
TargetedCall call =
|
22
|
|
new TargetedCall(getResolver(), "Test Call",
|
23
|
|
CallTestClass.class.getName(),
|
24
|
|
"whichClass", new String[0]);
|
25
|
|
|
26
|
1
|
call.run();
|
27
|
1
|
assertEquals("Wrong method invoked for whichClass",
|
28
|
|
CallTestClass.class.getName(),
|
29
|
|
((CallTestClass)call.target).which);
|
30
|
|
}
|
31
|
|
|
32
|
1
|
public void testResolveDuplicateMethods() throws Throwable {
|
33
|
1
|
TargetedCall call =
|
34
|
|
new TargetedCall(getResolver(), "Test Call",
|
35
|
|
CallTestClass.class.getName(),
|
36
|
|
"someMethodDuplicated",
|
37
|
|
new String[] { "1" });
|
38
|
|
|
39
|
1
|
call.run();
|
40
|
1
|
call.setArguments("string arg");
|
41
|
1
|
call.run();
|
42
|
|
}
|
43
|
|
|
44
|
1
|
public void testCall() throws Throwable {
|
45
|
1
|
TargetedCall call =
|
46
|
|
new TargetedCall(getResolver(), "Test Call",
|
47
|
|
CallTestClass.class.getName(),
|
48
|
|
"someMethod", new String[0]);
|
49
|
1
|
call.run();
|
50
|
1
|
assertTrue("Flag should be set after to invocation",
|
51
|
|
((CallTestClass)call.target).derivedWasCalled);
|
52
|
|
}
|
53
|
|
|
54
|
1
|
public void testReturnType() throws Throwable {
|
55
|
1
|
TargetedCall call = new TargetedCall(getResolver(), "Test Call",
|
56
|
|
CallTestClass.class.getName(),
|
57
|
|
"intReturningMethod", new String[0]);
|
58
|
1
|
call.run();
|
59
|
1
|
assertTrue("Flag should be set after to invocation",
|
60
|
|
((CallTestClass)call.target).derivedWasCalled);
|
61
|
|
}
|
62
|
|
|
63
|
|
public static class CallTestBase {
|
64
|
|
public boolean baseWasCalled = false;
|
65
|
|
public String which = null;
|
66
|
0
|
public String whichClass() {
|
67
|
0
|
return which = CallTestBase.class.getName();
|
68
|
|
}
|
69
|
|
}
|
70
|
|
|
71
|
|
public static class CallTestClass extends CallTestBase {
|
72
|
|
public boolean derivedWasCalled = false;
|
73
|
1
|
public void someMethod() {
|
74
|
1
|
derivedWasCalled = true;
|
75
|
|
}
|
76
|
0
|
public int someMethodDuplicated(int arg) {
|
77
|
0
|
return 0;
|
78
|
|
}
|
79
|
2
|
public String someMethodDuplicated(String arg) {
|
80
|
2
|
return "String";
|
81
|
|
}
|
82
|
0
|
public Object someMethodDuplicated(Object arg) {
|
83
|
0
|
return new Object();
|
84
|
|
}
|
85
|
1
|
public int intReturningMethod() {
|
86
|
1
|
derivedWasCalled = true;
|
87
|
1
|
return 1;
|
88
|
|
}
|
89
|
1
|
public String whichClass() {
|
90
|
1
|
return which = CallTestClass.class.getName();
|
91
|
|
}
|
92
|
|
}
|
93
|
|
|
94
|
4
|
public CallTest(String name) { super(name); }
|
95
|
|
|
96
|
0
|
public static void main(String[] args) {
|
97
|
0
|
TestHelper.runTests(args, CallTest.class);
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|
101
|
|
|