Skip to content

Commit 5aa37ef

Browse files
authored
update Mockito to 3.x and switch build to JDK17 (#416)
* update mockito to check for better JDK17 support * Replaced `stub()` by `when()`. * Changed Mockito matchers since they no longer match `null`. * added --add-opens to prevent test failure * Added profile for surefire on JDK8 and other JDKs
1 parent 9041f34 commit 5aa37ef

File tree

9 files changed

+167
-95
lines changed

9 files changed

+167
-95
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-18.04, macOS-latest, windows-2016]
16-
java: [8, 11, 15]
16+
java: [8, 11, 17]
1717
fail-fast: false
1818
max-parallel: 4
1919
name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}

quickfixj-core/pom.xml

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
</dependency>
2828
<dependency>
2929
<groupId>org.mockito</groupId>
30-
<artifactId>mockito-all</artifactId>
31-
<version>1.10.19</version>
30+
<artifactId>mockito-core</artifactId>
31+
<version>3.12.4</version>
3232
<scope>test</scope>
3333
</dependency>
3434
<dependency>
@@ -379,29 +379,6 @@
379379
</instructions>
380380
</configuration>
381381
</plugin>
382-
<plugin>
383-
<groupId>org.apache.maven.plugins</groupId>
384-
<artifactId>maven-surefire-plugin</artifactId>
385-
<configuration>
386-
<argLine>-Xmx512m -Djava.net.preferIPv4Stack=true</argLine>
387-
<trimStackTrace>false</trimStackTrace>
388-
<includes>
389-
<include>**/*Test.java</include>
390-
<include>${acceptance.tests}</include>
391-
</includes>
392-
<excludes>
393-
<exclude>**/*ForTest.java</exclude>
394-
<exclude>**/Abstract*Test.java</exclude>
395-
<exclude>**/AcceptanceTestSuite$*</exclude>
396-
</excludes>
397-
<systemPropertyVariables>
398-
<atest.heartbeat>5</atest.heartbeat>
399-
<atest.timeout>60000</atest.timeout>
400-
<atest.reconnectDelay>5</atest.reconnectDelay>
401-
<atest.skipslow>false</atest.skipslow>
402-
</systemPropertyVariables>
403-
</configuration>
404-
</plugin>
405382
</plugins>
406383
</build>
407384

@@ -436,5 +413,78 @@
436413
<acceptance.tests />
437414
</properties>
438415
</profile>
416+
<!-- select different java options on JDK8 for surefire since otherwise the build will fail -->
417+
<profile>
418+
<id>surefire-java8</id>
419+
<activation>
420+
<jdk>1.8</jdk>
421+
</activation>
422+
<build>
423+
<plugins>
424+
<plugin>
425+
<groupId>org.apache.maven.plugins</groupId>
426+
<artifactId>maven-surefire-plugin</artifactId>
427+
<configuration>
428+
<argLine>
429+
-Xmx512m -Djava.net.preferIPv4Stack=true
430+
</argLine>
431+
<trimStackTrace>false</trimStackTrace>
432+
<includes>
433+
<include>**/*Test.java</include>
434+
<include>${acceptance.tests}</include>
435+
</includes>
436+
<excludes>
437+
<exclude>**/*ForTest.java</exclude>
438+
<exclude>**/Abstract*Test.java</exclude>
439+
<exclude>**/AcceptanceTestSuite$*</exclude>
440+
</excludes>
441+
<systemPropertyVariables>
442+
<atest.heartbeat>5</atest.heartbeat>
443+
<atest.timeout>60000</atest.timeout>
444+
<atest.reconnectDelay>5</atest.reconnectDelay>
445+
<atest.skipslow>false</atest.skipslow>
446+
</systemPropertyVariables>
447+
</configuration>
448+
</plugin>
449+
</plugins>
450+
</build>
451+
</profile>
452+
<!-- surefire for JDK9 and upwards -->
453+
<profile>
454+
<id>surefire</id>
455+
<activation>
456+
<jdk>[1.9,)</jdk>
457+
</activation>
458+
<build>
459+
<plugins>
460+
<plugin>
461+
<groupId>org.apache.maven.plugins</groupId>
462+
<artifactId>maven-surefire-plugin</artifactId>
463+
<configuration>
464+
<argLine>
465+
-Xmx512m -Djava.net.preferIPv4Stack=true
466+
--add-opens java.base/java.lang=ALL-UNNAMED
467+
</argLine>
468+
<trimStackTrace>false</trimStackTrace>
469+
<includes>
470+
<include>**/*Test.java</include>
471+
<include>${acceptance.tests}</include>
472+
</includes>
473+
<excludes>
474+
<exclude>**/*ForTest.java</exclude>
475+
<exclude>**/Abstract*Test.java</exclude>
476+
<exclude>**/AcceptanceTestSuite$*</exclude>
477+
</excludes>
478+
<systemPropertyVariables>
479+
<atest.heartbeat>5</atest.heartbeat>
480+
<atest.timeout>60000</atest.timeout>
481+
<atest.reconnectDelay>5</atest.reconnectDelay>
482+
<atest.skipslow>false</atest.skipslow>
483+
</systemPropertyVariables>
484+
</configuration>
485+
</plugin>
486+
</plugins>
487+
</build>
488+
</profile>
439489
</profiles>
440490
</project>

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
import static org.hamcrest.CoreMatchers.notNullValue;
2323
import static org.junit.Assert.assertThat;
2424
import static org.junit.Assert.assertTrue;
25-
import static org.mockito.Mockito.mock;
26-
import static org.mockito.Mockito.stub;
2725

