KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > converters > extended > JavaMethodConverterTest


1 package com.thoughtworks.xstream.converters.extended;
2
3 import java.lang.reflect.Method JavaDoc;
4 import java.lang.reflect.Constructor JavaDoc;
5
6 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
7
8 public class JavaMethodConverterTest extends AbstractAcceptanceTest {
9
10     public void testMethod() throws Exception JavaDoc {
11         Method JavaDoc method = AnIntClass.class.getDeclaredMethod("setValue", new Class JavaDoc[]{Integer.TYPE});
12         String JavaDoc expected =
13                 "<method>\n" +
14                 " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n" +
15                 " <name>setValue</name>\n" +
16                 " <parameter-types>\n" +
17                 " <class>int</class>\n" +
18                 " </parameter-types>\n" +
19                 "</method>";
20         assertBothWays(method, expected);
21     }
22
23     public void testSupportsPrivateMethods() throws NoSuchMethodException JavaDoc {
24         Method JavaDoc method = AnIntClass.class.getDeclaredMethod("privateMethod", new Class JavaDoc[]{});
25         String JavaDoc expected =
26                 "<method>\n" +
27                 " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n" +
28                 " <name>privateMethod</name>\n" +
29                 " <parameter-types/>\n" +
30                 "</method>";
31         assertBothWays(method, expected);
32     }
33
34     public void testSupportsConstructor() throws NoSuchMethodException JavaDoc {
35         Constructor JavaDoc constructor = AnIntClass.class.getDeclaredConstructor(new Class JavaDoc[] { int.class });
36         String JavaDoc expected =
37                 "<constructor>\n" +
38                 " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n" +
39                 " <parameter-types>\n" +
40                 " <class>int</class>\n" +
41                 " </parameter-types>\n" +
42                 "</constructor>";
43         assertBothWays(constructor, expected);
44     }
45
46     static class AnIntClass {
47         private int value = 0;
48
49         protected AnIntClass(int integer) {
50             this.value = integer;
51         }
52
53         public int getValue() {
54             return value;
55         }
56
57         public void setValue(int integer) {
58             this.value = integer;
59         }
60
61         private void privateMethod() {
62         }
63     }
64 }
65
Popular Tags