01: /*
02: * Copyright (C) 2004, 2005 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 23. December 2004 by Mauro Talevi
11: */
12: package com.thoughtworks.xstream.converters.extended;
13:
14: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
15:
16: import java.lang.reflect.Constructor;
17: import java.lang.reflect.Method;
18:
19: public class JavaMethodConverterTest extends AbstractAcceptanceTest {
20:
21: public void testSupportsPublicMethods() throws Exception {
22: Method method = AnIntClass.class.getDeclaredMethod("setValue",
23: new Class[] { Integer.TYPE });
24: String expected = "<method>\n"
25: + " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n"
26: + " <name>setValue</name>\n" + " <parameter-types>\n"
27: + " <class>int</class>\n" + " </parameter-types>\n"
28: + "</method>";
29: assertBothWays(method, expected);
30: }
31:
32: public void testSupportsPrivateMethods()
33: throws NoSuchMethodException {
34: Method method = AnIntClass.class.getDeclaredMethod(
35: "privateMethod", new Class[] {});
36: String expected = "<method>\n"
37: + " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n"
38: + " <name>privateMethod</name>\n"
39: + " <parameter-types/>\n" + "</method>";
40: assertBothWays(method, expected);
41: }
42:
43: public void testSupportsConstructor() throws NoSuchMethodException {
44: Constructor constructor = AnIntClass.class
45: .getDeclaredConstructor(new Class[] { int.class });
46: String expected = "<constructor>\n"
47: + " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n"
48: + " <parameter-types>\n" + " <class>int</class>\n"
49: + " </parameter-types>\n" + "</constructor>";
50: assertBothWays(constructor, expected);
51: }
52:
53: static class AnIntClass {
54: private int value = 0;
55:
56: protected AnIntClass(int integer) {
57: this .value = integer;
58: }
59:
60: public int getValue() {
61: return value;
62: }
63:
64: public void setValue(int integer) {
65: this .value = integer;
66: }
67:
68: private void privateMethod() {
69: }
70: }
71: }
|