1919
2020package quickfix ;
2121
22- import junit .framework .TestCase ;
2322import quickfix .field .ApplVerID ;
2423import quickfix .field .BeginString ;
2524import quickfix .field .DefaultApplVerID ;
3635
3736import static org .hamcrest .Matchers .is ;
3837import static org .hamcrest .Matchers .notNullValue ;
38+ import static org .junit .Assert .assertEquals ;
39+ import static org .junit .Assert .assertNull ;
3940import static org .junit .Assert .assertThat ;
41+ import static org .junit .Assert .fail ;
42+ import org .junit .Test ;
4043import static org .mockito .Matchers .any ;
4144import static org .mockito .Mockito .mock ;
42- import static org .mockito .Mockito .stub ;
4345import static org .mockito .Mockito .when ;
4446
45- public class MessageUtilsTest extends TestCase {
47+ public class MessageUtilsTest {
4648
49+ @ Test
4750 public void testGetStringField () throws Exception {
4851 String messageString = "8=FIX.4.2\001 9=12\001 35=X\001 108=30\001 10=049\001 " ;
4952 assertEquals ("wrong value" , "FIX.4.2" , MessageUtils .getStringField (messageString ,
@@ -52,6 +55,7 @@ public void testGetStringField() throws Exception {
5255 assertNull (messageString , MessageUtils .getStringField (messageString , SenderCompID .FIELD ));
5356 }
5457
58+ @ Test
5559 public void testSessionIdFromMessage () throws Exception {
5660 Message message = new Logon ();
5761 message .getHeader ().setString (SenderCompID .FIELD , "TW" );
@@ -62,6 +66,7 @@ public void testSessionIdFromMessage() throws Exception {
6266 assertEquals ("ISLD" , sessionID .getTargetCompID ());
6367 }
6468
69+ @ Test
6570 public void testReverseSessionIdFromMessage () throws Exception {
6671 Message message = new Logon ();
6772 message .getHeader ().setString (SenderCompID .FIELD , "TW" );
@@ -72,6 +77,7 @@ public void testReverseSessionIdFromMessage() throws Exception {
7277 assertEquals ("TW" , sessionID .getTargetCompID ());
7378 }
7479
80+ @ Test
7581 public void testReverseSessionIdFromMessageWithMissingFields () throws Exception {
7682 Message message = new Logon ();
7783 SessionID sessionID = MessageUtils .getReverseSessionID (message );
@@ -80,6 +86,7 @@ public void testReverseSessionIdFromMessageWithMissingFields() throws Exception
8086 assertEquals (sessionID .getTargetCompID (), SessionID .NOT_SET );
8187 }
8288
89+ @ Test
8390 public void testSessionIdFromRawMessage () throws Exception {
8491 String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
8592 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
@@ -89,6 +96,7 @@ public void testSessionIdFromRawMessage() throws Exception {
8996 assertEquals ("ISLD" , sessionID .getTargetCompID ());
9097 }
9198
99+ @ Test
92100 public void testReverseSessionIdFromRawMessage () throws Exception {
93101 String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 50=TWS\001 " +
94102 "142=TWL\001 52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
@@ -100,12 +108,14 @@ public void testReverseSessionIdFromRawMessage() throws Exception {
100108 assertEquals ("TWL" , sessionID .getTargetLocationID ());
101109 }
102110
111+ @ Test
103112 public void testMessageType () throws Exception {
104113 String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
105114 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
106115 assertEquals ("A" , MessageUtils .getMessageType (messageString ));
107116 }
108117
118+ @ Test
109119 public void testMessageTypeError () throws Exception {
110120 String messageString = "8=FIX.4.0\001 9=56\001 34=1\001 49=TW\001 " +
111121 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
@@ -117,6 +127,7 @@ public void testMessageTypeError() throws Exception {
117127 }
118128 }
119129
130+ @ Test
120131 public void testMessageTypeError2 () throws Exception {
121132 String messageString = "8=FIX.4.0\001 9=56\001 35=1" ;
122133 try {
@@ -127,23 +138,26 @@ public void testMessageTypeError2() throws Exception {
127138 }
128139 }
129140
141+ @ Test
130142 public void testGetNonexistentStringField () throws Exception {
131143 String messageString = "8=FIX.4.0\001 9=56\001 34=1\001 49=TW\001 " +
132144 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
133145 assertNull (MessageUtils .getStringField (messageString , 35 ));
134146 }
135147
148+ @ Test
136149 public void testGetStringFieldWithBadValue () throws Exception {
137150 String messageString = "8=FIX.4.0\001 9=56\001 34=1\001 49=TW\001 " +
138151 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223" ;
139152 assertNull (MessageUtils .getStringField (messageString , 10 ));
140153 }
141154
155+ @ Test
142156 public void testParse () throws Exception {
143157 Session mockSession = mock (Session .class );
144158 DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
145- stub (mockSession .getDataDictionaryProvider ()).toReturn (mockDataDictionaryProvider );
146- stub (mockSession .getMessageFactory ()).toReturn (new quickfix .fix40 .MessageFactory ());
159+ when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
160+ when (mockSession .getMessageFactory ()).thenReturn (new quickfix .fix40 .MessageFactory ());
147161 String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
148162 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=223\001 " ;
149163
@@ -152,6 +166,7 @@ public void testParse() throws Exception {
152166 assertThat (message , is (notNullValue ()));
153167 }
154168
169+ @ Test
155170 public void testLegacyParse () throws Exception {
156171 String data = "8=FIX.4.4\001 9=309\001 35=8\001 49=ASX\001 56=CL1_FIX44\001 34=4\001 " +
157172 "52=20060324-01:05:58\001 17=X-B-WOW-1494E9A0:58BD3F9D-1109\001 150=D\001 " +
@@ -164,11 +179,12 @@ public void testLegacyParse() throws Exception {
164179 assertThat (message , is (notNullValue ()));
165180 }
166181
182+ @ Test
167183 public void testParseFixt () throws Exception {
168184 Session mockSession = mock (Session .class );
169185 DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
170- stub (mockSession .getDataDictionaryProvider ()).toReturn (mockDataDictionaryProvider );
171- stub (mockSession .getMessageFactory ()).toReturn (new quickfix .fix40 .MessageFactory ());
186+ when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
187+ when (mockSession .getMessageFactory ()).thenReturn (new quickfix .fix40 .MessageFactory ());
172188
173189 Email email = new Email (new EmailThreadID ("THREAD_ID" ), new EmailType (EmailType .NEW ), new Subject ("SUBJECT" ));
174190 email .getHeader ().setField (new ApplVerID (ApplVerID .FIX42 ));
@@ -181,11 +197,12 @@ public void testParseFixt() throws Exception {
181197 assertThat (message , is (quickfix .fix40 .Email .class ));
182198 }
183199
200+ @ Test
184201 public void testParseFixtLogon () throws Exception {
185202 Session mockSession = mock (Session .class );
186203 DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
187- stub (mockSession .getDataDictionaryProvider ()).toReturn (mockDataDictionaryProvider );
188- stub (mockSession .getMessageFactory ()).toReturn (new DefaultMessageFactory ());
204+ when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
205+ when (mockSession .getMessageFactory ()).thenReturn (new DefaultMessageFactory ());
189206
190207 quickfix .fixt11 .Logon logon = new quickfix .fixt11 .Logon (new EncryptMethod (EncryptMethod .NONE_OTHER ), new HeartBtInt (30 ),
191208 new DefaultApplVerID (ApplVerID .FIX42 ));
@@ -196,11 +213,12 @@ public void testParseFixtLogon() throws Exception {
196213 assertThat (message , is (quickfix .fixt11 .Logon .class ));
197214 }
198215
216+ @ Test
199217 public void testParseFixtLogout () throws Exception {
200218 Session mockSession = mock (Session .class );
201219 DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
202- stub (mockSession .getDataDictionaryProvider ()).toReturn (mockDataDictionaryProvider );
203- stub (mockSession .getMessageFactory ()).toReturn (new DefaultMessageFactory ());
220+ when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
221+ when (mockSession .getMessageFactory ()).thenReturn (new DefaultMessageFactory ());
204222
205223 quickfix .fixt11 .Logout logout = new quickfix .fixt11 .Logout ();
206224
@@ -210,11 +228,12 @@ public void testParseFixtLogout() throws Exception {
210228 assertThat (message , is (quickfix .fixt11 .Logout .class ));
211229 }
212230
231+ @ Test
213232 public void testParseFix50 () throws Exception {
214233 Session mockSession = mock (Session .class );
215234 DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
216- stub (mockSession .getDataDictionaryProvider ()).toReturn (mockDataDictionaryProvider );
217- stub (mockSession .getMessageFactory ()).toReturn (new DefaultMessageFactory ());
235+ when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
236+ when (mockSession .getMessageFactory ()).thenReturn (new DefaultMessageFactory ());
218237
219238 Email email = new Email (new EmailThreadID ("THREAD_ID" ), new EmailType (EmailType .NEW ), new Subject ("SUBJECT" ));
220239 email .getHeader ().setField (new ApplVerID (ApplVerID .FIX50 ));
@@ -228,15 +247,16 @@ public void testParseFix50() throws Exception {
228247 }
229248
230249 // QFJ-973
250+ @ Test
231251 public void testParseMessageWithoutChecksumValidation () throws InvalidMessage {
232252 Session mockSession = mock (Session .class );
233253 when (mockSession .isValidateChecksum ()).thenReturn (Boolean .FALSE );
234254
235255 DataDictionary dataDictionary = mock (DataDictionary .class );
236256 DataDictionaryProvider mockDataDictionaryProvider = mock (DataDictionaryProvider .class );
237257 when (mockDataDictionaryProvider .getSessionDataDictionary (any (String .class ))).thenReturn (dataDictionary );
238- stub (mockSession .getDataDictionaryProvider ()).toReturn (mockDataDictionaryProvider );
239- stub (mockSession .getMessageFactory ()).toReturn (new quickfix .fix40 .MessageFactory ());
258+ when (mockSession .getDataDictionaryProvider ()).thenReturn (mockDataDictionaryProvider );
259+ when (mockSession .getMessageFactory ()).thenReturn (new quickfix .fix40 .MessageFactory ());
240260
241261 String messageString = "8=FIX.4.0\001 9=56\001 35=A\001 34=1\001 49=TW\001 " +
242262 "52=20060118-16:34:19\001 56=ISLD\001 98=0\001 108=2\001 10=283\001 " ;
0 commit comments