diff --git a/quickfixj-base/src/test/java/quickfix/DayConverterTest.java b/quickfixj-base/src/test/java/quickfix/DayConverterTest.java index 4f7dae56a4..a765caa684 100644 --- a/quickfixj-base/src/test/java/quickfix/DayConverterTest.java +++ b/quickfixj-base/src/test/java/quickfix/DayConverterTest.java @@ -21,22 +21,26 @@ import java.util.Locale; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; -public class DayConverterTest extends TestCase { +public class DayConverterTest { private Locale defaultLocale; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { Locale.setDefault(defaultLocale); - super.tearDown(); } + @Test public void testConversionToInt() throws Exception { assertEquals(1, DayConverter.toInteger("sU")); assertEquals(4, DayConverter.toInteger("WEDnes")); @@ -54,6 +58,7 @@ public void testConversionToInt() throws Exception { assertEquals(2, DayConverter.toInteger("Mo")); } + @Test public void testConversionToString() throws Exception { Locale.setDefault(Locale.US); assertEquals("sunday", DayConverter.toString(1)); diff --git a/quickfixj-base/src/test/java/quickfix/DictionaryTest.java b/quickfixj-base/src/test/java/quickfix/DictionaryTest.java index b9e31db60e..a2113ecd72 100644 --- a/quickfixj-base/src/test/java/quickfix/DictionaryTest.java +++ b/quickfixj-base/src/test/java/quickfix/DictionaryTest.java @@ -21,24 +21,28 @@ import java.util.Locale; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; -public class DictionaryTest extends TestCase { +public class DictionaryTest { private Dictionary dictionary; private Locale defaultLocale; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { dictionary = new Dictionary(); defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); } - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { Locale.setDefault(defaultLocale); } + @Test public void testDay() throws Exception { assertFalse(dictionary.has("DAY")); dictionary.setString("DAY", "monday"); @@ -52,6 +56,7 @@ public void testDay() throws Exception { assertEquals(4, dictionary.getDay("DAY")); } + @Test public void testDayTooShort() throws Exception { dictionary.setString("DAY", "t"); try { @@ -61,6 +66,7 @@ public void testDayTooShort() throws Exception { } } + @Test public void testDayTooUnknown() throws Exception { dictionary.setString("DAY", "xyz"); try { @@ -70,6 +76,7 @@ public void testDayTooUnknown() throws Exception { } } + @Test public void testBoolean() throws Exception { dictionary.setBool("B", true); assertTrue(dictionary.getBool("B")); @@ -78,6 +85,7 @@ public void testBoolean() throws Exception { assertFalse(dictionary.getBool("B")); } + @Test public void testBooleanError() throws Exception { dictionary.setString("B", "XYZ"); try { @@ -87,6 +95,7 @@ public void testBooleanError() throws Exception { } } + @Test public void testBooleanMissing() throws Exception { try { dictionary.getBool("B"); @@ -95,11 +104,13 @@ public void testBooleanMissing() throws Exception { } } + @Test public void testString() throws Exception { dictionary.setString("B", "X"); assertEquals("X", dictionary.getString("B")); } + @Test public void testStringMissing() throws Exception { try { dictionary.getString("X"); @@ -108,11 +119,13 @@ public void testStringMissing() throws Exception { } } + @Test public void testDouble() throws Exception { dictionary.setDouble("B", 1.1); assertEquals(1.1, dictionary.getDouble("B"), 0); } + @Test public void testDoubleError() throws Exception { dictionary.setString("B", "XYZ"); try { @@ -122,6 +135,7 @@ public void testDoubleError() throws Exception { } } + @Test public void testDoubleMissing() throws Exception { try { dictionary.getDouble("B"); @@ -130,11 +144,13 @@ public void testDoubleMissing() throws Exception { } } + @Test public void testLong() throws Exception { dictionary.setLong("B", 1); assertEquals(1, dictionary.getLong("B")); } + @Test public void testLongError() throws Exception { dictionary.setString("B", "XYZ"); try { @@ -144,6 +160,7 @@ public void testLongError() throws Exception { } } + @Test public void testLongMissing() throws Exception { try { dictionary.getLong("B"); @@ -152,6 +169,7 @@ public void testLongMissing() throws Exception { } } + @Test public void testMerge() throws Exception { Dictionary d2 = new Dictionary("ABC"); d2.setString("XYZ", "123"); @@ -166,6 +184,7 @@ public void testMerge() throws Exception { assertEquals(1, d2.toMap().size()); } + @Test public void testName() throws Exception { assertNull(dictionary.getName()); @@ -173,6 +192,7 @@ public void testName() throws Exception { assertEquals("NAME", d.getName()); } + @Test public void testConstructors() throws Exception { Dictionary dw = new Dictionary(); assertNull(dw.getName()); @@ -194,6 +214,7 @@ public void testConstructors() throws Exception { } // From C++ tests + @Test public void testGetDay() throws Exception { Dictionary object = new Dictionary(); diff --git a/quickfixj-base/src/test/java/quickfix/ExceptionTest.java b/quickfixj-base/src/test/java/quickfix/ExceptionTest.java index e87eb0adf1..ca99b7ced6 100644 --- a/quickfixj-base/src/test/java/quickfix/ExceptionTest.java +++ b/quickfixj-base/src/test/java/quickfix/ExceptionTest.java @@ -19,25 +19,30 @@ package quickfix; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; -public class ExceptionTest extends TestCase { +public class ExceptionTest { + @Test public void testDoNotSend() { new DoNotSend(); } + @Test public void testIncorrectDataFormat() { IncorrectDataFormat e = new IncorrectDataFormat(5, "test"); assertEquals(5, e.getField()); assertEquals("test", e.getData()); } + @Test public void testIncorrectTagValue() { new IncorrectTagValue(5); - IncorrectTagValue e = new IncorrectTagValue(5, "test"); + new IncorrectTagValue(5, "test"); } + @Test public void testRuntimeError() { new RuntimeError(); new RuntimeError("test"); diff --git a/quickfixj-base/src/test/java/quickfix/SessionIDTest.java b/quickfixj-base/src/test/java/quickfix/SessionIDTest.java index 8eae351f86..551bb3fc67 100644 --- a/quickfixj-base/src/test/java/quickfix/SessionIDTest.java +++ b/quickfixj-base/src/test/java/quickfix/SessionIDTest.java @@ -19,7 +19,8 @@ package quickfix; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import quickfix.field.BeginString; import quickfix.field.SenderCompID; import quickfix.field.SenderLocationID; @@ -28,9 +29,8 @@ import quickfix.field.TargetLocationID; import quickfix.field.TargetSubID; -import static org.junit.Assert.assertNotEquals; - -public class SessionIDTest extends TestCase { +public class SessionIDTest { + @Test public void testAllFieldConstructor() throws Exception { SessionID sessionID = new SessionID(new BeginString("FIX.4.2"), new SenderCompID("SENDER"), new SenderSubID("SENDERSUB"), new SenderLocationID("SENDERLOC"), new TargetCompID( @@ -39,6 +39,7 @@ public void testAllFieldConstructor() throws Exception { assertAllFields(sessionID); } + @Test public void testAllStringConstructor() throws Exception { SessionID sessionID = new SessionID("FIX.4.2", "SENDER", "SENDERSUB", "SENDERLOC", "TARGET", "TARGETSUB", "TARGETLOC", "QUALIFIER"); @@ -56,6 +57,7 @@ private void assertAllFields(SessionID sessionID) { assertEquals("QUALIFIER", sessionID.getSessionQualifier()); } + @Test public void testFieldConstructorNoLocation() throws Exception { SessionID sessionID = new SessionID(new BeginString("FIX.4.2"), new SenderCompID("SENDER"), new SenderSubID("SENDERSUB"), new TargetCompID("TARGET"), new TargetSubID( @@ -63,6 +65,7 @@ public void testFieldConstructorNoLocation() throws Exception { assertFieldsNoLocation(sessionID); } + @Test public void testStringConstructorNoLocation() throws Exception { SessionID sessionID = new SessionID("FIX.4.2", "SENDER", "SENDERSUB", "TARGET", "TARGETSUB"); assertFieldsNoLocation(sessionID); @@ -79,12 +82,14 @@ private void assertFieldsNoLocation(SessionID sessionID) { assertEquals("", sessionID.getSessionQualifier()); } + @Test public void testFieldConstructorNoLocationOrSub() throws Exception { SessionID sessionID = new SessionID(new BeginString("FIX.4.2"), new SenderCompID("SENDER"), new TargetCompID("TARGET"), "QUALIFIER"); assertFieldsNoLocationOrSub(sessionID); } + @Test public void testStringConstructorNoLocationOrSub() throws Exception { SessionID sessionID = new SessionID("FIX.4.2", "SENDER", "TARGET", "QUALIFIER"); assertFieldsNoLocationOrSub(sessionID); @@ -101,12 +106,14 @@ private void assertFieldsNoLocationOrSub(SessionID sessionID) { assertEquals("QUALIFIER", sessionID.getSessionQualifier()); } + @Test public void testFieldConstructorNoLocationSubOrQualifier() throws Exception { SessionID sessionID = new SessionID(new BeginString("FIX.4.2"), new SenderCompID("SENDER"), new TargetCompID("TARGET")); assertFieldsNoLocationSubOrQualifier(sessionID); } + @Test public void testStringConstructorNoLocationSubOrQualifier() throws Exception { SessionID sessionID = new SessionID("FIX.4.2", "SENDER", "TARGET"); assertFieldsNoLocationSubOrQualifier(sessionID); @@ -123,6 +130,7 @@ private void assertFieldsNoLocationSubOrQualifier(SessionID sessionID) { assertEquals("", sessionID.getSessionQualifier()); } + @Test public void testDefaultConstructorException() throws Exception { try { new SessionID(); @@ -132,6 +140,7 @@ public void testDefaultConstructorException() throws Exception { } } + @Test public void testEquals() throws Exception { SessionID sessionID1 = new SessionID("FIX.4.2:SENDER->TARGET:QUALIFIER"); SessionID sessionID2 = new SessionID("FIX.4.2:SENDER->TARGET:QUALIFIER"); @@ -142,18 +151,21 @@ public void testEquals() throws Exception { assertFalse(sessionID1.equals(null)); } + @Test public void testHashCode() throws Exception { SessionID sessionID1 = new SessionID("FIX.4.2:SENDER->TARGET:QUALIFIER"); SessionID sessionID2 = new SessionID("FIX.4.2:SENDER->TARGET:QUALIFIER"); assertEquals(sessionID1.hashCode(), sessionID2.hashCode()); } + @Test public void testNullInFieldConstructor() { SessionID sessionID = new SessionID((BeginString) null, null, null, null, null, null, null, null); assertEmptyStrings(sessionID); } + @Test public void testNullInStringConstructor() { SessionID sessionID = new SessionID((String) null, null, null, null, null, null, null, null); assertEmptyStrings(sessionID); @@ -170,6 +182,7 @@ private void assertEmptyStrings(SessionID sessionID) { assertEquals("", sessionID.getSessionQualifier()); } + @Test public void testStringConstructor() throws Exception { SessionID sessionID = new SessionID("FIX.4.2:SENDER/SSUB/SLOC->TARGET/TSUB/TLOC:QUALIFIER"); assertEquals("FIX.4.2", sessionID.getBeginString()); @@ -183,6 +196,7 @@ public void testStringConstructor() throws Exception { assertEquals("FIX.4.2:SENDER/SSUB/SLOC->TARGET/TSUB/TLOC:QUALIFIER", sessionID.toString()); } + @Test public void testStringConstructorNoSubOrLocation() throws Exception { SessionID sessionID = new SessionID("FIX.4.2:SENDER->TARGET:QUALIFIER"); assertEquals("FIX.4.2", sessionID.getBeginString()); @@ -192,6 +206,7 @@ public void testStringConstructorNoSubOrLocation() throws Exception { assertEquals("FIX.4.2:SENDER->TARGET:QUALIFIER", sessionID.toString()); } + @Test public void testStringConstructorNoSubLocationOrQualifier() throws Exception { SessionID sessionID = new SessionID("FIX.4.2:SENDER->TARGET"); assertEquals("FIX.4.2", sessionID.getBeginString()); @@ -201,6 +216,7 @@ public void testStringConstructorNoSubLocationOrQualifier() throws Exception { assertEquals("FIX.4.2:SENDER->TARGET", sessionID.toString()); } + @Test public void testStringConstructorInvalidID() throws Exception { try { new SessionID("FIX.4.2:SENDER"); @@ -210,6 +226,7 @@ public void testStringConstructorInvalidID() throws Exception { } } + @Test public void testFromStringUnsupported() { SessionID sessionID = new SessionID((String) null, (String) null, (String) null); try { diff --git a/quickfixj-core/src/test/java/quickfix/BigDecimalFieldTest.java b/quickfixj-core/src/test/java/quickfix/BigDecimalFieldTest.java index 0304359c6f..bfadb728b9 100644 --- a/quickfixj-core/src/test/java/quickfix/BigDecimalFieldTest.java +++ b/quickfixj-core/src/test/java/quickfix/BigDecimalFieldTest.java @@ -19,9 +19,8 @@ package quickfix; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.Test; +import static org.junit.Assert.*; import java.math.BigDecimal; import java.lang.reflect.Constructor; @@ -32,24 +31,15 @@ /** * Conditionally test that BigDecimals are handled correctly if we've generated * the message fields with BigDecimal support - * - * @author toli - * @version $Id$ */ -public class BigDecimalFieldTest extends TestCase { - public BigDecimalFieldTest(String inName) { - super(inName); - } - - public static Test suite() { - return new TestSuite(BigDecimalFieldTest.class); - } +public class BigDecimalFieldTest { /** * Verify that the round-tripping of BigDecimals works with messages * Run the real test inside the testcase only if we have a BigDecimal-ized fields, * ie if we have a constructor taking a BigDecimal. */ + @Test public void testBigDecimalRoundTripping() throws Exception { // check to see if we have a BigDecimal constructor try { @@ -58,7 +48,7 @@ public void testBigDecimalRoundTripping() throws Exception { BigDecimal originalPrice = new BigDecimal("10.3000"); assertEquals(4, originalPrice.scale()); Message message = new NewOrderSingle(); - message.setField(cons.newInstance (new BigDecimal("10.3000"))); + message.setField(cons.newInstance(new BigDecimal("10.3000"))); BigDecimal extractedPrice = message.getDecimal(Price.FIELD); assertEquals(4, extractedPrice.scale()); assertEquals(new BigDecimal("10.3000"), extractedPrice); diff --git a/quickfixj-core/src/test/java/quickfix/CompositeLogTest.java b/quickfixj-core/src/test/java/quickfix/CompositeLogTest.java index edf96cd7e2..eb6892444b 100644 --- a/quickfixj-core/src/test/java/quickfix/CompositeLogTest.java +++ b/quickfixj-core/src/test/java/quickfix/CompositeLogTest.java @@ -20,9 +20,10 @@ package quickfix; import static org.mockito.Mockito.*; -import junit.framework.TestCase; +import org.junit.Test; -public class CompositeLogTest extends TestCase { +public class CompositeLogTest { + @Test public void testCompositeLog() throws Exception { Log mockLog1 = mock(Log.class); Log mockLog2 = mock(Log.class); diff --git a/quickfixj-core/src/test/java/quickfix/ExceptionTest.java b/quickfixj-core/src/test/java/quickfix/ExceptionTest.java index 13572eb49f..ec855e84e9 100644 --- a/quickfixj-core/src/test/java/quickfix/ExceptionTest.java +++ b/quickfixj-core/src/test/java/quickfix/ExceptionTest.java @@ -19,19 +19,22 @@ package quickfix; -import junit.framework.TestCase; +import org.junit.Test; -public class ExceptionTest extends TestCase { +public class ExceptionTest { + @Test public void testRejectLogon() { new RejectLogon(); } + @Test public void testSessionNotFound() { new SessionNotFound(); new SessionNotFound("test"); } + @Test public void testSessionException() { new SessionException(); new SessionException("test"); diff --git a/quickfixj-core/src/test/java/quickfix/ListenerSupportTest.java b/quickfixj-core/src/test/java/quickfix/ListenerSupportTest.java index 2cd9d1348a..fe13decf24 100644 --- a/quickfixj-core/src/test/java/quickfix/ListenerSupportTest.java +++ b/quickfixj-core/src/test/java/quickfix/ListenerSupportTest.java @@ -22,9 +22,10 @@ import java.util.Observable; import java.util.Observer; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; -public class ListenerSupportTest extends TestCase { +public class ListenerSupportTest { private static class ObserverForTest implements Observer { public Object arg; @@ -33,6 +34,7 @@ public void update(Observable o, Object arg) { } } + @Test public void testMulticasting() throws Exception { ListenerSupport support = new ListenerSupport(Observer.class); ObserverForTest observer = new ObserverForTest(); diff --git a/quickfixj-core/src/test/java/quickfix/ScreenLogTest.java b/quickfixj-core/src/test/java/quickfix/ScreenLogTest.java index dd3cf5703d..4fd18a7bfe 100644 --- a/quickfixj-core/src/test/java/quickfix/ScreenLogTest.java +++ b/quickfixj-core/src/test/java/quickfix/ScreenLogTest.java @@ -19,35 +19,36 @@ package quickfix; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import quickfix.field.converter.UtcTimestampConverter; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Date; -public class ScreenLogTest extends TestCase { +public class ScreenLogTest { private long systemTime; - public ScreenLogTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { systemTime = SystemTime.currentTimeMillis(); SystemTime.setTimeSource(new MockSystemTimeSource(systemTime)); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { SystemTime.setTimeSource(null); - super.tearDown(); } + @Test public void testScreenLog() { doScreenLogTest(true); } + @Test public void testScreenLogWithoutHeartBeats() { doScreenLogTest(false); } diff --git a/quickfixj-core/src/test/java/quickfix/mina/CriticalSessionProtocolExceptionTest.java b/quickfixj-core/src/test/java/quickfix/mina/CriticalSessionProtocolExceptionTest.java index 4de2977570..a78b67bd94 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/CriticalSessionProtocolExceptionTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/CriticalSessionProtocolExceptionTest.java @@ -19,11 +19,12 @@ package quickfix.mina; -import junit.framework.TestCase; +import org.junit.Test; -public class CriticalSessionProtocolExceptionTest extends TestCase { +public class CriticalSessionProtocolExceptionTest { // For coverage + @Test public void testConstructors() throws Exception { new CriticalProtocolCodecException(); new CriticalProtocolCodecException(""); diff --git a/quickfixj-core/src/test/java/quickfix/mina/message/FIXProtocolCodecFactoryTest.java b/quickfixj-core/src/test/java/quickfix/mina/message/FIXProtocolCodecFactoryTest.java index 14659ce1e1..0fe17ab3ae 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/message/FIXProtocolCodecFactoryTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/message/FIXProtocolCodecFactoryTest.java @@ -19,9 +19,11 @@ package quickfix.mina.message; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; -public class FIXProtocolCodecFactoryTest extends TestCase { +public class FIXProtocolCodecFactoryTest { + @Test public void testFactory() throws Exception { // Unfortunately, there's not a lot of testing that can be done here FIXProtocolCodecFactory factory = new FIXProtocolCodecFactory(); diff --git a/quickfixj-core/src/test/java/quickfix/test/acceptance/AcceptanceTestSuite.java b/quickfixj-core/src/test/java/quickfix/test/acceptance/AcceptanceTestSuite.java index deacc7c4ab..bdf1420732 100644 --- a/quickfixj-core/src/test/java/quickfix/test/acceptance/AcceptanceTestSuite.java +++ b/quickfixj-core/src/test/java/quickfix/test/acceptance/AcceptanceTestSuite.java @@ -7,6 +7,8 @@ import junit.framework.TestResult; import junit.framework.TestSuite; import org.apache.mina.util.AvailablePortFinder; +import org.junit.runner.RunWith; +import org.junit.runners.AllTests; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import quickfix.Session; @@ -26,6 +28,22 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +/** + * Note on inheritance: + * This class intentionally extends junit.framework.TestSuite (JUnit 3) even though + * it is run with the JUnit 4 runner {@link org.junit.runners.AllTests}. + * + * Rationale: + * - The static {@code suite()} method below programmatically builds a hierarchical + * TestSuite tree and wraps instances of this class into {@link junit.extensions.TestSetup} + * via {@code new AcceptanceTestServerSetUp(new AcceptanceTestSuite(...))}. + * - {@link junit.extensions.TestSetup} expects a {@link junit.framework.Test} and later + * casts {@code getTest()} to {@link junit.framework.TestSuite}. Therefore + * {@code AcceptanceTestSuite} must itself be a TestSuite instance. + * - The AllTests runner discovers and executes the returned {@link junit.framework.Test} + * from {@code suite()}; the inheritance here is required for composition, not for discovery. + */ +@RunWith(AllTests.class) public class AcceptanceTestSuite extends TestSuite { private static final String ATEST_TIMEOUT_KEY = "atest.timeout"; private static final String ATEST_TRANSPORT_KEY = "atest.transport"; diff --git a/quickfixj-messages/quickfixj-messages-all/src/test/java/quickfix/SerializationTest.java b/quickfixj-messages/quickfixj-messages-all/src/test/java/quickfix/SerializationTest.java index 638c5b5e8f..5f733f395c 100644 --- a/quickfixj-messages/quickfixj-messages-all/src/test/java/quickfix/SerializationTest.java +++ b/quickfixj-messages/quickfixj-messages-all/src/test/java/quickfix/SerializationTest.java @@ -19,7 +19,8 @@ package quickfix; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -34,14 +35,11 @@ import java.lang.reflect.Method; import java.util.regex.Pattern; -public class SerializationTest extends TestCase { +public class SerializationTest { private String srcDir; - - public SerializationTest(String name) { - super(name); - } + @Test public void testSerializationWithDataDictionary() throws Exception { Message message = new Message("8=FIX.4.2\0019=40\00135=A\001" + "98=0\001384=2\001372=D\001385=R\001372=8\001385=S\00110=96\001", @@ -51,6 +49,7 @@ public void testSerializationWithDataDictionary() throws Exception { outs.writeObject(message); } + @Test public void testSerialization() { String buildDirectoryName = System.getProperty("buildDirectory"); // generated-sources @@ -274,6 +273,7 @@ private static FieldMap createFieldMapWithDefaultValues(Class cl) throws Inst return res; } + @Test public void testSerialVersionUUID() throws ClassNotFoundException { String buildDirectoryName = System.getProperty("buildDirectory"); String baseDirectory = buildDirectoryName + "/classes";