### Question:
ClientSessionHandler extends AbstractSessionHandler { @Override protected void decode(ChannelHandlerContext ctx, FixMessage msg, List<Object> out) throws Exception { final FixMessageHeader header = msg.getHeader(); FixSession session = getSession(ctx); if (MessageTypes.LOGON.equals(header.getMessageType())) { if (session != null) { int incomingMsgSeqNum = header.getMsgSeqNum(); if (!session.checkAndIncrementIncomingSeqNum(incomingMsgSeqNum)) { int expectedMsgSeqNum = session.getNextIncomingMessageSeqNum(); if (incomingMsgSeqNum > expectedMsgSeqNum) { FixMessageBuilder resendRequest = new FixMessageBuilderImpl(MessageTypes.RESEND_REQUEST); resendRequest.add(FieldType.BeginSeqNo, expectedMsgSeqNum); resendRequest.add(FieldType.EndSeqNo, incomingMsgSeqNum - 1); prepareMessageToSend(ctx, session, resendRequest); ctx.writeAndFlush(resendRequest); } else { getLogger().warn("Message Sequence Too Low"); ctx.channel().close(); return; } } getLogger().info("Fix Session Established."); LogonEvent logonEvent = new LogonEvent(session); out.add(logonEvent); return; } else { throw new IllegalStateException("Duplicate Logon Request. Session Already Established."); } } super.decode(ctx, msg, out); } protected  ClientSessionHandler(FixSessionSettingsProvider settingsProvider,
                                   AuthenticationProvider authenticationProvider,
                                   MessageSequenceProvider messageSequenceProvider,
                                   FixApplication fixApplication); @Override void channelActive(ChannelHandlerContext ctx);  }### Answer:
@Test public void testSequenceTooHigh() throws Exception { FixMessage logonResponseMsg = new FixMessageBuilderImpl(MessageTypes.LOGON); FixMessageHeader header = logonResponseMsg.getHeader(); header.setMsgSeqNum(3); header.setSenderCompID(randomAscii(3)); header.setTargetCompID(randomAscii(4)); logonResponseMsg.getHeader().setMsgSeqNum(3); FixSession fixSession = FixSession.newBuilder() .senderCompID(header.getSenderCompID()) .targetCompID(header.getTargetCompID()) .build(); fixSession.setNextIncomingMessageSeqNum(1); sessionAttribute.set(fixSession); final List<Object> outgoingMessages = new ArrayList<>(); handler.decode(ctx, logonResponseMsg, outgoingMessages); assertEquals(1, outgoingMessages.size()); assertTrue(outgoingMessages.get(0) instanceof LogonEvent); verify(ctx).writeAndFlush(messageCaptor.capture()); final FixMessageBuilderImpl sentMessage = messageCaptor.getValue(); FixMessageAsserts.assertResendRequest(sentMessage, 1, 2); }
@Test public void testSequenceTooLow() throws Exception { FixMessage logonResponseMsg = new FixMessageBuilderImpl(MessageTypes.LOGON); FixMessageHeader header = logonResponseMsg.getHeader(); header.setMsgSeqNum(3); header.setSenderCompID(randomAscii(3)); header.setTargetCompID(randomAscii(4)); logonResponseMsg.getHeader().setMsgSeqNum(3); FixSession fixSession = FixSession.newBuilder() .senderCompID(header.getSenderCompID()) .targetCompID(header.getTargetCompID()) .build(); fixSession.setNextIncomingMessageSeqNum(4); sessionAttribute.set(fixSession); final List<Object> outgoingMessages = new ArrayList<>(); handler.decode(ctx, logonResponseMsg, outgoingMessages); assertEquals(0, outgoingMessages.size()); verify(channel).close(); }