3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.issue.notification;
22 import com.google.common.collect.HashMultimap;
23 import com.google.common.collect.Multimap;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.sonar.api.notifications.Notification;
27 import org.sonar.api.notifications.NotificationChannel;
28 import org.sonar.server.notification.NotificationDispatcher;
29 import org.sonar.server.notification.NotificationManager;
31 import static org.mockito.Mockito.*;
33 public class NewIssuesNotificationDispatcherTest {
35 private NotificationManager notifications = mock(NotificationManager.class);
36 private NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
37 private NotificationChannel emailChannel = mock(NotificationChannel.class);
38 private NotificationChannel twitterChannel = mock(NotificationChannel.class);
39 private NewIssuesNotificationDispatcher dispatcher = mock(NewIssuesNotificationDispatcher.class);
43 dispatcher = new NewIssuesNotificationDispatcher(notifications);
47 public void shouldNotDispatchIfNotNewViolationsNotification() {
48 Notification notification = new Notification("other-notif");
49 dispatcher.performDispatch(notification, context);
51 verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
55 public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() {
56 Multimap<String, NotificationChannel> recipients = HashMultimap.create();
57 recipients.put("user1", emailChannel);
58 recipients.put("user2", twitterChannel);
59 when(notifications.findNotificationSubscribers(dispatcher, "struts")).thenReturn(recipients);
61 Notification notification = new Notification(NewIssuesNotification.TYPE).setFieldValue("projectKey", "struts");
62 dispatcher.performDispatch(notification, context);
64 verify(context).addUser("user1", emailChannel);
65 verify(context).addUser("user2", twitterChannel);
66 verifyNoMoreInteractions(context);