@Test
  public void shouldReturnFalseWhenThereIsAStartEntryButNoCommitEntries() throws IOException {
    // given
    when(entryReader.readLogEntry(channel)).thenReturn(A_START_ENTRY, NULL_ENTRY);

    // when
    final boolean result = cursor.next();

    // then
    assertFalse(result);
    assertNull(cursor.get());
  }
  @Override
  public boolean next() throws IOException {
    LogEntry entry = entryReader.readLogEntry(channel);
    if (entry == null) {
      return false;
    }

    assert entry instanceof LogEntryStart : "Expected Start entry, read " + entry + " instead";
    LogEntryStart startEntry = (LogEntryStart) entry;
    LogEntryCommit commitEntry;

    List<Command> entries = commandList();
    while (true) {
      entry = entryReader.readLogEntry(channel);
      if (entry == null) {
        return false;
      }
      if (entry instanceof LogEntryCommit) {
        commitEntry = entry.as();
        break;
      }

      entries.add(entry.<LogEntryCommand>as().getXaCommand());
    }

    PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(entries);
    transaction.setHeader(
        startEntry.getAdditionalHeader(),
        startEntry.getMasterId(),
        startEntry.getLocalId(),
        startEntry.getTimeWritten(),
        startEntry.getLastCommittedTxWhenTransactionStarted(),
        commitEntry.getTimeWritten(),
        -1);
    current = new CommittedTransactionRepresentation(startEntry, transaction, commitEntry);
    return true;
  }
  @Test
  public void shouldCallTheVisitorWithTheFoundTransaction() throws IOException {
    // given
    when(entryReader.readLogEntry(channel))
        .thenReturn(A_START_ENTRY, A_COMMAND_ENTRY, A_COMMIT_ENTRY);

    // when
    cursor.next();

    // then
    PhysicalTransactionRepresentation txRepresentation =
        new PhysicalTransactionRepresentation(Arrays.asList(A_COMMAND_ENTRY.getXaCommand()));
    assertEquals(
        new CommittedTransactionRepresentation(A_START_ENTRY, txRepresentation, A_COMMIT_ENTRY),
        cursor.get());
  }