public void addMessageListener(ReleaseMessageListener listener) {
    if (!listeners.contains(listener)) {
      listeners.add(listener);
    }
  }
@Test
  public void testScanMessageWithGapAndNotifyMessageListener() throws Exception {
    String someMessage = "someMessage";
    long someId = 1;
    ReleaseMessage someReleaseMessage = assembleReleaseMessage(someId, someMessage);

    String someMissingMessage = "someMissingMessage";
    long someMissingId = 2;
    ReleaseMessage someMissingReleaseMessage = assembleReleaseMessage(someMissingId, someMissingMessage);

    String anotherMessage = "anotherMessage";
    long anotherId = 3;
    ReleaseMessage anotherReleaseMessage = assembleReleaseMessage(anotherId, anotherMessage);

    String anotherMissingMessage = "anotherMissingMessage";
    long anotherMissingId = 4;
    ReleaseMessage anotherMissingReleaseMessage = assembleReleaseMessage(anotherMissingId, anotherMissingMessage);

    long someRolledBackId = 5;

    String yetAnotherMessage = "yetAnotherMessage";
    long yetAnotherId = 6;
    ReleaseMessage yetAnotherReleaseMessage = assembleReleaseMessage(yetAnotherId, yetAnotherMessage);

    ArrayList<ReleaseMessage> receivedMessage = Lists.newArrayList();
    SettableFuture<ReleaseMessage> someListenerFuture = SettableFuture.create();
    ReleaseMessageListener someListener = (message, channel) -> receivedMessage.add(message);
    releaseMessageScanner.addMessageListener(someListener);

    when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0L)).thenReturn(
        Lists.newArrayList(someReleaseMessage));

    await().untilAsserted(() -> {
      assertEquals(1, receivedMessage.size());
      assertSame(someReleaseMessage, receivedMessage.get(0));
    });

    when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(someId)).thenReturn(
        Lists.newArrayList(anotherReleaseMessage));

    await().untilAsserted(() -> {
      assertEquals(2, receivedMessage.size());
      assertSame(someReleaseMessage, receivedMessage.get(0));
      assertSame(anotherReleaseMessage, receivedMessage.get(1));
    });

    when(releaseMessageRepository.findAllById(Sets.newHashSet(someMissingId)))
        .thenReturn(Lists.newArrayList(someMissingReleaseMessage));

    await().untilAsserted(() -> {
      assertEquals(3, receivedMessage.size());
      assertSame(someReleaseMessage, receivedMessage.get(0));
      assertSame(anotherReleaseMessage, receivedMessage.get(1));
      assertSame(someMissingReleaseMessage, receivedMessage.get(2));
    });

    when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(anotherId)).thenReturn(
        Lists.newArrayList(yetAnotherReleaseMessage));

    await().untilAsserted(() -> {
      assertEquals(4, receivedMessage.size());
      assertSame(someReleaseMessage, receivedMessage.get(0));
      assertSame(anotherReleaseMessage, receivedMessage.get(1));
      assertSame(someMissingReleaseMessage, receivedMessage.get(2));
      assertSame(yetAnotherReleaseMessage, receivedMessage.get(3));
    });

    when(releaseMessageRepository.findAllById(Sets.newHashSet(anotherMissingId, someRolledBackId)))
        .thenReturn(Lists.newArrayList(anotherMissingReleaseMessage));

    await().untilAsserted(() -> {
      assertEquals(5, receivedMessage.size());
      assertSame(someReleaseMessage, receivedMessage.get(0));
      assertSame(anotherReleaseMessage, receivedMessage.get(1));
      assertSame(someMissingReleaseMessage, receivedMessage.get(2));
      assertSame(yetAnotherReleaseMessage, receivedMessage.get(3));
      assertSame(anotherMissingReleaseMessage, receivedMessage.get(4));
    });
  }