Skip to content
17 changes: 11 additions & 6 deletions quickfixj-base/src/test/java/quickfix/DayConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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));
Expand Down
33 changes: 27 additions & 6 deletions quickfixj-base/src/test/java/quickfix/DictionaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 {
Expand All @@ -61,6 +66,7 @@ public void testDayTooShort() throws Exception {
}
}

@Test
public void testDayTooUnknown() throws Exception {
dictionary.setString("DAY", "xyz");
try {
Expand All @@ -70,6 +76,7 @@ public void testDayTooUnknown() throws Exception {
}
}

@Test
public void testBoolean() throws Exception {
dictionary.setBool("B", true);
assertTrue(dictionary.getBool("B"));
Expand All @@ -78,6 +85,7 @@ public void testBoolean() throws Exception {
assertFalse(dictionary.getBool("B"));
}

@Test
public void testBooleanError() throws Exception {
dictionary.setString("B", "XYZ");
try {
Expand All @@ -87,6 +95,7 @@ public void testBooleanError() throws Exception {
}
}

@Test
public void testBooleanMissing() throws Exception {
try {
dictionary.getBool("B");
Expand All @@ -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");
Expand All @@ -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 {
Expand All @@ -122,6 +135,7 @@ public void testDoubleError() throws Exception {
}
}

@Test
public void testDoubleMissing() throws Exception {
try {
dictionary.getDouble("B");
Expand All @@ -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 {
Expand All @@ -144,6 +160,7 @@ public void testLongError() throws Exception {
}
}

@Test
public void testLongMissing() throws Exception {
try {
dictionary.getLong("B");
Expand All @@ -152,6 +169,7 @@ public void testLongMissing() throws Exception {
}
}

@Test
public void testMerge() throws Exception {
Dictionary d2 = new Dictionary("ABC");
d2.setString("XYZ", "123");
Expand All @@ -166,13 +184,15 @@ public void testMerge() throws Exception {
assertEquals(1, d2.toMap().size());
}

@Test
public void testName() throws Exception {
assertNull(dictionary.getName());

Dictionary d = new Dictionary("NAME");
assertEquals("NAME", d.getName());
}

@Test
public void testConstructors() throws Exception {
Dictionary dw = new Dictionary();
assertNull(dw.getName());
Expand All @@ -194,6 +214,7 @@ public void testConstructors() throws Exception {
}

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

Expand Down
11 changes: 8 additions & 3 deletions quickfixj-base/src/test/java/quickfix/ExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
25 changes: 21 additions & 4 deletions quickfixj-base/src/test/java/quickfix/SessionIDTest.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jetbrains-junie you did not add any @Test annotations in this class. Please fix it.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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");
Expand All @@ -56,13 +57,15 @@ 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(
"TARGETSUB"));
assertFieldsNoLocation(sessionID);
}

@Test
public void testStringConstructorNoLocation() throws Exception {
SessionID sessionID = new SessionID("FIX.4.2", "SENDER", "SENDERSUB", "TARGET", "TARGETSUB");
assertFieldsNoLocation(sessionID);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -123,6 +130,7 @@ private void assertFieldsNoLocationSubOrQualifier(SessionID sessionID) {
assertEquals("", sessionID.getSessionQualifier());
}

@Test
public void testDefaultConstructorException() throws Exception {
try {
new SessionID();
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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");
Expand All @@ -210,6 +226,7 @@ public void testStringConstructorInvalidID() throws Exception {
}
}

@Test
public void testFromStringUnsupported() {
SessionID sessionID = new SessionID((String) null, (String) null, (String) null);
try {
Expand Down
Loading