1 package com.thoughtworks.acceptance; 2 3 import java.lang.reflect.Constructor ; 4 import java.lang.reflect.Method ; 5 6 public class ReflectionClassesTest extends AbstractAcceptanceTest { 7 public static class StupidObject { 8 public StupidObject(String arg) { 9 } 10 11 public void aMethod(String something) { 12 } 13 14 public void aMethod(int cheese) { 15 } 16 } 17 18 public void testReflectionMethod() throws NoSuchMethodException { 19 Method method = StupidObject.class.getMethod("aMethod", new Class []{String .class}); 20 21 String 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 { 34 Constructor constructor = StupidObject.class.getConstructor(new Class []{String .class}); 35 36 String 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 |