2826
import java.io.InvalidObjectException;
2927

30-
import org.junit.Before;
3128
import org.junit.Test;
3229

3330
import quickfix.MessageCracker.RedundantHandlerException;
@@ -41,14 +38,6 @@
4138

4239
public class MessageCrackerTest {
4340
private int messageCracked;
44-
private Session mockSession;
45-
46-
@Before
47-
public void setUp() throws Exception {
48-
mockSession = mock(Session.class);
49-
stub(mockSession.getTargetDefaultApplicationVersionID()).toReturn(
50-
new ApplVerID(ApplVerID.FIX50SP2));
51-
}
5241

5342
@Test(expected=UnsupportedMessageType.class)
5443
public void testInvokerException1() throws Exception {
@@ -241,8 +230,6 @@ public void onMessage(quickfix.fix44.Email email, SessionID sessionID) {
241230
@Test
242231
public void testFixtMessageCrackingWithSessionDefaultApplVerID() throws Exception {
243232
quickfix.fix44.Email message = createFix44Email();
244-
stub(mockSession.getTargetDefaultApplicationVersionID()).toReturn(
245-
new ApplVerID(ApplVerID.FIX44));
246233

247234
MessageCracker cracker = new MessageCracker() {
248235
@SuppressWarnings("unused")

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package quickfix;
2121

22-
import junit.framework.TestCase;
2322
import quickfix.field.ApplVerID;
2423
import quickfix.field.BeginString;
2524
import quickfix.field.DefaultApplVerID;
@@ -36,14 +35,18 @@
3635

3736
import static org.hamcrest.Matchers.is;
3837
import static org.hamcrest.Matchers.notNullValue;
38+
import static org.junit.Assert.assertEquals;
39+
import static org.junit.Assert.assertNull;
3940
import static org.junit.Assert.assertThat;
41+
import static org.junit.Assert.fail;
42+
import org.junit.Test;
4043
import static org.mockito.Matchers.any;
4144
import static org.mockito.Mockito.mock;
42-
import static org.mockito.Mockito.stub;
4345
import 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\0019=12\00135=X\001108=30\00110=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\0019=56\00135=A\00134=1\00149=TW\001" +
8592
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=56\00135=A\00134=1\00149=TW\00150=TWS\001" +
94102
"142=TWL\00152=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=56\00135=A\00134=1\00149=TW\001" +
105114
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=56\00134=1\00149=TW\001" +
111121
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=56\00135=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\0019=56\00134=1\00149=TW\001" +
132144
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=56\00134=1\00149=TW\001" +
138151
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=56\00135=A\00134=1\00149=TW\001" +
148162
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=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\0019=309\00135=8\00149=ASX\00156=CL1_FIX44\00134=4\001" +
157172
"52=20060324-01:05:58\00117=X-B-WOW-1494E9A0:58BD3F9D-1109\001150=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\0019=56\00135=A\00134=1\00149=TW\001" +
242262
"52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=283\001";

0 commit comments

Comments
 (0)