summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-email-notifications-plugin
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-31 16:30:54 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-31 16:32:17 +0100
commit98459327e1257c7d2b6e1a4abe531d9d2e45f853 (patch)
tree83cec404400faefdaa34b395c0ebb271f90f05a7 /plugins/sonar-email-notifications-plugin
parentaa7e8691a6e192a091e256f5f16007e3d04162b0 (diff)
downloadsonarqube-98459327e1257c7d2b6e1a4abe531d9d2e45f853.tar.gz
sonarqube-98459327e1257c7d2b6e1a4abe531d9d2e45f853.zip
SONAR-3959 Refactor existing notification-related code
Diffstat (limited to 'plugins/sonar-email-notifications-plugin')
-rw-r--r--plugins/sonar-email-notifications-plugin/pom.xml5
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java32
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java62
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java62
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java72
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/alerts/AlertsEmailTemplate.java (renamed from plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsEmailTemplate.java)2
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/reviews/ReviewEmailTemplate.java (renamed from plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java)2
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java (renamed from plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java)2
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java2
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java89
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java89
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java118
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/alerts/AlertsEmailTemplateTest.java (renamed from plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsEmailTemplateTest.java)4
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/reviews/ReviewEmailTemplateTest.java (renamed from plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java)4
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java (renamed from plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java)4
15 files changed, 21 insertions, 528 deletions
diff --git a/plugins/sonar-email-notifications-plugin/pom.xml b/plugins/sonar-email-notifications-plugin/pom.xml
index bf10af333c1..72d10f4b76c 100644
--- a/plugins/sonar-email-notifications-plugin/pom.xml
+++ b/plugins/sonar-email-notifications-plugin/pom.xml
@@ -23,11 +23,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.2</version>
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
index d62857fbca8..e226088092e 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
@@ -19,15 +19,14 @@
*/
package org.sonar.plugins.emailnotifications;
+import org.sonar.plugins.emailnotifications.templates.reviews.ReviewEmailTemplate;
+
+import org.sonar.plugins.emailnotifications.templates.violations.NewViolationsEmailTemplate;
+
+import org.sonar.plugins.emailnotifications.templates.alerts.AlertsEmailTemplate;
+
import com.google.common.collect.ImmutableList;
import org.sonar.api.SonarPlugin;
-import org.sonar.api.notifications.NotificationDispatcherMetadata;
-import org.sonar.plugins.emailnotifications.alerts.AlertsEmailTemplate;
-import org.sonar.plugins.emailnotifications.alerts.AlertsOnMyFavouriteProject;
-import org.sonar.plugins.emailnotifications.newviolations.NewViolationsEmailTemplate;
-import org.sonar.plugins.emailnotifications.newviolations.NewViolationsOnMyFavouriteProject;
-import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewAssignedToMeOrCreatedByMe;
-import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
import java.util.List;
@@ -36,24 +35,9 @@ public class EmailNotificationsPlugin extends SonarPlugin {
return ImmutableList.of(
EmailNotificationChannel.class,
- // Notify incoming violations on my favourite projects
- NewViolationsOnMyFavouriteProject.class,
- NotificationDispatcherMetadata.create("NewViolationsOnMyFavouriteProject")
- .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, "true"),
+ // Email templates
NewViolationsEmailTemplate.class,
-
- // Notify reviews changes
- ChangesInReviewAssignedToMeOrCreatedByMe.class,
- NotificationDispatcherMetadata.create("ChangesInReviewAssignedToMeOrCreatedByMe")
- .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, "true"),
ReviewEmailTemplate.class,
-
- // Notify alerts on my favourite projects
- AlertsOnMyFavouriteProject.class,
- NotificationDispatcherMetadata.create("AlertsOnMyFavouriteProject")
- .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, "true"),
- AlertsEmailTemplate.class
-
- );
+ AlertsEmailTemplate.class);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java
deleted file mode 100644
index 49c7da72e02..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProject.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.emailnotifications.alerts;
-
-import com.google.common.collect.Multimap;
-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 java.util.Collection;
-import java.util.List;
-
-/**
- * This dispatcher means: "notify me when alerts are raised on projects that I flagged as favourite".
- *
- * @since 3.5
- */
-public class AlertsOnMyFavouriteProject extends NotificationDispatcher {
-
- private NotificationManager notificationManager;
- private PropertiesDao propertiesDao;
-
- public AlertsOnMyFavouriteProject(NotificationManager notificationManager, PropertiesDao propertiesDao) {
- super("alerts");
- this.notificationManager = notificationManager;
- this.propertiesDao = propertiesDao;
- }
-
- @Override
- public void dispatch(Notification notification, Context context) {
- // "null" is passed as a 2nd argument because this dispatcher is not a per-project dispatcher
- Multimap<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null);
-
- List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(Long.parseLong(notification.getFieldValue("projectId")));
- for (String userLogin : userLogins) {
- Collection<NotificationChannel> channels = subscribedRecipients.get(userLogin);
- for (NotificationChannel channel : channels) {
- context.addUser(userLogin, channel);
- }
- }
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java
deleted file mode 100644
index 1125bb02dee..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProject.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.emailnotifications.newviolations;
-
-import com.google.common.collect.Multimap;
-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 java.util.Collection;
-import java.util.List;
-
-/**
- * This dispatcher means: "notify me when new violations are introduced on projects that I flagged as favourite".
- *
- * @since 2.14
- */
-public class NewViolationsOnMyFavouriteProject extends NotificationDispatcher {
-
- private NotificationManager notificationManager;
- private PropertiesDao propertiesDao;
-
- public NewViolationsOnMyFavouriteProject(NotificationManager notificationManager, PropertiesDao propertiesDao) {
- super("new-violations");
- this.notificationManager = notificationManager;
- this.propertiesDao = propertiesDao;
- }
-
- @Override
- public void dispatch(Notification notification, Context context) {
- // "null" is passed as a 2nd argument because this dispatcher is not a per-project dispatcher
- Multimap<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null);
-
- List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource(Long.parseLong(notification.getFieldValue("projectId")));
- for (String userLogin : userLogins) {
- Collection<NotificationChannel> channels = subscribedRecipients.get(userLogin);
- for (NotificationChannel channel : channels) {
- context.addUser(userLogin, channel);
- }
- }
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
deleted file mode 100644
index 31b1952b1b3..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.emailnotifications.reviews;
-
-import com.google.common.collect.Multimap;
-import org.apache.commons.lang.StringUtils;
-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 java.util.Collection;
-
-/**
- * This dispatcher means: "notify me when someone changes review assigned to me or created by me".
- *
- * @since 2.10
- */
-public class ChangesInReviewAssignedToMeOrCreatedByMe extends NotificationDispatcher {
-
- private NotificationManager notificationManager;
-
- public ChangesInReviewAssignedToMeOrCreatedByMe(NotificationManager notificationManager) {
- super("review-changed");
- this.notificationManager = notificationManager;
- }
-
- @Override
- public void dispatch(Notification notification, Context context) {
- int projectId = Integer.parseInt(notification.getFieldValue("projectId"));
- Multimap<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, projectId);
-
- String author = notification.getFieldValue("author");
- String creator = notification.getFieldValue("creator");
- String oldAssignee = notification.getFieldValue("old.assignee");
- String assignee = notification.getFieldValue("assignee");
- if (creator != null && !StringUtils.equals(author, creator)) {
- addUserToContextIfSubscribed(context, creator, subscribedRecipients);
- }
- if (oldAssignee != null && !StringUtils.equals(author, oldAssignee)) {
- addUserToContextIfSubscribed(context, oldAssignee, subscribedRecipients);
- }
- if (assignee != null && !StringUtils.equals(author, assignee)) {
- addUserToContextIfSubscribed(context, assignee, subscribedRecipients);
- }
- }
-
- private void addUserToContextIfSubscribed(Context context, String user, Multimap<String, NotificationChannel> subscribedRecipients) {
- Collection<NotificationChannel> channels = subscribedRecipients.get(user);
- for (NotificationChannel channel : channels) {
- context.addUser(user, channel);
- }
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/alerts/AlertsEmailTemplate.java
index 96d96cb3ad7..0a015ae56d2 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/alerts/AlertsEmailTemplate.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/alerts/AlertsEmailTemplate.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.emailnotifications.alerts;
+package org.sonar.plugins.emailnotifications.templates.alerts;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.EmailSettings;
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/reviews/ReviewEmailTemplate.java
index 57da295f6eb..2a2e4df3bc1 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/reviews/ReviewEmailTemplate.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.emailnotifications.reviews;
+package org.sonar.plugins.emailnotifications.templates.reviews;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.EmailSettings;
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java
index 2294b368e34..4e9552d9d5c 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplate.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.emailnotifications.newviolations;
+package org.sonar.plugins.emailnotifications.templates.violations;
import org.sonar.api.notifications.Notification;
import org.sonar.api.config.EmailSettings;
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
index 55096f5565b..b2763851df3 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
@@ -26,6 +26,6 @@ import static org.fest.assertions.Assertions.assertThat;
public class EmailNotificationsPluginTest {
@Test
public void should_get_extensions() {
- assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(10);
+ assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(4);
}
}
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
deleted file mode 100644
index 01887396b05..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsOnMyFavouriteProjectTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-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.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-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 shouldNotDispatchIfNotAlertsNotification() 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 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("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
deleted file mode 100644
index 91de747a3e3..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsOnMyFavouriteProjectTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-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.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-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 {
- Notification notification = new Notification("other-notif");
- dispatcher.performDispatch(notification, context);
-
- verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
- }
-
- @Test
- 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("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
deleted file mode 100644
index a5b68352aa2..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-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.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() {
- 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", emailChannel);
- verify(context).addUser("freddy", twitterChannel);
- verify(context).addUser("godin", twitterChannel);
- verifyNoMoreInteractions(context);
- }
-
- @Test
- public void doNotDispatchToAuthorOfChanges() {
- 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);
- }
-
- @Test
- public void shouldNotDispatch() {
- Notification notification = new Notification("other");
- dispatcher.performDispatch(notification, context);
-
- verifyNoMoreInteractions(context);
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/alerts/AlertsEmailTemplateTest.java
index 1a68497f1c9..5f7cc46d9ca 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/alerts/AlertsEmailTemplateTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/alerts/AlertsEmailTemplateTest.java
@@ -17,7 +17,9 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.emailnotifications.alerts;
+package org.sonar.plugins.emailnotifications.templates.alerts;
+
+import org.sonar.plugins.emailnotifications.templates.alerts.AlertsEmailTemplate;
import org.junit.Before;
import org.junit.Test;
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/reviews/ReviewEmailTemplateTest.java
index 3e52167e9d1..7ea299fded1 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/reviews/ReviewEmailTemplateTest.java
@@ -17,7 +17,9 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.emailnotifications.reviews;
+package org.sonar.plugins.emailnotifications.templates.reviews;
+
+import org.sonar.plugins.emailnotifications.templates.reviews.ReviewEmailTemplate;
import org.junit.Before;
import org.junit.Test;
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java
index 3bd32290422..27dbe38667c 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/templates/violations/NewViolationsEmailTemplateTest.java
@@ -17,7 +17,9 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.emailnotifications.newviolations;
+package org.sonar.plugins.emailnotifications.templates.violations;
+
+import org.sonar.plugins.emailnotifications.templates.violations.NewViolationsEmailTemplate;
import org.junit.Before;
import org.junit.Test;