private void assertNotFound(
     JEReplicaDB replicaDB, final CSN startCSN, final PositionStrategy positionStrategy)
     throws ChangelogException {
   DBCursor<UpdateMsg> cursor =
       replicaDB.generateCursorFrom(startCSN, GREATER_THAN_OR_EQUAL_TO_KEY, positionStrategy);
   try {
     final SoftAssertions softly = new SoftAssertions();
     softly.assertThat(cursor.next()).isFalse();
     softly.assertThat(cursor.getRecord()).isNull();
     softly.assertAll();
   } finally {
     close(cursor);
   }
 }
  /**
   * Test the cursor with all acceptable strategies combination. Creation of a replication server is
   * costly so it is created only once on first test and cleaned after the last test using the stop
   * line in data to do so.
   */
  @Test(dataProvider = "cursorData")
  public void testGenerateCursor(
      CSN[] csns,
      CSN startCsn,
      KeyMatchingStrategy matchingStrategy,
      PositionStrategy positionStrategy,
      int startIndex,
      int endIndex)
      throws Exception {
    DBCursor<UpdateMsg> cursor = null;
    try {
      if (replicationServer == null) {
        // initialize only once
        TestCaseUtils.startServer();
        replicationServer = configureReplicationServer(100000, 10);
        replicaDB = newReplicaDB(replicationServer);
        for (CSN csn : csns) {
          replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csn, "uid"));
        }
      }
      if (csns == null) {
        return; // stop line, time to clean replication artefacts
      }

      cursor = replicaDB.generateCursorFrom(startCsn, matchingStrategy, positionStrategy);
      if (startIndex != -1) {
        assertThatCursorCanBeFullyReadFromStart(cursor, csns, startIndex, endIndex);
      } else {
        assertThatCursorIsExhausted(cursor);
      }
    } finally {
      close(cursor);
      if (csns == null) {
        // stop line, stop and remove replication
        shutdown(replicaDB);
        remove(replicationServer);
      }
    }
  }
  private void assertFoundInOrder(
      JEReplicaDB replicaDB, final PositionStrategy positionStrategy, CSN... csns)
      throws ChangelogException {
    DBCursor<UpdateMsg> cursor =
        replicaDB.generateCursorFrom(csns[0], GREATER_THAN_OR_EQUAL_TO_KEY, positionStrategy);
    try {
      assertNull(cursor.getRecord(), "Cursor should point to a null record initially");

      for (int i = positionStrategy == ON_MATCHING_KEY ? 0 : 1; i < csns.length; i++) {
        final String msg = "i=" + i + ", csns[i]=" + csns[i].toStringUI();
        final SoftAssertions softly = new SoftAssertions();
        softly.assertThat(cursor.next()).as(msg).isTrue();
        softly.assertThat(cursor.getRecord().getCSN()).as(msg).isEqualTo(csns[i]);
        softly.assertAll();
      }
      final SoftAssertions softly = new SoftAssertions();
      softly.assertThat(cursor.next()).isFalse();
      softly.assertThat(cursor.getRecord()).isNull();
      softly.assertAll();
    } finally {
      close(cursor);
    }
  }