@Before public void setUp() { emailChannel = mock(NotificationChannel.class); when(emailChannel.getKey()).thenReturn("email"); gtalkChannel = mock(NotificationChannel.class); when(gtalkChannel.getKey()).thenReturn("gtalk"); NotificationDispatcher commentOnReviewAssignedToMe = mock(NotificationDispatcher.class); when(commentOnReviewAssignedToMe.getKey()).thenReturn("comment on review assigned to me"); doAnswer( new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws Throwable { ((NotificationDispatcher.Context) invocation.getArguments()[1]).addUser(assignee); return null; } }) .when(commentOnReviewAssignedToMe) .dispatch(any(Notification.class), any(NotificationDispatcher.Context.class)); NotificationDispatcher commentOnReviewCreatedByMe = mock(NotificationDispatcher.class); when(commentOnReviewCreatedByMe.getKey()).thenReturn("comment on review created by me"); doAnswer( new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws Throwable { ((NotificationDispatcher.Context) invocation.getArguments()[1]).addUser(creator); return null; } }) .when(commentOnReviewCreatedByMe) .dispatch(any(Notification.class), any(NotificationDispatcher.Context.class)); NotificationDispatcher[] dispatchers = new NotificationDispatcher[] {commentOnReviewAssignedToMe, commentOnReviewCreatedByMe}; NotificationChannel[] channels = new NotificationChannel[] {emailChannel, gtalkChannel}; manager = mock(DefaultNotificationManager.class); Settings settings = new Settings(new PropertyDefinitions(NotificationService.class)); settings.setProperty("sonar.notifications.delay", 1L); // delay 1 second service = spy(new NotificationService(settings, manager, dispatchers, channels)); doReturn(false) .when(manager) .isEnabled(any(String.class), any(String.class), any(String.class)); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); when(dispatcher.getKey()).thenReturn("NewViolations"); when(emailChannel.getKey()).thenReturn("Email"); when(twitterChannel.getKey()).thenReturn("Twitter"); manager = new DefaultNotificationManager( new NotificationChannel[] {emailChannel, twitterChannel}, notificationQueueDao, propertiesDao); }