From b33f0940b2621b70fece6fa113638c535ccdf8ae Mon Sep 17 00:00:00 2001 From: Christoph John Date: Mon, 4 Oct 2021 00:35:30 +0200 Subject: [PATCH 1/7] update mockito to check for better JDK17 support --- quickfixj-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickfixj-core/pom.xml b/quickfixj-core/pom.xml index 252edbc973..518e67f91a 100644 --- a/quickfixj-core/pom.xml +++ b/quickfixj-core/pom.xml @@ -27,8 +27,8 @@ org.mockito - mockito-all - 1.10.19 + mockito-core + 3.12.4 test From b755a9d7483c31545d86f5bb41a5f1ba06bb5673 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Tue, 5 Oct 2021 22:50:25 +0200 Subject: [PATCH 2/7] Replaced `stub()` by `when()`. --- .../java/quickfix/MessageCrackerTest.java | 13 ----- .../test/java/quickfix/MessageUtilsTest.java | 50 +++++++++++++------ .../src/test/java/quickfix/SessionTest.java | 11 ++-- .../quickfix/mina/IoSessionResponderTest.java | 45 +++++++++++------ .../mina/acceptor/AcceptorIoHandlerTest.java | 18 +++---- .../initiator/InitiatorIoHandlerTest.java | 6 +-- 6 files changed, 81 insertions(+), 62 deletions(-) diff --git a/quickfixj-core/src/test/java/quickfix/MessageCrackerTest.java b/quickfixj-core/src/test/java/quickfix/MessageCrackerTest.java index 2056517d7a..1599ec1f8e 100644 --- a/quickfixj-core/src/test/java/quickfix/MessageCrackerTest.java +++ b/quickfixj-core/src/test/java/quickfix/MessageCrackerTest.java @@ -22,12 +22,9 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.stub; import java.io.InvalidObjectException; -import org.junit.Before; import org.junit.Test; import quickfix.MessageCracker.RedundantHandlerException; @@ -41,14 +38,6 @@ public class MessageCrackerTest { private int messageCracked; - private Session mockSession; - - @Before - public void setUp() throws Exception { - mockSession = mock(Session.class); - stub(mockSession.getTargetDefaultApplicationVersionID()).toReturn( - new ApplVerID(ApplVerID.FIX50SP2)); - } @Test(expected=UnsupportedMessageType.class) public void testInvokerException1() throws Exception { @@ -241,8 +230,6 @@ public void onMessage(quickfix.fix44.Email email, SessionID sessionID) { @Test public void testFixtMessageCrackingWithSessionDefaultApplVerID() throws Exception { quickfix.fix44.Email message = createFix44Email(); - stub(mockSession.getTargetDefaultApplicationVersionID()).toReturn( - new ApplVerID(ApplVerID.FIX44)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") diff --git a/quickfixj-core/src/test/java/quickfix/MessageUtilsTest.java b/quickfixj-core/src/test/java/quickfix/MessageUtilsTest.java index 872bacaffc..b42da2255d 100644 --- a/quickfixj-core/src/test/java/quickfix/MessageUtilsTest.java +++ b/quickfixj-core/src/test/java/quickfix/MessageUtilsTest.java @@ -19,7 +19,6 @@ package quickfix; -import junit.framework.TestCase; import quickfix.field.ApplVerID; import quickfix.field.BeginString; import quickfix.field.DefaultApplVerID; @@ -36,14 +35,18 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; +import org.junit.Test; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.stub; import static org.mockito.Mockito.when; -public class MessageUtilsTest extends TestCase { +public class MessageUtilsTest { + @Test public void testGetStringField() throws Exception { String messageString = "8=FIX.4.2\0019=12\00135=X\001108=30\00110=049\001"; assertEquals("wrong value", "FIX.4.2", MessageUtils.getStringField(messageString, @@ -52,6 +55,7 @@ public void testGetStringField() throws Exception { assertNull(messageString, MessageUtils.getStringField(messageString, SenderCompID.FIELD)); } + @Test public void testSessionIdFromMessage() throws Exception { Message message = new Logon(); message.getHeader().setString(SenderCompID.FIELD, "TW"); @@ -62,6 +66,7 @@ public void testSessionIdFromMessage() throws Exception { assertEquals("ISLD", sessionID.getTargetCompID()); } + @Test public void testReverseSessionIdFromMessage() throws Exception { Message message = new Logon(); message.getHeader().setString(SenderCompID.FIELD, "TW"); @@ -72,6 +77,7 @@ public void testReverseSessionIdFromMessage() throws Exception { assertEquals("TW", sessionID.getTargetCompID()); } + @Test public void testReverseSessionIdFromMessageWithMissingFields() throws Exception { Message message = new Logon(); SessionID sessionID = MessageUtils.getReverseSessionID(message); @@ -80,6 +86,7 @@ public void testReverseSessionIdFromMessageWithMissingFields() throws Exception assertEquals(sessionID.getTargetCompID(), SessionID.NOT_SET); } + @Test public void testSessionIdFromRawMessage() throws Exception { String messageString = "8=FIX.4.0\0019=56\00135=A\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=223\001"; @@ -89,6 +96,7 @@ public void testSessionIdFromRawMessage() throws Exception { assertEquals("ISLD", sessionID.getTargetCompID()); } + @Test public void testReverseSessionIdFromRawMessage() throws Exception { String messageString = "8=FIX.4.0\0019=56\00135=A\00134=1\00149=TW\00150=TWS\001" + "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 { assertEquals("TWL", sessionID.getTargetLocationID()); } + @Test public void testMessageType() throws Exception { String messageString = "8=FIX.4.0\0019=56\00135=A\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=223\001"; assertEquals("A", MessageUtils.getMessageType(messageString)); } + @Test public void testMessageTypeError() throws Exception { String messageString = "8=FIX.4.0\0019=56\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=223\001"; @@ -117,6 +127,7 @@ public void testMessageTypeError() throws Exception { } } + @Test public void testMessageTypeError2() throws Exception { String messageString = "8=FIX.4.0\0019=56\00135=1"; try { @@ -127,23 +138,26 @@ public void testMessageTypeError2() throws Exception { } } + @Test public void testGetNonexistentStringField() throws Exception { String messageString = "8=FIX.4.0\0019=56\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=223\001"; assertNull(MessageUtils.getStringField(messageString, 35)); } + @Test public void testGetStringFieldWithBadValue() throws Exception { String messageString = "8=FIX.4.0\0019=56\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=223"; assertNull(MessageUtils.getStringField(messageString, 10)); } + @Test public void testParse() throws Exception { Session mockSession = mock(Session.class); DataDictionaryProvider mockDataDictionaryProvider = mock(DataDictionaryProvider.class); - stub(mockSession.getDataDictionaryProvider()).toReturn(mockDataDictionaryProvider); - stub(mockSession.getMessageFactory()).toReturn(new quickfix.fix40.MessageFactory()); + when(mockSession.getDataDictionaryProvider()).thenReturn(mockDataDictionaryProvider); + when(mockSession.getMessageFactory()).thenReturn(new quickfix.fix40.MessageFactory()); String messageString = "8=FIX.4.0\0019=56\00135=A\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=223\001"; @@ -152,6 +166,7 @@ public void testParse() throws Exception { assertThat(message, is(notNullValue())); } + @Test public void testLegacyParse() throws Exception { String data = "8=FIX.4.4\0019=309\00135=8\00149=ASX\00156=CL1_FIX44\00134=4\001" + "52=20060324-01:05:58\00117=X-B-WOW-1494E9A0:58BD3F9D-1109\001150=D\001" + @@ -164,11 +179,12 @@ public void testLegacyParse() throws Exception { assertThat(message, is(notNullValue())); } + @Test public void testParseFixt() throws Exception { Session mockSession = mock(Session.class); DataDictionaryProvider mockDataDictionaryProvider = mock(DataDictionaryProvider.class); - stub(mockSession.getDataDictionaryProvider()).toReturn(mockDataDictionaryProvider); - stub(mockSession.getMessageFactory()).toReturn(new quickfix.fix40.MessageFactory()); + when(mockSession.getDataDictionaryProvider()).thenReturn(mockDataDictionaryProvider); + when(mockSession.getMessageFactory()).thenReturn(new quickfix.fix40.MessageFactory()); Email email = new Email(new EmailThreadID("THREAD_ID"), new EmailType(EmailType.NEW), new Subject("SUBJECT")); email.getHeader().setField(new ApplVerID(ApplVerID.FIX42)); @@ -181,11 +197,12 @@ public void testParseFixt() throws Exception { assertThat(message, is(quickfix.fix40.Email.class)); } + @Test public void testParseFixtLogon() throws Exception { Session mockSession = mock(Session.class); DataDictionaryProvider mockDataDictionaryProvider = mock(DataDictionaryProvider.class); - stub(mockSession.getDataDictionaryProvider()).toReturn(mockDataDictionaryProvider); - stub(mockSession.getMessageFactory()).toReturn(new DefaultMessageFactory()); + when(mockSession.getDataDictionaryProvider()).thenReturn(mockDataDictionaryProvider); + when(mockSession.getMessageFactory()).thenReturn(new DefaultMessageFactory()); quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod(EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); @@ -196,11 +213,12 @@ public void testParseFixtLogon() throws Exception { assertThat(message, is(quickfix.fixt11.Logon.class)); } + @Test public void testParseFixtLogout() throws Exception { Session mockSession = mock(Session.class); DataDictionaryProvider mockDataDictionaryProvider = mock(DataDictionaryProvider.class); - stub(mockSession.getDataDictionaryProvider()).toReturn(mockDataDictionaryProvider); - stub(mockSession.getMessageFactory()).toReturn(new DefaultMessageFactory()); + when(mockSession.getDataDictionaryProvider()).thenReturn(mockDataDictionaryProvider); + when(mockSession.getMessageFactory()).thenReturn(new DefaultMessageFactory()); quickfix.fixt11.Logout logout = new quickfix.fixt11.Logout(); @@ -210,11 +228,12 @@ public void testParseFixtLogout() throws Exception { assertThat(message, is(quickfix.fixt11.Logout.class)); } + @Test public void testParseFix50() throws Exception { Session mockSession = mock(Session.class); DataDictionaryProvider mockDataDictionaryProvider = mock(DataDictionaryProvider.class); - stub(mockSession.getDataDictionaryProvider()).toReturn(mockDataDictionaryProvider); - stub(mockSession.getMessageFactory()).toReturn(new DefaultMessageFactory()); + when(mockSession.getDataDictionaryProvider()).thenReturn(mockDataDictionaryProvider); + when(mockSession.getMessageFactory()).thenReturn(new DefaultMessageFactory()); Email email = new Email(new EmailThreadID("THREAD_ID"), new EmailType(EmailType.NEW), new Subject("SUBJECT")); email.getHeader().setField(new ApplVerID(ApplVerID.FIX50)); @@ -228,6 +247,7 @@ public void testParseFix50() throws Exception { } // QFJ-973 + @Test public void testParseMessageWithoutChecksumValidation() throws InvalidMessage { Session mockSession = mock(Session.class); when(mockSession.isValidateChecksum()).thenReturn(Boolean.FALSE); @@ -235,8 +255,8 @@ public void testParseMessageWithoutChecksumValidation() throws InvalidMessage { DataDictionary dataDictionary = mock(DataDictionary.class); DataDictionaryProvider mockDataDictionaryProvider = mock(DataDictionaryProvider.class); when(mockDataDictionaryProvider.getSessionDataDictionary(any(String.class))).thenReturn(dataDictionary); - stub(mockSession.getDataDictionaryProvider()).toReturn(mockDataDictionaryProvider); - stub(mockSession.getMessageFactory()).toReturn(new quickfix.fix40.MessageFactory()); + when(mockSession.getDataDictionaryProvider()).thenReturn(mockDataDictionaryProvider); + when(mockSession.getMessageFactory()).thenReturn(new quickfix.fix40.MessageFactory()); String messageString = "8=FIX.4.0\0019=56\00135=A\00134=1\00149=TW\001" + "52=20060118-16:34:19\00156=ISLD\00198=0\001108=2\00110=283\001"; diff --git a/quickfixj-core/src/test/java/quickfix/SessionTest.java b/quickfixj-core/src/test/java/quickfix/SessionTest.java index c246581fe3..3293c932d7 100644 --- a/quickfixj-core/src/test/java/quickfix/SessionTest.java +++ b/quickfixj-core/src/test/java/quickfix/SessionTest.java @@ -64,7 +64,6 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.stub; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -91,12 +90,11 @@ public void testDisposalOfFileResources() throws Exception { final MessageStoreFactory mockMessageStoreFactory = mock(MessageStoreFactory.class); final CloseableMessageStore mockMessageStore = mock(CloseableMessageStore.class); - stub(mockMessageStoreFactory.create(sessionID)).toReturn( - mockMessageStore); + when(mockMessageStoreFactory.create(sessionID)).thenReturn(mockMessageStore); final LogFactory mockLogFactory = mock(LogFactory.class); final CloseableLog mockLog = mock(CloseableLog.class); - stub(mockLogFactory.create(sessionID)).toReturn(mockLog); + when(mockLogFactory.create(sessionID)).thenReturn(mockLog); try (Session session = new Session(application, mockMessageStoreFactory, sessionID, null, null, mockLogFactory, @@ -132,12 +130,11 @@ public void testNondisposableFileResources() throws Exception { final MessageStoreFactory mockMessageStoreFactory = mock(MessageStoreFactory.class); final MessageStore mockMessageStore = mock(MessageStore.class); - stub(mockMessageStoreFactory.create(sessionID)).toReturn( - mockMessageStore); + when(mockMessageStoreFactory.create(sessionID)).thenReturn(mockMessageStore); final LogFactory mockLogFactory = mock(LogFactory.class); final Log mockLog = mock(Log.class); - stub(mockLogFactory.create(sessionID)).toReturn(mockLog); + when(mockLogFactory.create(sessionID)).thenReturn(mockLog); try (Session session = new Session(application, mockMessageStoreFactory, sessionID, null, null, mockLogFactory, diff --git a/quickfixj-core/src/test/java/quickfix/mina/IoSessionResponderTest.java b/quickfixj-core/src/test/java/quickfix/mina/IoSessionResponderTest.java index 0ee62f5d28..77d2ac6546 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/IoSessionResponderTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/IoSessionResponderTest.java @@ -19,20 +19,30 @@ package quickfix.mina; -import junit.framework.TestCase; +import java.net.InetSocketAddress; import org.apache.mina.core.future.WriteFuture; import org.apache.mina.core.session.IoSession; -import java.net.InetSocketAddress; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; -import static org.mockito.Mockito.*; -public class IoSessionResponderTest extends TestCase { +public class IoSessionResponderTest { + + @Test public void testAsynchronousSend() throws Exception { IoSession mockIoSession = mock(IoSession.class); WriteFuture mockWriteFuture = mock(WriteFuture.class); - stub(mockWriteFuture.isWritten()).toReturn(true); - stub(mockIoSession.write("abcd")).toReturn(mockWriteFuture); + when(mockWriteFuture.isWritten()).thenReturn(true); + when(mockIoSession.write("abcd")).thenReturn(mockWriteFuture); IoSessionResponder responder = new IoSessionResponder(mockIoSession, false, 0, 0); boolean result = responder.send("abcd"); @@ -43,12 +53,13 @@ public void testAsynchronousSend() throws Exception { verifyNoMoreInteractions(mockIoSession); } + @Test public void testSynchronousSend() throws Exception { int timeout = 123; IoSession mockIoSession = mock(IoSession.class); WriteFuture mockWriteFuture = mock(WriteFuture.class); - stub(mockIoSession.write("abcd")).toReturn(mockWriteFuture); - stub(mockWriteFuture.awaitUninterruptibly(timeout)).toReturn(true); + when(mockIoSession.write("abcd")).thenReturn(mockWriteFuture); + when(mockWriteFuture.awaitUninterruptibly(timeout)).thenReturn(true); IoSessionResponder responder = new IoSessionResponder(mockIoSession, true, timeout, 0); boolean result = responder.send("abcd"); @@ -60,12 +71,13 @@ public void testSynchronousSend() throws Exception { verifyNoMoreInteractions(mockIoSession); } + @Test public void testSynchronousSendWithJoinException() throws Exception { int timeout = 123; IoSession mockIoSession = mock(IoSession.class); WriteFuture mockWriteFuture = mock(WriteFuture.class); - stub(mockIoSession.write("abcd")).toReturn(mockWriteFuture); + when(mockIoSession.write("abcd")).thenReturn(mockWriteFuture); doThrow(new RuntimeException("TEST")).when(mockWriteFuture).awaitUninterruptibly(timeout); IoSessionResponder responder = new IoSessionResponder(mockIoSession, true, timeout, 0); @@ -78,13 +90,14 @@ public void testSynchronousSendWithJoinException() throws Exception { verifyNoMoreInteractions(mockIoSession); } + @Test public void testSynchronousSendWithJoinTimeout() throws Exception { int timeout = 123; IoSession mockIoSession = mock(IoSession.class); WriteFuture mockWriteFuture = mock(WriteFuture.class); - stub(mockIoSession.write("abcd")).toReturn(mockWriteFuture); - stub(mockWriteFuture.awaitUninterruptibly(timeout)).toReturn(false); + when(mockIoSession.write("abcd")).thenReturn(mockWriteFuture); + when(mockWriteFuture.awaitUninterruptibly(timeout)).thenReturn(false); IoSessionResponder responder = new IoSessionResponder(mockIoSession, true, timeout, 0); boolean result = responder.send("abcd"); @@ -96,10 +109,12 @@ public void testSynchronousSendWithJoinTimeout() throws Exception { verifyNoMoreInteractions(mockIoSession); } + @Test public void testDisconnect() throws Exception { IoSession mockProtocolSession = mock(IoSession.class); - stub(mockProtocolSession.getScheduledWriteMessages()).toReturn(0); - stub(mockProtocolSession.closeNow()).toReturn(null); + + when(mockProtocolSession.getScheduledWriteMessages()).thenReturn(0); + when(mockProtocolSession.closeNow()).thenReturn(null); IoSessionResponder responder = new IoSessionResponder(mockProtocolSession, false, 0, 0); responder.disconnect(); @@ -110,10 +125,10 @@ public void testDisconnect() throws Exception { verifyNoMoreInteractions(mockProtocolSession); } + @Test public void testGetRemoteSocketAddress() throws Exception { IoSession mockProtocolSession = mock(IoSession.class); - stub(mockProtocolSession.getRemoteAddress()).toReturn( - new InetSocketAddress("1.2.3.4", 5432)); + when(mockProtocolSession.getRemoteAddress()).thenReturn(new InetSocketAddress("1.2.3.4", 5432)); IoSessionResponder responder = new IoSessionResponder(mockProtocolSession, false, 0, 0); diff --git a/quickfixj-core/src/test/java/quickfix/mina/acceptor/AcceptorIoHandlerTest.java b/quickfixj-core/src/test/java/quickfix/mina/acceptor/AcceptorIoHandlerTest.java index 850acbda47..15405da74c 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/acceptor/AcceptorIoHandlerTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/acceptor/AcceptorIoHandlerTest.java @@ -57,9 +57,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.stub; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; public class AcceptorIoHandlerTest { @@ -78,7 +78,7 @@ public void testFIXTLogonAndApplVerID() throws Exception { "TARGET"); try (Session session = SessionFactoryTestSupport.createSession(sessionID, new UnitTestApplication(), false)) { - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); // to create a new Session + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); // to create a new Session final HashMap acceptorSessions = new HashMap<>(); acceptorSessions.put(sessionID, session); @@ -105,7 +105,7 @@ public void testFIXTLogonAndApplVerID() throws Exception { public void testMessageBeforeLogon() throws Exception { IoSession mockIoSession = mock(IoSession.class); SessionSettings settings = mock(SessionSettings.class); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); EventHandlingStrategy mockEventHandlingStrategy = mock(EventHandlingStrategy.class); @@ -130,7 +130,7 @@ public void testMessageBeforeLogonWithBoundSession() throws Exception { SessionSettings settings = mock(SessionSettings.class); try (Session qfSession = SessionFactoryTestSupport.createSession()) { - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(qfSession); + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(qfSession); EventHandlingStrategy mockEventHandlingStrategy = mock(EventHandlingStrategy.class); @@ -157,7 +157,7 @@ public void testMessageBeforeLogonWithKnownButUnboundSession() throws Exception IoSession mockIoSession = mock(IoSession.class); SessionSettings settings = mock(SessionSettings.class); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); EventHandlingStrategy mockEventHandlingStrategy = mock(EventHandlingStrategy.class); @@ -195,7 +195,7 @@ public void testLogonWithoutHeartBtInt() throws Exception { "TARGET"); try (Session session = SessionFactoryTestSupport.createSession(sessionID, new UnitTestApplication(), false)) { - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); // to create a new Session + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); // to create a new Session final HashMap acceptorSessions = new HashMap<>(); acceptorSessions.put(sessionID, session); @@ -233,7 +233,7 @@ public void testRejectGarbledMessage() throws Exception { session.setRejectGarbledMessage(true); eventHandlingStrategy.blockInThread(); Responder responder = new UnitTestResponder(); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); // to create a new Session + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); // to create a new Session final HashMap acceptorSessions = new HashMap<>(); acceptorSessions.put(sessionID, session); @@ -257,7 +257,7 @@ public void testRejectGarbledMessage() throws Exception { assertEquals(2, session.getStore().getNextTargetMsgSeqNum()); assertEquals(2, session.getStore().getNextSenderMsgSeqNum()); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(session); + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(session); // garbled: character as group count String fixString = "8=FIXT.1.19=6835=B34=249=TARGET52=20180623-22:06:28.97756=SENDER148=foo33=a10=248"; @@ -336,7 +336,7 @@ public void testRejectGarbledMessageWithoutMsgTypeBeforeSessionIsCreated() throw session.setRejectGarbledMessage(true); eventHandlingStrategy.blockInThread(); Responder responder = new UnitTestResponder(); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); // to create a new Session + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); // to create a new Session final HashMap acceptorSessions = new HashMap<>(); acceptorSessions.put(sessionID, session); diff --git a/quickfixj-core/src/test/java/quickfix/mina/initiator/InitiatorIoHandlerTest.java b/quickfixj-core/src/test/java/quickfix/mina/initiator/InitiatorIoHandlerTest.java index fa13b38a8c..0f8067630e 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/initiator/InitiatorIoHandlerTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/initiator/InitiatorIoHandlerTest.java @@ -34,7 +34,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.stub; +import static org.mockito.Mockito.when; public class InitiatorIoHandlerTest { @@ -57,7 +57,7 @@ public void testRejectGarbledMessage() throws Exception { ApplVerID.FIX50SP2))) { session.setRejectGarbledMessage(true); eventHandlingStrategy.blockInThread(); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(null); // to create a new Session + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(null); // to create a new Session final InitiatorIoHandler handler = new InitiatorIoHandler(session, settings, new NetworkingOptions(new Properties()), eventHandlingStrategy); @@ -77,7 +77,7 @@ public void testRejectGarbledMessage() throws Exception { assertEquals(2, session.getStore().getNextTargetMsgSeqNum()); assertEquals(2, session.getStore().getNextSenderMsgSeqNum()); - stub(mockIoSession.getAttribute("QF_SESSION")).toReturn(session); + when(mockIoSession.getAttribute("QF_SESSION")).thenReturn(session); // garbled: character as group count String fixString = "8=FIXT.1.19=6835=B34=249=TARGET52=20180623-22:06:28.97756=SENDER148=foo33=a10=248"; From a54ac0c230052a4be2c53740532476531be2faa2 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Wed, 6 Oct 2021 00:18:40 +0200 Subject: [PATCH 3/7] Changed Mockito matchers since they no longer match `null`. --- .../mina/ssl/X509TrustManagerWrapperTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/quickfixj-core/src/test/java/quickfix/mina/ssl/X509TrustManagerWrapperTest.java b/quickfixj-core/src/test/java/quickfix/mina/ssl/X509TrustManagerWrapperTest.java index 95fa131945..b2d45214c6 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/ssl/X509TrustManagerWrapperTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/ssl/X509TrustManagerWrapperTest.java @@ -11,6 +11,9 @@ import org.junit.Test; import org.mockito.Mockito; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + public class X509TrustManagerWrapperTest { private X509TrustManagerWrapper underTest; @@ -18,14 +21,14 @@ public class X509TrustManagerWrapperTest { @Before public void setUp() throws Exception { - trustManager = Mockito.mock(X509TrustManager.class); + trustManager = mock(X509TrustManager.class); underTest = new X509TrustManagerWrapper(trustManager); } @Test public void shouldWrapX509TrustManagers() { - TrustManager[] managers = new TrustManager[] { Mockito.mock(TrustManager.class), - Mockito.mock(X509TrustManager.class) }; + TrustManager[] managers = new TrustManager[]{mock(TrustManager.class), + mock(X509TrustManager.class)}; TrustManager[] wrapped = X509TrustManagerWrapper.wrap(managers); @@ -38,8 +41,8 @@ public void shouldWrapX509TrustManagers() { @Test(expected = CertificateException.class) public void shouldRethrowCertificateExceptionOnCheckClientTrusted() throws Exception { // underlying trust manager should throw runtime exception - Mockito.doThrow(new RuntimeException()).when(trustManager) - .checkClientTrusted(Mockito.any(X509Certificate[].class), Mockito.anyString()); + doThrow(new RuntimeException()).when(trustManager) + .checkClientTrusted(Mockito.any(), Mockito.any()); underTest.checkClientTrusted(null, null); } @@ -47,8 +50,8 @@ public void shouldRethrowCertificateExceptionOnCheckClientTrusted() throws Excep @Test(expected = CertificateException.class) public void shouldRethrowCertificateExceptionOnCheckServerTrusted() throws Exception { // underlying trust manager should throw runtime exception - Mockito.doThrow(new RuntimeException()).when(trustManager) - .checkServerTrusted(Mockito.any(X509Certificate[].class), Mockito.anyString()); + doThrow(new RuntimeException()).when(trustManager) + .checkServerTrusted(Mockito.any(), Mockito.any()); underTest.checkServerTrusted(null, null); } From 5cbc44aabe4808cf4879f24780ee3f543bffb967 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Thu, 7 Oct 2021 12:43:09 +0200 Subject: [PATCH 4/7] added --add-opens to prevent test failure --- quickfixj-core/pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quickfixj-core/pom.xml b/quickfixj-core/pom.xml index 518e67f91a..410d249c73 100644 --- a/quickfixj-core/pom.xml +++ b/quickfixj-core/pom.xml @@ -383,7 +383,10 @@ org.apache.maven.plugins maven-surefire-plugin - -Xmx512m -Djava.net.preferIPv4Stack=true + + -Xmx512m -Djava.net.preferIPv4Stack=true + --add-opens java.base/java.lang=ALL-UNNAMED + false **/*Test.java From 34d771aec353eacda8e892debcb36a4dd07a607f Mon Sep 17 00:00:00 2001 From: Christoph John Date: Thu, 7 Oct 2021 23:51:15 +0200 Subject: [PATCH 5/7] Added profile for surefire on JDK8 and other JDKs --- quickfixj-core/pom.xml | 99 +++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 26 deletions(-) diff --git a/quickfixj-core/pom.xml b/quickfixj-core/pom.xml index 410d249c73..7d268e6298 100644 --- a/quickfixj-core/pom.xml +++ b/quickfixj-core/pom.xml @@ -379,32 +379,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - - - -Xmx512m -Djava.net.preferIPv4Stack=true - --add-opens java.base/java.lang=ALL-UNNAMED - - false - - **/*Test.java - ${acceptance.tests} - - - **/*ForTest.java - **/Abstract*Test.java - **/AcceptanceTestSuite$* - - - 5 - 60000 - 5 - false - - - @@ -439,5 +413,78 @@ + + + surefire-java8 + + 1.8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + -Xmx512m -Djava.net.preferIPv4Stack=true + + false + + **/*Test.java + ${acceptance.tests} + + + **/*ForTest.java + **/Abstract*Test.java + **/AcceptanceTestSuite$* + + + 5 + 60000 + 5 + false + + + + + + + + + surefire + + [1.9,) + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + -Xmx512m -Djava.net.preferIPv4Stack=true + --add-opens java.base/java.lang=ALL-UNNAMED + + false + + **/*Test.java + ${acceptance.tests} + + + **/*ForTest.java + **/Abstract*Test.java + **/AcceptanceTestSuite$* + + + 5 + 60000 + 5 + false + + + + + + From a4c8b13355703a9998f9208bc8a885765c1593e8 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Fri, 8 Oct 2021 13:27:49 +0200 Subject: [PATCH 6/7] formatting changes --- quickfixj-core/pom.xml | 86 +++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/quickfixj-core/pom.xml b/quickfixj-core/pom.xml index 7d268e6298..74effa41d9 100644 --- a/quickfixj-core/pom.xml +++ b/quickfixj-core/pom.xml @@ -413,7 +413,7 @@ - + surefire-java8 @@ -425,31 +425,31 @@ org.apache.maven.plugins maven-surefire-plugin - - -Xmx512m -Djava.net.preferIPv4Stack=true - - false - - **/*Test.java - ${acceptance.tests} - - - **/*ForTest.java - **/Abstract*Test.java - **/AcceptanceTestSuite$* - - - 5 - 60000 - 5 - false - - + + -Xmx512m -Djava.net.preferIPv4Stack=true + + false + + **/*Test.java + ${acceptance.tests} + + + **/*ForTest.java + **/Abstract*Test.java + **/AcceptanceTestSuite$* + + + 5 + 60000 + 5 + false + + - + surefire @@ -461,27 +461,27 @@ org.apache.maven.plugins maven-surefire-plugin - - -Xmx512m -Djava.net.preferIPv4Stack=true - --add-opens java.base/java.lang=ALL-UNNAMED - - false - - **/*Test.java - ${acceptance.tests} - - - **/*ForTest.java - **/Abstract*Test.java - **/AcceptanceTestSuite$* - - - 5 - 60000 - 5 - false - - + + -Xmx512m -Djava.net.preferIPv4Stack=true + --add-opens java.base/java.lang=ALL-UNNAMED + + false + + **/*Test.java + ${acceptance.tests} + + + **/*ForTest.java + **/Abstract*Test.java + **/AcceptanceTestSuite$* + + + 5 + 60000 + 5 + false + + From 58378fdd23c3334e98129eb7f0199710aa9e84d8 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Fri, 8 Oct 2021 14:21:52 +0200 Subject: [PATCH 7/7] activated JDK17 again --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7ac29c0317..681f604ee2 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-18.04, macOS-latest, windows-2016] - java: [8, 11, 15] + java: [8, 11, 17] fail-fast: false max-parallel: 4 name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}