01: /*
02: * Copyright (C) 2004 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 08. April 2004 by Joe Walnes
11: */
12: package com.thoughtworks.acceptance;
13:
14: import java.lang.reflect.Constructor;
15: import java.lang.reflect.Method;
16:
17: public class ReflectionClassesTest extends AbstractAcceptanceTest {
18: public static class StupidObject {
19: public StupidObject(String arg) {
20: }
21:
22: public void aMethod(String something) {
23: }
24:
25: public void aMethod(int cheese) {
26: }
27: }
28:
29: public void testReflectionMethod() throws NoSuchMethodException {
30: Method method = StupidObject.class.getMethod("aMethod",
31: new Class[] { String.class });
32:
33: String expected = "<method>\n"
34: + " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n"
35: + " <name>aMethod</name>\n" + " <parameter-types>\n"
36: + " <class>java.lang.String</class>\n"
37: + " </parameter-types>\n" + "</method>";
38:
39: assertBothWays(method, expected);
40: }
41:
42: public void testReflectionConstructor()
43: throws NoSuchMethodException {
44: Constructor constructor = StupidObject.class
45: .getConstructor(new Class[] { String.class });
46:
47: String expected = "<constructor>\n"
48: + " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n"
49: + " <parameter-types>\n"
50: + " <class>java.lang.String</class>\n"
51: + " </parameter-types>\n" + "</constructor>";
52:
53: assertBothWays(constructor, expected);
54: }
55:
56: public void testSupportsPrimitiveTypes() {
57: assertBothWays(int.class, "<java-class>int</java-class>");
58: }
59:
60: }
|