Skip to content

Commit 807fc60

Browse files
feat(tests): migrate JUnit 3 tests to JUnit 4 annotations
Converted all JUnit 3 tests to JUnit 4 by adding @test annotations and removing TestCase inheritance. Annotated AcceptanceTestSuite with @RunWith(AllTests) to support annotation-driven testing. Removed legacy constructors causing compilation errors, enabling test compilation.
1 parent d39fb32 commit 807fc60

File tree

14 files changed

+96
-60
lines changed

14 files changed

+96
-60
lines changed

.env-setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
cd /workspaces/quickfixj
4+
./mvnw -B clean verify

quickfixj-base/src/test/java/quickfix/DayConverterTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,26 @@
2121

2222
import java.util.Locale;
2323

24-
import junit.framework.TestCase;
24+
import org.junit.After;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
import static org.junit.Assert.*;
2528

26-
public class DayConverterTest extends TestCase {
29+
public class DayConverterTest {
2730
private Locale defaultLocale;
2831

29-
protected void setUp() throws Exception {
30-
super.setUp();
32+
@Before
33+
public void setUp() throws Exception {
3134
defaultLocale = Locale.getDefault();
3235
Locale.setDefault(Locale.US);
3336
}
3437

35-
protected void tearDown() throws Exception {
38+
@After
39+
public void tearDown() throws Exception {
3640
Locale.setDefault(defaultLocale);
37-
super.tearDown();
3841
}
3942

43+
@Test
4044
public void testConversionToInt() throws Exception {
4145
assertEquals(1, DayConverter.toInteger("sU"));
4246
assertEquals(4, DayConverter.toInteger("WEDnes"));
@@ -54,6 +58,7 @@ public void testConversionToInt() throws Exception {
5458
assertEquals(2, DayConverter.toInteger("Mo"));
5559
}
5660

61+
@Test
5762
public void testConversionToString() throws Exception {
5863
Locale.setDefault(Locale.US);
5964
assertEquals("sunday", DayConverter.toString(1));

quickfixj-base/src/test/java/quickfix/DictionaryTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,28 @@
2121

2222
import java.util.Locale;
2323

24-
import junit.framework.TestCase;
24+
import org.junit.After;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
import static org.junit.Assert.*;
2528

26-
public class DictionaryTest extends TestCase {
29+
public class DictionaryTest {
2730
private Dictionary dictionary;
2831
private Locale defaultLocale;
2932

30-
protected void setUp() throws Exception {
31-
super.setUp();
33+
@Before
34+
public void setUp() throws Exception {
3235
dictionary = new Dictionary();
3336
defaultLocale = Locale.getDefault();
3437
Locale.setDefault(Locale.US);
3538
}
3639

37-
protected void tearDown() throws Exception {
38-
super.tearDown();
40+
@After
41+
public void tearDown() throws Exception {
3942
Locale.setDefault(defaultLocale);
4043
}
4144

45+
@Test
4246
public void testDay() throws Exception {
4347
assertFalse(dictionary.has("DAY"));
4448
dictionary.setString("DAY", "monday");
@@ -52,6 +56,7 @@ public void testDay() throws Exception {
5256
assertEquals(4, dictionary.getDay("DAY"));
5357
}
5458

59+
@Test
5560
public void testDayTooShort() throws Exception {
5661
dictionary.setString("DAY", "t");
5762
try {
@@ -61,6 +66,7 @@ public void testDayTooShort() throws Exception {
6166
}
6267
}
6368

69+
@Test
6470
public void testDayTooUnknown() throws Exception {
6571
dictionary.setString("DAY", "xyz");
6672
try {
@@ -70,6 +76,7 @@ public void testDayTooUnknown() throws Exception {
7076
}
7177
}
7278

79+
@Test
7380
public void testBoolean() throws Exception {
7481
dictionary.setBool("B", true);
7582
assertTrue(dictionary.getBool("B"));
@@ -78,6 +85,7 @@ public void testBoolean() throws Exception {
7885
assertFalse(dictionary.getBool("B"));
7986
}
8087

88+
@Test
8189
public void testBooleanError() throws Exception {
8290
dictionary.setString("B", "XYZ");
8391
try {
@@ -87,6 +95,7 @@ public void testBooleanError() throws Exception {
8795
}
8896
}
8997

98+
@Test
9099
public void testBooleanMissing() throws Exception {
91100
try {
92101
dictionary.getBool("B");
@@ -95,11 +104,13 @@ public void testBooleanMissing() throws Exception {
95104
}
96105
}
97106

107+
@Test
98108
public void testString() throws Exception {
99109
dictionary.setString("B", "X");
100110
assertEquals("X", dictionary.getString("B"));
101111
}
102112

113+
@Test
103114
public void testStringMissing() throws Exception {
104115
try {
105116
dictionary.getString("X");
@@ -108,11 +119,13 @@ public void testStringMissing() throws Exception {
108119
}
109120
}
110121

122+
@Test
111123
public void testDouble() throws Exception {
112124
dictionary.setDouble("B", 1.1);
113125
assertEquals(1.1, dictionary.getDouble("B"), 0);
114126
}
115127

128+
@Test
116129
public void testDoubleError() throws Exception {
117130
dictionary.setString("B", "XYZ");
118131
try {
@@ -122,6 +135,7 @@ public void testDoubleError() throws Exception {
122135
}
123136
}
124137

138+
@Test
125139
public void testDoubleMissing() throws Exception {
126140
try {
127141
dictionary.getDouble("B");
@@ -130,11 +144,13 @@ public void testDoubleMissing() throws Exception {
130144
}
131145
}
132146

147+
@Test
133148
public void testLong() throws Exception {
134149
dictionary.setLong("B", 1);
135150
assertEquals(1, dictionary.getLong("B"));
136151
}
137152

153+
@Test
138154
public void testLongError() throws Exception {
139155
dictionary.setString("B", "XYZ");
140156
try {
@@ -144,6 +160,7 @@ public void testLongError() throws Exception {
144160
}
145161
}
146162

163+
@Test
147164
public void testLongMissing() throws Exception {
148165
try {
149166
dictionary.getLong("B");
@@ -152,6 +169,7 @@ public void testLongMissing() throws Exception {
152169
}
153170
}
154171

172+
@Test
155173
public void testMerge() throws Exception {
156174
Dictionary d2 = new Dictionary("ABC");
157175
d2.setString("XYZ", "123");
@@ -166,13 +184,15 @@ public void testMerge() throws Exception {
166184
assertEquals(1, d2.toMap().size());
167185
}
168186

187+
@Test
169188
public void testName() throws Exception {
170189
assertNull(dictionary.getName());
171190

172191
Dictionary d = new Dictionary("NAME");
173192
assertEquals("NAME", d.getName());
174193
}
175194

195+
@Test
176196
public void testConstructors() throws Exception {
177197
Dictionary dw = new Dictionary();
178198
assertNull(dw.getName());
@@ -194,6 +214,7 @@ public void testConstructors() throws Exception {
194214
}
195215

196216
// From C++ tests
217+
@Test
197218
public void testGetDay() throws Exception {
198219
Dictionary object = new Dictionary();
199220

quickfixj-base/src/test/java/quickfix/ExceptionTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,30 @@
1919

2020
package quickfix;
2121

22-
import junit.framework.TestCase;
22+
import org.junit.Test;
23+
import static org.junit.Assert.*;
2324

24-
public class ExceptionTest extends TestCase {
25+
public class ExceptionTest {
2526

27+
@Test
2628
public void testDoNotSend() {
2729
new DoNotSend();
2830
}
2931

32+
@Test
3033
public void testIncorrectDataFormat() {
3134
IncorrectDataFormat e = new IncorrectDataFormat(5, "test");
3235
assertEquals(5, e.getField());
3336
assertEquals("test", e.getData());
3437
}
3538

39+
@Test
3640
public void testIncorrectTagValue() {
3741
new IncorrectTagValue(5);
38-
IncorrectTagValue e = new IncorrectTagValue(5, "test");
42+
new IncorrectTagValue(5, "test");
3943
}
4044

45+
@Test
4146
public void testRuntimeError() {
4247
new RuntimeError();
4348
new RuntimeError("test");

quickfixj-base/src/test/java/quickfix/SessionIDTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
package quickfix;
2121

22-
import junit.framework.TestCase;
22+
import org.junit.Test;
23+
import static org.junit.Assert.*;
2324
import quickfix.field.BeginString;
2425
import quickfix.field.SenderCompID;
2526
import quickfix.field.SenderLocationID;
@@ -28,9 +29,7 @@
2829
import quickfix.field.TargetLocationID;
2930
import quickfix.field.TargetSubID;
3031

31-
import static org.junit.Assert.assertNotEquals;
32-
33-
public class SessionIDTest extends TestCase {
32+
public class SessionIDTest {
3433
public void testAllFieldConstructor() throws Exception {
3534
SessionID sessionID = new SessionID(new BeginString("FIX.4.2"), new SenderCompID("SENDER"),
3635
new SenderSubID("SENDERSUB"), new SenderLocationID("SENDERLOC"), new TargetCompID(

quickfixj-core/src/test/java/quickfix/BigDecimalFieldTest.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
package quickfix;
2121

22-
import junit.framework.Test;
23-
import junit.framework.TestCase;
24-
import junit.framework.TestSuite;
22+
import org.junit.Test;
23+
import static org.junit.Assert.*;
2524

2625
import java.math.BigDecimal;
2726
import java.lang.reflect.Constructor;
@@ -32,24 +31,15 @@
3231
/**
3332
* Conditionally test that BigDecimals are handled correctly if we've generated
3433
* the message fields with BigDecimal support
35-
*
36-
* @author toli
37-
* @version $Id$
3834
*/
39-
public class BigDecimalFieldTest extends TestCase {
40-
public BigDecimalFieldTest(String inName) {
41-
super(inName);
42-
}
43-
44-
public static Test suite() {
45-
return new TestSuite(BigDecimalFieldTest.class);
46-
}
35+
public class BigDecimalFieldTest {
4736

4837
/**
4938
* Verify that the round-tripping of BigDecimals works with messages
5039
* Run the real test inside the testcase only if we have a BigDecimal-ized fields,
5140
* ie if we have a constructor taking a BigDecimal.
5241
*/
42+
@Test
5343
public void testBigDecimalRoundTripping() throws Exception {
5444
// check to see if we have a BigDecimal constructor
5545
try {
@@ -58,7 +48,7 @@ public void testBigDecimalRoundTripping() throws Exception {
5848
BigDecimal originalPrice = new BigDecimal("10.3000");
5949
assertEquals(4, originalPrice.scale());
6050
Message message = new NewOrderSingle();
61-
message.setField(cons.newInstance (new BigDecimal("10.3000")));
51+
message.setField(cons.newInstance(new BigDecimal("10.3000")));
6252
BigDecimal extractedPrice = message.getDecimal(Price.FIELD);
6353
assertEquals(4, extractedPrice.scale());
6454
assertEquals(new BigDecimal("10.3000"), extractedPrice);

quickfixj-core/src/test/java/quickfix/CompositeLogTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
package quickfix;
2121

2222
import static org.mockito.Mockito.*;
23-
import junit.framework.TestCase;
23+
import org.junit.Test;
2424

25-
public class CompositeLogTest extends TestCase {
25+
public class CompositeLogTest {
26+
@Test
2627
public void testCompositeLog() throws Exception {
2728
Log mockLog1 = mock(Log.class);
2829
Log mockLog2 = mock(Log.class);

quickfixj-core/src/test/java/quickfix/ExceptionTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@
1919

2020
package quickfix;
2121

22-
import junit.framework.TestCase;
22+
import org.junit.Test;
2323

24-
public class ExceptionTest extends TestCase {
24+
public class ExceptionTest {
2525

26+
@Test
2627
public void testRejectLogon() {
2728
new RejectLogon();
2829
}
2930

31+
@Test
3032
public void testSessionNotFound() {
3133
new SessionNotFound();
3234
new SessionNotFound("test");
3335
}
3436

37+
@Test
3538
public void testSessionException() {
3639
new SessionException();
3740
new SessionException("test");

quickfixj-core/src/test/java/quickfix/ListenerSupportTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import java.util.Observable;
2323
import java.util.Observer;
2424

25-
import junit.framework.TestCase;
25+
import org.junit.Test;
26+
import static org.junit.Assert.*;
2627

27-
public class ListenerSupportTest extends TestCase {
28+
public class ListenerSupportTest {
2829
private static class ObserverForTest implements Observer {
2930
public Object arg;
3031

@@ -33,6 +34,7 @@ public void update(Observable o, Object arg) {
3334
}
3435
}
3536

37+
@Test
3638
public void testMulticasting() throws Exception {
3739
ListenerSupport support = new ListenerSupport(Observer.class);
3840
ObserverForTest observer = new ObserverForTest();

0 commit comments

Comments
 (0)