### Question:
FetchCodeReviewsTaskListener implements BackgroundTaskListener { @Override public void onSuccess() { List<Review> unseen = reviewDAO.unseen(); if (unseen.isEmpty() && showMessages) { invoker.invokeMessageBox("No new code reviews."); return; } else if (!unseen.isEmpty() && !showMessages) { invoker.invokeCodeReviewPopupNotification(unseen); } else{ for (Review r : unseen) { r.setMarkedAsRead(true); invoker.invokeCodeReviewDialog(r); } } } FetchCodeReviewsTaskListener(FetchCodeReviewsTask task, IdeUIInvoker invoker, ReviewDAO reviewDAO,
            boolean showMessages); @Override void onBegin(); @Override void onSuccess(); @Override void onFailure(); @Override void onInterruption();  }### Answer:
@Test public void onSuccessFetchesAndShowAndMarksAsReadAllUnseenReviews() { List<Review> reviews = new ArrayList<Review>(); Review r1 = new Review(); r1.setMarkedAsRead(false); reviews.add(r1); Review r2 = new Review(); r2.setMarkedAsRead(false); reviews.add(r2); when(reviewDAO.unseen()).thenReturn(reviews); listener.onSuccess(); verify(reviewDAO, times(1)).unseen(); verify(invoker, times(2)).invokeCodeReviewDialog(any(Review.class)); verifyNoMoreInteractions(invoker); assertTrue(r1.isMarkedAsRead()); assertTrue(r2.isMarkedAsRead()); }
@Test public void onSuccessRaisesMessageIfNoUnseenMessagesAndShowMessagesIsTrue() { when(reviewDAO.unseen()).thenReturn(new ArrayList<Review>()); listener.onSuccess(); verify(invoker, times(1)).invokeMessageBox("No new code reviews."); verifyNoMoreInteractions(invoker); }
@Test public void onSuccessDoesNotRaiseMessageIfNoUnseenMessagesAndShowMessagesIsFalse() { listener = new FetchCodeReviewsTaskListener(task, invoker, reviewDAO, false); when(reviewDAO.unseen()).thenReturn(new ArrayList<Review>()); listener.onSuccess(); verifyZeroInteractions(invoker); }