Skip to content

Commit de599fc

Browse files
committed
convert JUnit3 tests to JUnit4
1 parent 149d59e commit de599fc

7 files changed

Lines changed: 123 additions & 110 deletions

File tree

‎hamcrest-api/src/test/java/org/hamcrest/NullDescriptionTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hamcrest;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.Assert.assertEquals;
44

55
import org.hamcrest.Description.NullDescription;
66
import org.junit.Test;

‎hamcrest-generator/src/test/java/org/hamcrest/generator/EasyMock2FactoryWriterTest.java‎

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
package org.hamcrest.generator;
22

3-
import junit.framework.TestCase;
3+
import static org.junit.Assert.assertEquals;
44

5-
import java.io.StringWriter;
65
import java.io.IOException;
6+
import java.io.StringWriter;
77

8-
public class EasyMock2FactoryWriterTest extends TestCase {
8+
import org.junit.Test;
99

10-
private FactoryWriter factoryWriter;
11-
private StringWriter output = new StringWriter();
10+
public final class EasyMock2FactoryWriterTest {
1211

13-
@Override
14-
protected void setUp() throws Exception {
15-
super.setUp();
16-
factoryWriter = new EasyMock2FactoryWriter(output, "com.blah", "EasyMatchers");
17-
}
12+
private final StringWriter output = new StringWriter();
13+
private final FactoryWriter factoryWriter = new EasyMock2FactoryWriter(output, "com.blah", "EasyMatchers");
1814

19-
public void testWritesMethodDelegationMethodWrappedInAdapter() throws IOException {
15+
@Test public void
16+
writesMethodDelegationMethodWrappedInAdapter() throws IOException {
2017
FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "anyObject", "unusedReturnType");
2118

2219
factoryWriter.writeMethod(method.getName(), method);
@@ -30,7 +27,8 @@ public void testWritesMethodDelegationMethodWrappedInAdapter() throws IOExceptio
3027
output.toString());
3128
}
3229

33-
public void testWritesReturnType() throws IOException {
30+
@Test public void
31+
writesReturnType() throws IOException {
3432
FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "anyString", "unusedReturnType");
3533
method.setGenerifiedType("String");
3634

@@ -45,7 +43,8 @@ public void testWritesReturnType() throws IOException {
4543
output.toString());
4644
}
4745

48-
public void testWritesAdvancedGenerifiedMatcherType() throws IOException {
46+
@Test public void
47+
writesAdvancedGenerifiedMatcherType() throws IOException {
4948
FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "weirdThing", "unusedReturnType");
5049
method.setGenerifiedType("java.util.Map<com.Foo<Cheese>,?>");
5150

@@ -60,7 +59,8 @@ public void testWritesAdvancedGenerifiedMatcherType() throws IOException {
6059
output.toString());
6160
}
6261

63-
public void testWritesParameters() throws IOException {
62+
@Test public void
63+
writesParameters() throws IOException {
6464
FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "between", "unusedReturnType");
6565
method.addParameter("int[]", "lower");
6666
method.addParameter("com.blah.Cheesable<Long>...", "upper");
@@ -76,7 +76,8 @@ public void testWritesParameters() throws IOException {
7676
output.toString());
7777
}
7878

79-
public void testWritesExceptions() throws IOException {
79+
@Test public void
80+
writesExceptions() throws IOException {
8081
FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "tricky", "unusedReturnType");
8182
method.addException("java.io.IOException");
8283
method.addException("com.foo.CheeselessException");
@@ -92,7 +93,8 @@ public void testWritesExceptions() throws IOException {
9293
output.toString());
9394
}
9495
//
95-
// public void testWritesGenericTypeParameters() throws IOException {
96+
// @Test public void
97+
// writesGenericTypeParameters() throws IOException {
9698
// FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "tricky");
9799
// method.addGenericTypeParameter("T");
98100
// method.addGenericTypeParameter("V extends String & Cheese");
@@ -108,7 +110,8 @@ public void testWritesExceptions() throws IOException {
108110
// output.toString());
109111
// }
110112
//
111-
// public void testWritesJavaDoc() throws IOException {
113+
// @Test public void
114+
// writesJavaDoc() throws IOException {
112115
// FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "needsDoc");
113116
// method.setJavaDoc("This is a complicated method.\nIt needs docs.\n\n@see MoreStuff");
114117
//
@@ -127,7 +130,8 @@ public void testWritesExceptions() throws IOException {
127130
// output.toString());
128131
// }
129132
//
130-
// public void testWritesMethodWithNameOverridden() throws IOException {
133+
// @Test public void
134+
// writesMethodWithNameOverridden() throws IOException {
131135
// FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "eq");
132136
//
133137
// factoryWriter.writeMethod("anotherName", method);
@@ -142,6 +146,4 @@ public void testWritesExceptions() throws IOException {
142146
// primitives
143147
// arrays?
144148
// and/or/not/etc
145-
146-
147149
}

‎hamcrest-generator/src/test/java/org/hamcrest/generator/HamcrestFactoryWriterTest.java‎

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package org.hamcrest.generator;
22

3+
import static org.junit.Assert.assertEquals;
4+
35
import java.io.IOException;
46
import 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.\nIt 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
}

‎hamcrest-generator/src/test/java/org/hamcrest/generator/QDoxFactoryReaderTest.java‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package org.hamcrest.generator;
22

3-
import junit.framework.TestCase;
3+
import static org.junit.Assert.assertEquals;
44

55
import java.io.StringReader;
66
import java.util.ArrayList;
77
import java.util.Iterator;
88
import java.util.List;
99

10-
public class QDoxFactoryReaderTest extends TestCase {
10+
import org.junit.Test;
1111

12-
public void testExtractsOriginalParameterNamesFromSource() {
12+
public final class QDoxFactoryReaderTest {
13+
14+
@Test public void
15+
extractsOriginalParameterNamesFromSource() {
1316
FactoryMethod method = new FactoryMethod("org.SomeClass", "someMethod", "unusedReturnType");
1417
method.addParameter("java.lang.String", "badParamName");
1518

@@ -23,8 +26,9 @@ public void testExtractsOriginalParameterNamesFromSource() {
2326
assertEquals("java.lang.String", factoryMethod.getParameters().get(0).getType());
2427
assertEquals("realParamName", factoryMethod.getParameters().get(0).getName());
2528
}
26-
27-
public void testExtractsOriginalGenericParameterNamesFromSource() {
29+
30+
@Test public void
31+
extractsOriginalGenericParameterNamesFromSource() {
2832
FactoryMethod method = new FactoryMethod("org.SomeClass", "someMethod", "unusedReturnType");
2933
method.addParameter("java.util.Collection<java.lang.String>", "badParamName");
3034

@@ -39,7 +43,8 @@ public void testExtractsOriginalGenericParameterNamesFromSource() {
3943
assertEquals("realParamName", factoryMethod.getParameters().get(0).getName());
4044
}
4145

42-
public void testExtractsOriginalVarArgParameterNamesFromSource() {
46+
@Test public void
47+
extractsOriginalVarArgParameterNamesFromSource() {
4348
FactoryMethod method = new FactoryMethod("org.SomeClass", "someMethod", "unusedReturnType");
4449
method.addParameter("java.lang.String...", "badParamName");
4550

@@ -54,7 +59,8 @@ public void testExtractsOriginalVarArgParameterNamesFromSource() {
5459
assertEquals("realParamName", factoryMethod.getParameters().get(0).getName());
5560
}
5661

57-
public void testExtractsOriginalJavaDocFromSource() {
62+
@Test public void
63+
extractsOriginalJavaDocFromSource() {
5864
FactoryMethod method = new FactoryMethod("org.SomeClass", "someMethod", "unusedReturnType");
5965

6066
String input = "" +
@@ -73,8 +79,7 @@ public void testExtractsOriginalJavaDocFromSource() {
7379
factoryMethod.getJavaDoc());
7480
}
7581

76-
private static FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod,
77-
String className, String input) {
82+
private static FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod, String className, String input) {
7883
List<FactoryMethod> originalMethods = new ArrayList<FactoryMethod>();
7984
originalMethods.add(originalMethod);
8085

@@ -91,6 +96,4 @@ private static FactoryMethod getFirstFactoryMethod(QDoxFactoryReader qDoxFactory
9196
iterator.hasNext();
9297
return iterator.next();
9398
}
94-
95-
9699
}
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
package org.hamcrest.generator;
22

3-
import junit.framework.TestCase;
3+
import static org.junit.Assert.assertEquals;
44

5-
import java.io.PrintStream;
65
import java.io.ByteArrayOutputStream;
76
import java.io.IOException;
7+
import java.io.PrintStream;
88

9-
public class QuickReferenceWriterTest extends TestCase {
9+
import org.junit.Test;
1010

11-
private ByteArrayOutputStream actualBuffer;
12-
private ByteArrayOutputStream expectedBuffer;
13-
private PrintStream expected;
14-
private QuickReferenceWriter writer;
11+
public final class QuickReferenceWriterTest {
1512

16-
@Override
17-
protected void setUp() throws Exception {
18-
super.setUp();
19-
actualBuffer = new ByteArrayOutputStream();
20-
writer = new QuickReferenceWriter(new PrintStream(actualBuffer));
13+
private final ByteArrayOutputStream actualBuffer = new ByteArrayOutputStream();
14+
private final ByteArrayOutputStream expectedBuffer = new ByteArrayOutputStream();
15+
private final PrintStream expected = new PrintStream(expectedBuffer);
16+
private final QuickReferenceWriter writer = new QuickReferenceWriter(new PrintStream(actualBuffer));
2117

22-
expectedBuffer = new ByteArrayOutputStream();
23-
expected = new PrintStream(expectedBuffer);
24-
}
25-
26-
public void testWritesSimplifiedSummaryOfMatchers() throws IOException {
18+
@Test public void
19+
writesSimplifiedSummaryOfMatchers() throws IOException {
2720
FactoryMethod namedMethod = new FactoryMethod("SomeClass", "someMethod", "unusedReturnType");
2821
namedMethod.addParameter("Cheese", "a");
2922
namedMethod.addParameter("int", "b");
@@ -39,7 +32,8 @@ public void testWritesSimplifiedSummaryOfMatchers() throws IOException {
3932
verify();
4033
}
4134

42-
public void testRemovesPackageNames() throws IOException {
35+
@Test public void
36+
removesPackageNames() throws IOException {
4337
FactoryMethod namedMethod = new FactoryMethod("SomeClass", "someMethod", "unusedReturnType");
4438
namedMethod.addParameter("com.blah.Foo", "a");
4539
namedMethod.addParameter("com.foo.Cheese<x.y.Zoo>", "b");
@@ -53,5 +47,4 @@ public void testRemovesPackageNames() throws IOException {
5347
private void verify() {
5448
assertEquals(new String(expectedBuffer.toByteArray()), new String(actualBuffer.toByteArray()));
5549
}
56-
5750
}

0 commit comments

Comments
 (0)