11package org .hamcrest .generator ;
22
3+ import static org .junit .Assert .assertEquals ;
4+
35import java .io .IOException ;
46import java .io .StringWriter ;
57
6- import junit .framework .TestCase ;
7-
8- public class HamcrestFactoryWriterTest extends TestCase {
9- private FactoryWriter factoryWriter ;
10- private StringWriter output = new StringWriter ();
8+ import org .junit .Test ;
119
12- @ Override
13- protected void setUp () throws Exception {
14- super .setUp ();
15- factoryWriter = new HamcrestFactoryWriter (null , null , output );
16- }
10+ public final class HamcrestFactoryWriterTest {
11+ private final StringWriter output = new StringWriter ();
12+ private final FactoryWriter factoryWriter = new HamcrestFactoryWriter (null , null , output );
1713
18- public void testWritesMethodDelegationMethod () throws IOException {
14+ @ Test public void
15+ writesMethodDelegationMethod () throws IOException {
1916 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "anyObject" , "matcher.ReturnType" );
2017
2118 factoryWriter .writeMethod (method .getName (), method );
@@ -27,13 +24,15 @@ public void testWritesMethodDelegationMethod() throws IOException {
2724 output .toString ());
2825 }
2926
30- public void testWritesCompleteJavaSource () throws IOException {
31- factoryWriter = new HamcrestFactoryWriter ("com.some.package" , "SomeClass" , output );
32- factoryWriter .writeHeader ();
33- factoryWriter .writeMethod ("method1" , new FactoryMethod ("com.example.MyMatcher" , "method1" , "matcher.ReturnType" ));
34- factoryWriter .writeMethod ("method2" , new FactoryMethod ("com.example.MyMatcher" , "method2" , "matcher.ReturnType" ));
35- factoryWriter .writeFooter ();
36-
27+ @ Test public void
28+ writesCompleteJavaSource () throws IOException {
29+ final FactoryWriter writer = new HamcrestFactoryWriter ("com.some.package" , "SomeClass" , output );
30+ writer .writeHeader ();
31+ writer .writeMethod ("method1" , new FactoryMethod ("com.example.MyMatcher" , "method1" , "matcher.ReturnType" ));
32+ writer .writeMethod ("method2" , new FactoryMethod ("com.example.MyMatcher" , "method2" , "matcher.ReturnType" ));
33+ writer .writeFooter ();
34+ writer .close ();
35+
3736 assertEquals ("" +
3837 "// Generated source.\n " +
3938 "package com.some.package;\n " +
@@ -52,7 +51,8 @@ public void testWritesCompleteJavaSource() throws IOException {
5251 output .toString ());
5352 }
5453
55- public void testWritesGenerifiedMatcherType () throws IOException {
54+ @ Test public void
55+ writesGenerifiedMatcherType () throws IOException {
5656 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "anyString" , "matcher.ReturnType" );
5757 method .setGenerifiedType ("String" );
5858
@@ -65,7 +65,8 @@ public void testWritesGenerifiedMatcherType() throws IOException {
6565 output .toString ());
6666 }
6767
68- public void testWritesAdvancedGenerifiedMatcherType () throws IOException {
68+ @ Test public void
69+ writesAdvancedGenerifiedMatcherType () throws IOException {
6970 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "weirdThing" , "matcher.ReturnType" );
7071 method .setGenerifiedType ("java.util.Map<com.Foo<Cheese>,?>" );
7172
@@ -78,7 +79,8 @@ public void testWritesAdvancedGenerifiedMatcherType() throws IOException {
7879 output .toString ());
7980 }
8081
81- public void testWritesParameters () throws IOException {
82+ @ Test public void
83+ writesParameters () throws IOException {
8284 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "between" , "matcher.ReturnType" );
8385 method .addParameter ("int[]" , "lower" );
8486 method .addParameter ("com.blah.Cheesable<Long>..." , "upper" );
@@ -92,7 +94,8 @@ public void testWritesParameters() throws IOException {
9294 output .toString ());
9395 }
9496
95- public void testWritesExceptions () throws IOException {
97+ @ Test public void
98+ writesExceptions () throws IOException {
9699 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "tricky" , "matcher.ReturnType" );
97100 method .addException ("java.io.IOException" );
98101 method .addException ("com.foo.CheeselessException" );
@@ -106,7 +109,8 @@ public void testWritesExceptions() throws IOException {
106109 output .toString ());
107110 }
108111
109- public void testWritesGenericTypeParameters () throws IOException {
112+ @ Test public void
113+ writesGenericTypeParameters () throws IOException {
110114 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "tricky" , "matcher.ReturnType" );
111115 method .addGenericTypeParameter ("T" );
112116 method .addGenericTypeParameter ("V extends String & Cheese" );
@@ -122,7 +126,8 @@ public void testWritesGenericTypeParameters() throws IOException {
122126 output .toString ());
123127 }
124128
125- public void testWritesJavaDoc () throws IOException {
129+ @ Test public void
130+ writesJavaDoc () throws IOException {
126131 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "needsDoc" , "matcher.ReturnType" );
127132 method .setJavaDoc ("This is a complicated method.\n It needs docs.\n \n @see MoreStuff" );
128133
@@ -141,7 +146,8 @@ public void testWritesJavaDoc() throws IOException {
141146 output .toString ());
142147 }
143148
144- public void testWritesMethodWithNameOverridden () throws IOException {
149+ @ Test public void
150+ writesMethodWithNameOverridden () throws IOException {
145151 FactoryMethod method = new FactoryMethod ("com.example.MyMatcher" , "eq" , "matcher.ReturnType" );
146152
147153 factoryWriter .writeMethod ("anotherName" , method );
@@ -152,5 +158,4 @@ public void testWritesMethodWithNameOverridden() throws IOException {
152158 "\n " ,
153159 output .toString ());
154160 }
155-
156161}
0 commit comments