@Test
  public void shouldPeriodicallyProcessQueue() throws Exception {
    NotificationQueueElement queueElement = mock(NotificationQueueElement.class);
    Notification notification = mock(Notification.class);
    when(queueElement.getNotification()).thenReturn(notification);
    when(manager.getFromQueue())
        .thenReturn(queueElement)
        .thenReturn(null)
        .thenReturn(queueElement)
        .thenReturn(null)
        .thenReturn(queueElement)
        .thenReturn(null);
    doNothing().when(service).deliver(any(Notification.class));

    service.start();
    Thread.sleep(1500); // sleep 1.5 second to process queue
    service.stop();

    verify(service, times(3))
        .deliver(notification); // 3 times - 1 on start, 1 after delay, 1 on stop
  }
  /**
   * Given: Nobody wants to receive notifications.
   *
   * <p>When: Freddy adds comment to review created by Evgeny and assigned to Simon.
   *
   * <p>Then: No notifications.
   */
  @Test
  public void scenario4() {
    Notification notification = mock(Notification.class);
    creator = USER_EVGENY;
    assignee = USER_SIMON;

    service.deliver(notification);

    verify(emailChannel, atLeast(1)).getKey();
    verify(gtalkChannel, atLeast(1)).getKey();
    verifyNoMoreInteractions(emailChannel);
    verifyNoMoreInteractions(gtalkChannel);
  }
  /**
   * Given: Simon wants to receive notifications by email on comments for reviews assigned to him or
   * created by him.
   *
   * <p>When: Freddy adds comment to review created by Simon and assigned to Simon.
   *
   * <p>Then: Only one notification should be delivered to Simon by Email.
   */
  @Test
  public void scenario1() {
    doReturn(true).when(manager).isEnabled(USER_SIMON, "email", "comment on review assigned to me");
    doReturn(true).when(manager).isEnabled(USER_SIMON, "email", "comment on review created by me");

    Notification notification = mock(Notification.class);
    creator = USER_SIMON;
    assignee = USER_SIMON;

    service.deliver(notification);

    verify(emailChannel, atLeast(1)).getKey();
    verify(gtalkChannel, atLeast(1)).getKey();
    verify(emailChannel).deliver(notification, USER_SIMON);
    verifyNoMoreInteractions(emailChannel);
    verifyNoMoreInteractions(gtalkChannel);
  }