1 package com.thoughtworks.xstream.converters.extended; 2 3 import java.lang.reflect.Method ; 4 import java.lang.reflect.Constructor ; 5 6 import com.thoughtworks.acceptance.AbstractAcceptanceTest; 7 8 public class JavaMethodConverterTest extends AbstractAcceptanceTest { 9 10 public void testMethod() throws Exception { 11 Method method = AnIntClass.class.getDeclaredMethod("setValue", new Class []{Integer.TYPE}); 12 String 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 { 24 Method method = AnIntClass.class.getDeclaredMethod("privateMethod", new Class []{}); 25 String 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 { 35 Constructor constructor = AnIntClass.class.getDeclaredConstructor(new Class [] { int.class }); 36 String 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 |