@Test
public void testRemoveQueuedMessagesOnSequenceReset() throws Exception {


    final UnitTestApplication application = new UnitTestApplication();
    try (Session session = setUpSession(application, false,
            new UnitTestResponder())) {
        final SessionState state = getSessionState(session);
        
        final int from = 10;
        int numberOfMsgs = 200;
        int to = from + numberOfMsgs;
        
        logonTo(session, 1);
        assertEquals(2, state.getNextTargetMsgSeqNum());
        for (int i = from; i < to; i++) {
            processMessage(session, createAppMessage(i));
        }
        for (int i = from; i < to; i++) {
            assertTrue(state.getQueuedSeqNums().contains(i));
        }

        assertEquals(state.getQueuedSeqNums().size(), numberOfMsgs);
        assertTrue(application.fromAppMessages.isEmpty());
        // Create a sequence reset which will cause deletion of almost all
        // messages
        // from the sessionState queue since former messages are skipped.
        // The remaining two messages will then be dequeued and processed by the
        // app.
        final int two = 2;
        processMessage(session, createSequenceReset(2, to - two, true));
        assertEquals(application.fromAppMessages.size(), two);
        assertFalse(state.isResendRequested());
        assertTrue(session.isLoggedOn());
        assertTrue(state.getQueuedSeqNums().isEmpty());
    }
}