Skip to content

Add unit tests for SequenceReset message handling in Session class#1133

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/add-unit-tests-sequencereset
Draft

Add unit tests for SequenceReset message handling in Session class#1133
Copilot wants to merge 3 commits intomasterfrom
copilot/add-unit-tests-sequencereset

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

SequenceReset message handling in the Session class lacked comprehensive unit test coverage, particularly for GapFill functionality and error conditions.

Changes

  • New test class: SessionSequenceResetTest.java with three test scenarios:

    • GapFill sequence recovery: Validates ResendRequest generation on sequence gaps and proper sequence number updates when receiving SequenceReset-GapFill messages
    • Hard reset: Verifies sequence number reset when GapFillFlag is absent
    • Invalid NewSeqNo rejection: Confirms Reject message generation when NewSeqNo is lower than expected
  • Test implementation: Uses Mockito for dependency mocking (MessageStore, Application, Responder), establishes proper logged-on sessions before testing sequence scenarios, and validates message store interactions

Example test flow:

// Establish session with seqnum 1-2, then receive message 50 (gap detected)
NewOrderSingle nos = createMessage(50);
session.next(nos);

// Verify ResendRequest sent for messages 3-49
assertTrue(sentMessages.stream().anyMatch(m -> m.contains("35=2")));

// Send SequenceReset-GapFill from 3 to 50
SequenceReset sr = createSequenceReset(3, 50, true);
session.next(sr);

// Verify sequence updated and queued message processed
verify(messageStore).setNextTargetMsgSeqNum(50);

Tests follow existing QuickFIX/J patterns using SessionFactoryTestSupport.Builder for session creation and FIX 4.4 message format.

Original prompt

Problem Statement

Add comprehensive unit tests for SequenceReset message handling in the Session class to ensure proper behavior when receiving SequenceReset messages with and without GapFill flags.

Background

The Session class in QuickFIX/J handles SequenceReset messages which are critical for maintaining sequence number synchronization between FIX counterparties. Currently, there is insufficient test coverage for these scenarios, particularly for the GapFill functionality.

Requirements

Create a new test class SessionSequenceResetTest.java in the test directory that covers the following scenarios:

Test 1: SequenceReset with GapFill

This test should verify the complete flow when a session receives messages out of sequence and uses SequenceReset with GapFill to skip a range of messages:

  1. Receive a Logon message with sequence number 100 (when expecting 1)
  2. Verify that a ResendRequest is sent asking for messages 1-99 (or 1-infinity depending on configuration)
  3. Simulate receiving resent messages from sequence number 1 to 50 with PossDupFlag set
  4. Receive a SequenceReset message with:
    • MsgSeqNum = 51
    • GapFillFlag = true
    • NewSeqNo = 110
  5. Verify that the session updates the next expected target sequence number to 110
  6. Verify that subsequent messages with sequence number 110+ are accepted normally
  7. Verify no Reject messages are generated

Test 2: SequenceReset without GapFill (Hard Reset)

Test that a SequenceReset without GapFill flag properly resets the sequence number:

  1. Establish a logged-on session
  2. Send a SequenceReset message without GapFillFlag (or with it set to false)
  3. Verify the sequence number is reset to the NewSeqNo value

Test 3: Invalid SequenceReset

Test that invalid SequenceReset messages are properly rejected:

  1. Establish a logged-on session
  2. Send a SequenceReset with NewSeqNo LOWER than the current expected sequence number
  3. Verify that a Reject message is generated

Test Implementation Details

The test should:

  • Use Mockito for mocking dependencies (Application, MessageStore, Responder, etc.)
  • Use FIX 4.4 messages for testing
  • Properly mock the MessageStore sequence number methods
  • Capture and verify sent messages
  • Verify interactions with the MessageStore (setNextTargetMsgSeqNum calls)
  • Follow existing QuickFIX/J test patterns and conventions

File Location

Create the test file at:

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

Dependencies

The test should use existing test dependencies:

  • JUnit 4
  • Mockito
  • QuickFIX/J test utilities

Expected Outcome

After implementing these tests:

  1. The SequenceReset handling logic in Session.java will have improved test coverage
  2. Future changes to SequenceReset handling can be verified against these tests
  3. Edge cases and error conditions are documented through tests
  4. Developers can reference these tests to understand proper SequenceReset behavior

Test Code

package quickfix;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import quickfix.field.*;
import quickfix.fix44.Logon;
import quickfix.fix44.NewOrderSingle;
import quickfix.fix44.SequenceReset;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class SessionSequenceResetTest {

    private Session session;
    private Application application;
    private MessageStoreFactory messageStoreFactory;
    private MessageStore messageStore;
    private Responder responder;
    private SessionID sessionID;
    private DataDictionaryProvider dataDictionaryProvider;
    private List<String> sentMessages;

    @Before
    public void setUp() throws Exception {
        // Initialize session ID
        sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER", "TARGET");

        // Mock application
        application = mock(Application.class);

        // Mock message store
        messageStore = mock(MessageStore.class);
        when(messageStore.getNextSenderMsgSeqNum()).thenReturn(1);
        when(messageStore.getNextTargetMsgSeqNum()).thenReturn(1);
        when(messageStore.getCreationTime()).thenReturn(new java.util.Date());

        messageStoreFactory = mock(MessageStoreFactory.class);
        when(messageStoreFactory.create(any(SessionID.class))).thenReturn(messageStore);

        // Mock data dictionary provider
        dataDictionaryProvider = mock(DataDictionaryProvider.class);
        DataDictionary dataDictionary = new DataDictionary("FIX44.xml");
        when(dataDictionaryProvider.getSessionDataDictionary(anyString())).thenReturn(dataDictionary);
        when(dataDictionaryProvider.getApplicationDataDictionary(any(ApplVerID.class))).thenReturn(dataDictionary);

        // Mock responder
        responder = mock(Responder.class);
        sentMessages = new ArrayList<>();
        doAnswer(invocation -> {
      ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI and others added 2 commits February 6, 2026 17:50
Co-authored-by: chrjohn <6644028+chrjohn@users.noreply.github.com>
Co-authored-by: chrjohn <6644028+chrjohn@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for SequenceReset message handling in Session class Add unit tests for SequenceReset message handling in Session class Feb 6, 2026
Copilot AI requested a review from chrjohn February 6, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants