KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > acceptance > ReflectionClassesTest


1 package com.thoughtworks.acceptance;
2
3 import java.lang.reflect.Constructor JavaDoc;
4 import java.lang.reflect.Method JavaDoc;
5
6 public class ReflectionClassesTest extends AbstractAcceptanceTest {
7     public static class StupidObject {
8         public StupidObject(String JavaDoc arg) {
9         }
10
11         public void aMethod(String JavaDoc something) {
12         }
13
14         public void aMethod(int cheese) {
15         }
16     }
17
18     public void testReflectionMethod() throws NoSuchMethodException JavaDoc {
19         Method JavaDoc method = StupidObject.class.getMethod("aMethod", new Class JavaDoc[]{String JavaDoc.class});
20
21         String JavaDoc expected =
22                 "<method>\n" +
23                 " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n" +
24                 " <name>aMethod</name>\n" +
25                 " <parameter-types>\n" +
26                 " <class>java.lang.String</class>\n" +
27                 " </parameter-types>\n" +
28                 "</method>";
29
30         assertBothWays(method, expected);
31     }
32
33     public void testReflectionConstructor() throws NoSuchMethodException JavaDoc {
34         Constructor JavaDoc constructor = StupidObject.class.getConstructor(new Class JavaDoc[]{String JavaDoc.class});
35
36         String JavaDoc expected =
37                 "<constructor>\n" +
38                 " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n" +
39                 " <parameter-types>\n" +
40                 " <class>java.lang.String</class>\n" +
41                 " </parameter-types>\n" +
42                 "</constructor>";
43
44         assertBothWays(constructor, expected);
45     }
46
47 }
48
Popular Tags