66import junit .framework .TestCase ;
77
88public class HamcrestFactoryWriterTest extends TestCase {
9-
109 private FactoryWriter factoryWriter ;
1110 private StringWriter output = new StringWriter ();
1211
12+ @ Override
1313 protected void setUp () throws Exception {
1414 super .setUp ();
1515 factoryWriter = new HamcrestFactoryWriter (null , null , output );
1616 }
1717
1818 public void testWritesMethodDelegationMethod () throws IOException {
19- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "anyObject" );
19+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "anyObject" , "matcher.ReturnType" );
2020
2121 factoryWriter .writeMethod (method .getName (), method );
2222 assertEquals ("" +
23- " public static org.hamcrest.Matcher anyObject() {\n " +
23+ " public static matcher.ReturnType anyObject() {\n " +
2424 " return com.example.MyMatcher.anyObject();\n " +
2525 " }\n " +
2626 "\n " ,
@@ -30,8 +30,8 @@ public void testWritesMethodDelegationMethod() throws IOException {
3030 public void testWritesCompleteJavaSource () throws IOException {
3131 factoryWriter = new HamcrestFactoryWriter ("com.some.package" , "SomeClass" , output );
3232 factoryWriter .writeHeader ();
33- factoryWriter .writeMethod ("method1" , new FactoryMethod ("com.example.MyMatcher" , "method1" ));
34- factoryWriter .writeMethod ("method2" , new FactoryMethod ("com.example.MyMatcher" , "method2" ));
33+ factoryWriter .writeMethod ("method1" , new FactoryMethod ("com.example.MyMatcher" , "method1" , "matcher.ReturnType" ));
34+ factoryWriter .writeMethod ("method2" , new FactoryMethod ("com.example.MyMatcher" , "method2" , "matcher.ReturnType" ));
3535 factoryWriter .writeFooter ();
3636
3737 assertEquals ("" +
@@ -40,11 +40,11 @@ public void testWritesCompleteJavaSource() throws IOException {
4040 "\n " +
4141 "public class SomeClass {\n " +
4242 "\n " +
43- " public static org.hamcrest.Matcher method1() {\n " +
43+ " public static matcher.ReturnType method1() {\n " +
4444 " return com.example.MyMatcher.method1();\n " +
4545 " }\n " +
4646 "\n " +
47- " public static org.hamcrest.Matcher method2() {\n " +
47+ " public static matcher.ReturnType method2() {\n " +
4848 " return com.example.MyMatcher.method2();\n " +
4949 " }\n " +
5050 "\n " +
@@ -53,77 +53,77 @@ public void testWritesCompleteJavaSource() throws IOException {
5353 }
5454
5555 public void testWritesGenerifiedMatcherType () throws IOException {
56- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "anyString" );
56+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "anyString" , "matcher.ReturnType" );
5757 method .setGenerifiedType ("String" );
5858
5959 factoryWriter .writeMethod (method .getName (), method );
6060 assertEquals ("" +
61- " public static org.hamcrest.Matcher <String> anyString() {\n " +
61+ " public static matcher.ReturnType <String> anyString() {\n " +
6262 " return com.example.MyMatcher.anyString();\n " +
6363 " }\n " +
6464 "\n " ,
6565 output .toString ());
6666 }
6767
6868 public void testWritesAdvancedGenerifiedMatcherType () throws IOException {
69- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "weirdThing" );
69+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "weirdThing" , "matcher.ReturnType" );
7070 method .setGenerifiedType ("java.util.Map<com.Foo<Cheese>,?>" );
7171
7272 factoryWriter .writeMethod (method .getName (), method );
7373 assertEquals ("" +
74- " public static org.hamcrest.Matcher <java.util.Map<com.Foo<Cheese>,?>> weirdThing() {\n " +
74+ " public static matcher.ReturnType <java.util.Map<com.Foo<Cheese>,?>> weirdThing() {\n " +
7575 " return com.example.MyMatcher.weirdThing();\n " +
7676 " }\n " +
7777 "\n " ,
7878 output .toString ());
7979 }
8080
8181 public void testWritesParameters () throws IOException {
82- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "between" );
82+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "between" , "matcher.ReturnType" );
8383 method .addParameter ("int[]" , "lower" );
8484 method .addParameter ("com.blah.Cheesable<Long>..." , "upper" );
8585
8686 factoryWriter .writeMethod (method .getName (), method );
8787 assertEquals ("" +
88- " public static org.hamcrest.Matcher between(int[] lower, com.blah.Cheesable<Long>... upper) {\n " +
88+ " public static matcher.ReturnType between(int[] lower, com.blah.Cheesable<Long>... upper) {\n " +
8989 " return com.example.MyMatcher.between(lower, upper);\n " +
9090 " }\n " +
9191 "\n " ,
9292 output .toString ());
9393 }
9494
9595 public void testWritesExceptions () throws IOException {
96- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "tricky" );
96+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "tricky" , "matcher.ReturnType" );
9797 method .addException ("java.io.IOException" );
9898 method .addException ("com.foo.CheeselessException" );
9999
100100 factoryWriter .writeMethod (method .getName (), method );
101101 assertEquals ("" +
102- " public static org.hamcrest.Matcher tricky() throws java.io.IOException, com.foo.CheeselessException {\n " +
102+ " public static matcher.ReturnType tricky() throws java.io.IOException, com.foo.CheeselessException {\n " +
103103 " return com.example.MyMatcher.tricky();\n " +
104104 " }\n " +
105105 "\n " ,
106106 output .toString ());
107107 }
108108
109109 public void testWritesGenericTypeParameters () throws IOException {
110- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "tricky" );
110+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "tricky" , "matcher.ReturnType" );
111111 method .addGenericTypeParameter ("T" );
112112 method .addGenericTypeParameter ("V extends String & Cheese" );
113113 method .addParameter ("T" , "t" );
114114 method .addParameter ("List<V>" , "v" );
115115
116116 factoryWriter .writeMethod (method .getName (), method );
117117 assertEquals ("" +
118- " public static <T, V extends String & Cheese> org.hamcrest.Matcher tricky(T t, List<V> v) {\n " +
118+ " public static <T, V extends String & Cheese> matcher.ReturnType tricky(T t, List<V> v) {\n " +
119119 " return com.example.MyMatcher.tricky(t, v);\n " +
120120 " }\n " +
121121 "\n " ,
122122 output .toString ());
123123 }
124124
125125 public void testWritesJavaDoc () throws IOException {
126- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "needsDoc" );
126+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "needsDoc" , "matcher.ReturnType" );
127127 method .setJavaDoc ("This is a complicated method.\n It needs docs.\n \n @see MoreStuff" );
128128
129129 factoryWriter .writeMethod (method .getName (), method );
@@ -134,19 +134,19 @@ public void testWritesJavaDoc() throws IOException {
134134 " * \n " +
135135 " * @see MoreStuff\n " +
136136 " */\n " +
137- " public static org.hamcrest.Matcher needsDoc() {\n " +
137+ " public static matcher.ReturnType needsDoc() {\n " +
138138 " return com.example.MyMatcher.needsDoc();\n " +
139139 " }\n " +
140140 "\n " ,
141141 output .toString ());
142142 }
143143
144144 public void testWritesMethodWithNameOverriden () throws IOException {
145- FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "eq" );
145+ FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "eq" , "matcher.ReturnType" );
146146
147147 factoryWriter .writeMethod ("anotherName" , method );
148148 assertEquals ("" +
149- " public static org.hamcrest.Matcher anotherName() {\n " +
149+ " public static matcher.ReturnType anotherName() {\n " +
150150 " return com.example.MyMatcher.eq();\n " +
151151 " }\n " +
152152 "\n " ,
0 commit comments