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 MyNewIssuesNotificationDispatcherTest {
35 private MyNewIssuesNotificationDispatcher underTest;
37 private NotificationManager notificationManager = mock(NotificationManager.class);
38 private NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
39 private NotificationChannel emailChannel = mock(NotificationChannel.class);
40 private NotificationChannel twitterChannel = mock(NotificationChannel.class);
45 underTest = new MyNewIssuesNotificationDispatcher(notificationManager);
49 public void do_not_dispatch_if_no_new_notification() {
50 Notification notification = new Notification("other-notif");
51 underTest.performDispatch(notification, context);
53 verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
57 public void dispatch_to_users_who_have_subscribed_to_notification_and_project() {
58 Multimap<String, NotificationChannel> recipients = HashMultimap.create();
59 recipients.put("user1", emailChannel);
60 recipients.put("user2", twitterChannel);
61 when(notificationManager.findNotificationSubscribers(underTest, "struts")).thenReturn(recipients);
63 Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE)
64 .setFieldValue("projectKey", "struts")
65 .setFieldValue("assignee", "user1");
66 underTest.performDispatch(notification, context);
68 verify(context).addUser("user1", emailChannel);
69 verifyNoMoreInteractions(context);