Debian Codegraph @

test/utils/cache/TestJavaMethod.java

raw
1 package test.utils.cache;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.apache.axis.utils.cache.JavaMethod;
7
8 import java.lang.reflect.Method;
9
10 public class TestJavaMethod extends TestCase
11 {
12 public TestJavaMethod (String name) {
13 super(name);
14 }
15
16 public static Test suite() {
17 return new TestSuite(TestJavaMethod.class);
18 }
19
20 protected void setup() {
21 }
22
23 public void testGetMethodWithVectorMethods()
24 {
25 Class vector = new java.util.Vector().getClass();
26 JavaMethod jmAdd = new JavaMethod(vector, "add");
27 assertNotNull("jmAdd was null", jmAdd);
28
29 Method[] adds = jmAdd.getMethod();
30 assertEquals("There are not 2 add methods as expected, there are " + adds.length, 2, adds.length);
31
32 for (int i = 0; i < adds.length; ++i) {
33 if (adds[i].getReturnType().equals(boolean.class)) {
34 assertEquals("Unexpected boolean add signature",
35 "public synchronized boolean java.util.Vector.add(java.lang.Object)",
36 adds[i].toString());
37 }
38 else {
39 assertEquals("Unexpected void add signature",
40 "public void java.util.Vector.add(int,java.lang.Object)",
41 adds[i].toString());
42 }
43 }
44 }
45
46 public void testGetMethodWithOverloadedStringValueOf()
47 {
48 /* RJB - now that I've removed the numArgs parameter, is this test really testing anything?
49 Class str = new String().getClass();
50 JavaMethod jm = new JavaMethod(str, "valueOf");
51 assertNotNull("JavaMethod is null", jm);
52
53 Method methodWithOneParam = jm.getMethod()[0];
54 assertEquals("Method with one param is not 'valueOf'", "valueOf",methodWithOneParam.getName());
55 Method methodWithThreeParams = jm.getMethod()[0];
56 assertEquals("Method with two params is not 'valueOf'", "valueOf",methodWithThreeParams.getName());
57
58 assertEquals("Method with one param return type is not 'java.lang.String'", "java.lang.String", methodWithOneParam.getReturnType().getName());
59 assertEquals("Method with two parama return type is not 'java.lang.String'", "java.lang.String", methodWithThreeParams.getReturnType().getName());
60
61 boolean gotError = false;
62 try {
63 Method nonceMethod = jm.getMethod()[0]; //should be no valueOf() method with 2 params
64 nonceMethod.getName();
65 }
66 catch (NullPointerException ex) {
67 gotError = true;
68 }
69 assertTrue("Expected NullPointerException", gotError);
70 */
71 }
72 }