aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-email-notifications-plugin/src/test
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-29 17:37:57 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-29 18:01:15 +0100
commit8d9eb9edf1ea931aabd94a4e6fe1cbe5343e93a3 (patch)
treeee90db58acf7dda6be3772d1845d954b31122dea /plugins/sonar-email-notifications-plugin/src/test
parent6d28b25606431eef5b911c4900a7ea4fd764b3df (diff)
downloadsonarqube-8d9eb9edf1ea931aabd94a4e6fe1cbe5343e93a3.tar.gz
sonarqube-8d9eb9edf1ea931aabd94a4e6fe1cbe5343e93a3.zip
SONAR-3959 Update NotifDispatchers to use new NotifManager method
Diffstat (limited to 'plugins/sonar-email-notifications-plugin/src/test')
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java51
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java49
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java62
3 files changed, 130 insertions, 32 deletions
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
index 7bf49f0c2ad..01887396b05 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
@@ -19,14 +19,20 @@
*/
package org.sonar.plugins.emailnotifications.alerts;
+import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.NotificationDispatcher;
+import org.sonar.api.notifications.NotificationManager;
import org.sonar.core.properties.PropertiesDao;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -34,28 +40,49 @@ import static org.mockito.Mockito.when;
public class AlertsOnMyFavouriteProjectTest {
+ @Mock
+ private NotificationManager notificationManager;
+
+ @Mock
+ private PropertiesDao propertiesDao;
+
+ @Mock
+ private NotificationDispatcher.Context context;
+
+ @Mock
+ private NotificationChannel emailChannel;
+
+ @Mock
+ private NotificationChannel twitterChannel;
+
+ private AlertsOnMyFavouriteProject dispatcher;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ dispatcher = new AlertsOnMyFavouriteProject(notificationManager, propertiesDao);
+ }
+
@Test
- public void shouldNotDispatchIfNotNewViolationsNotification() throws Exception {
- NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
- AlertsOnMyFavouriteProject dispatcher = new AlertsOnMyFavouriteProject(null);
+ public void shouldNotDispatchIfNotAlertsNotification() throws Exception {
Notification notification = new Notification("other-notif");
dispatcher.performDispatch(notification, context);
- verify(context, never()).addUser(any(String.class));
+ verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
}
@Test
- public void shouldDispatchToUsersWhoHaveFlaggedProjectAsFavourite() {
- NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
- PropertiesDao propertiesDao = mock(PropertiesDao.class);
- when(propertiesDao.findUserIdsForFavouriteResource(34L)).thenReturn(Lists.newArrayList("user1", "user2"));
- AlertsOnMyFavouriteProject dispatcher = new AlertsOnMyFavouriteProject(propertiesDao);
+ public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() {
+ Multimap<String, NotificationChannel> recipients = HashMultimap.create();
+ recipients.put("user1", emailChannel);
+ recipients.put("user2", twitterChannel);
+ when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, null)).thenReturn(recipients);
+ when(propertiesDao.findUserIdsForFavouriteResource(34L)).thenReturn(Lists.newArrayList("user2", "user3"));
Notification notification = new Notification("alerts").setFieldValue("projectId", "34");
dispatcher.performDispatch(notification, context);
- verify(context).addUser("user1");
- verify(context).addUser("user2");
+ verify(context).addUser("user2", twitterChannel);
verifyNoMoreInteractions(context);
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
index 4e8e66e002e..91de747a3e3 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
@@ -19,14 +19,20 @@
*/
package org.sonar.plugins.emailnotifications.newviolations;
+import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.NotificationDispatcher;
+import org.sonar.api.notifications.NotificationManager;
import org.sonar.core.properties.PropertiesDao;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -34,28 +40,49 @@ import static org.mockito.Mockito.when;
public class NewViolationsOnMyFavouriteProjectTest {
+ @Mock
+ private NotificationManager notificationManager;
+
+ @Mock
+ private PropertiesDao propertiesDao;
+
+ @Mock
+ private NotificationDispatcher.Context context;
+
+ @Mock
+ private NotificationChannel emailChannel;
+
+ @Mock
+ private NotificationChannel twitterChannel;
+
+ private NewViolationsOnMyFavouriteProject dispatcher;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ dispatcher = new NewViolationsOnMyFavouriteProject(notificationManager, propertiesDao);
+ }
+
@Test
public void shouldNotDispatchIfNotNewViolationsNotification() throws Exception {
- NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
- NewViolationsOnMyFavouriteProject dispatcher = new NewViolationsOnMyFavouriteProject(null);
Notification notification = new Notification("other-notif");
dispatcher.performDispatch(notification, context);
- verify(context, never()).addUser(any(String.class));
+ verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
}
@Test
- public void shouldDispatchToUsersWhoHaveFlaggedProjectAsFavourite() {
- NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
- PropertiesDao propertiesDao = mock(PropertiesDao.class);
- when(propertiesDao.findUserIdsForFavouriteResource(34L)).thenReturn(Lists.newArrayList("user1", "user2"));
- NewViolationsOnMyFavouriteProject dispatcher = new NewViolationsOnMyFavouriteProject(propertiesDao);
+ public void shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite() {
+ Multimap<String, NotificationChannel> recipients = HashMultimap.create();
+ recipients.put("user1", emailChannel);
+ recipients.put("user2", twitterChannel);
+ when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, null)).thenReturn(recipients);
+ when(propertiesDao.findUserIdsForFavouriteResource(34L)).thenReturn(Lists.newArrayList("user2", "user3"));
Notification notification = new Notification("new-violations").setFieldValue("projectId", "34");
dispatcher.performDispatch(notification, context);
- verify(context).addUser("user1");
- verify(context).addUser("user2");
+ verify(context).addUser("user2", twitterChannel);
verifyNoMoreInteractions(context);
}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
index b0f89604bc4..a5b68352aa2 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
@@ -19,46 +19,90 @@
*/
package org.sonar.plugins.emailnotifications.reviews;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.NotificationDispatcher;
+import org.sonar.api.notifications.NotificationManager;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
public class ChangesInReviewAssignedToMeOrCreatedByMeTest {
+ @Mock
+ private NotificationManager notificationManager;
+
+ @Mock
private NotificationDispatcher.Context context;
+
+ @Mock
+ private NotificationChannel emailChannel;
+
+ @Mock
+ private NotificationChannel twitterChannel;
+
private ChangesInReviewAssignedToMeOrCreatedByMe dispatcher;
@Before
public void setUp() {
- context = mock(NotificationDispatcher.Context.class);
- dispatcher = new ChangesInReviewAssignedToMeOrCreatedByMe();
+ MockitoAnnotations.initMocks(this);
+
+ dispatcher = new ChangesInReviewAssignedToMeOrCreatedByMe(notificationManager);
+ }
+
+ @Test
+ public void shouldNotDispatchIfNotNewViolationsNotification() throws Exception {
+ Notification notification = new Notification("other-notif");
+ dispatcher.performDispatch(notification, context);
+
+ verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
}
@Test
public void dispatchToCreatorAndAssignee() {
+ Multimap<String, NotificationChannel> recipients = HashMultimap.create();
+ recipients.put("simon", emailChannel);
+ recipients.put("freddy", twitterChannel);
+ recipients.put("godin", twitterChannel);
+ when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 42)).thenReturn(recipients);
+
Notification notification = new Notification("review-changed")
+ .setFieldValue("projectId", "42")
.setFieldValue("author", "olivier")
.setFieldValue("creator", "simon")
.setFieldValue("old.assignee", "godin")
.setFieldValue("assignee", "freddy");
dispatcher.performDispatch(notification, context);
- verify(context).addUser("simon");
- verify(context).addUser("godin");
- verify(context).addUser("freddy");
+ verify(context).addUser("simon", emailChannel);
+ verify(context).addUser("freddy", twitterChannel);
+ verify(context).addUser("godin", twitterChannel);
verifyNoMoreInteractions(context);
}
@Test
public void doNotDispatchToAuthorOfChanges() {
- dispatcher.performDispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("creator", "simon"), context);
- dispatcher.performDispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("assignee", "simon"), context);
- dispatcher.performDispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("old.assignee", "simon"), context);
+ Multimap<String, NotificationChannel> recipients = HashMultimap.create();
+ recipients.put("simon", emailChannel);
+ recipients.put("freddy", twitterChannel);
+ recipients.put("godin", twitterChannel);
+ when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 42)).thenReturn(recipients);
+
+ dispatcher.performDispatch(new Notification("review-changed").setFieldValue("projectId", "42")
+ .setFieldValue("author", "simon").setFieldValue("creator", "simon"), context);
+ dispatcher.performDispatch(new Notification("review-changed").setFieldValue("projectId", "42")
+ .setFieldValue("author", "simon").setFieldValue("assignee", "simon"), context);
+ dispatcher.performDispatch(new Notification("review-changed").setFieldValue("projectId", "42")
+ .setFieldValue("author", "simon").setFieldValue("old.assignee", "simon"), context);
verifyNoMoreInteractions(context);
}