summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-email-notifications-plugin
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-07-27 17:42:09 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-07-27 18:45:30 +0400
commit98f23e758f5e923262f629e6f8881f56c0cd4604 (patch)
tree34fa48221691bf4e3071a6d58e0fdd6b2b476b4e /plugins/sonar-email-notifications-plugin
parentde3bf1c8c62b41a175eaf828def73e26c878d4c1 (diff)
downloadsonarqube-98f23e758f5e923262f629e6f8881f56c0cd4604.tar.gz
sonarqube-98f23e758f5e923262f629e6f8881f56c0cd4604.zip
SONAR-2607 Should be only one dispatcher - ChangesInReviewAssignedToMeOrCreatedByMe
Diffstat (limited to 'plugins/sonar-email-notifications-plugin')
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java12
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java (renamed from plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMe.java)12
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMe.java44
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java (renamed from plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeTest.java)30
-rw-r--r--plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMeTest.java74
5 files changed, 26 insertions, 146 deletions
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 c5cc4ccc7de..a63cbaa7caf 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,14 +19,13 @@
*/
package org.sonar.plugins.emailnotifications;
-import org.sonar.api.SonarPlugin;
-import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewAssignedToMe;
-import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewCreatedByMe;
-import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
-
import java.util.Arrays;
import java.util.List;
+import org.sonar.api.SonarPlugin;
+import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewAssignedToMeOrCreatedByMe;
+import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
+
public class EmailNotificationsPlugin extends SonarPlugin {
public List getExtensions() {
@@ -35,8 +34,7 @@ public class EmailNotificationsPlugin extends SonarPlugin {
EmailNotificationChannel.class,
ReviewEmailTemplate.class,
- ChangesInReviewAssignedToMe.class,
- ChangesInReviewCreatedByMe.class);
+ ChangesInReviewAssignedToMeOrCreatedByMe.class);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMe.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
index c5859ee13da..0b0387cb028 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMe.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java
@@ -24,22 +24,26 @@ import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationDispatcher;
/**
- * This dispatcher means: "notify me when when someone changes review assigned to me".
+ * This dispatcher means: "notify me when when someone changes review assigned to me or created by me".
*
* @since 2.10
*/
-public class ChangesInReviewAssignedToMe extends NotificationDispatcher {
+public class ChangesInReviewAssignedToMeOrCreatedByMe extends NotificationDispatcher {
@Override
public void dispatch(Notification notification, Context context) {
if (StringUtils.startsWith(notification.getType(), "review")) {
String author = notification.getFieldValue("author"); // author of change
+ String creator = notification.getFieldValue("creator"); // creator of review
String oldAssignee = notification.getFieldValue("old.assignee"); // previous assignee
String assignee = notification.getFieldValue("assignee"); // current assignee
- if (!StringUtils.equals(author, oldAssignee)) {
+ if (creator != null && !StringUtils.equals(author, creator)) {
+ context.addUser(creator);
+ }
+ if (oldAssignee != null && !StringUtils.equals(author, oldAssignee)) {
context.addUser(oldAssignee);
}
- if (!StringUtils.equals(author, assignee)) {
+ if (assignee != null && !StringUtils.equals(author, assignee)) {
context.addUser(assignee);
}
}
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMe.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMe.java
deleted file mode 100644
index 85f104637d0..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMe.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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 org.apache.commons.lang.StringUtils;
-import org.sonar.api.notifications.Notification;
-import org.sonar.api.notifications.NotificationDispatcher;
-
-/**
- * This dispatcher means: "notify me when when someone changes review created by me".
- *
- * @since 2.10
- */
-public class ChangesInReviewCreatedByMe extends NotificationDispatcher {
-
- @Override
- public void dispatch(Notification notification, Context context) {
- if (StringUtils.startsWith(notification.getType(), "review")) {
- String author = notification.getFieldValue("author"); // author of change
- String creator = notification.getFieldValue("creator"); // creator of review
- if (!StringUtils.equals(author, creator)) {
- context.addUser(creator);
- }
- }
- }
-
-}
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
index e9b169c6363..b4c63dc8aa2 100644
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeTest.java
+++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
@@ -28,48 +28,44 @@ import org.junit.Test;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationDispatcher;
-public class ChangesInReviewAssignedToMeTest {
+public class ChangesInReviewAssignedToMeOrCreatedByMeTest {
private NotificationDispatcher.Context context;
- private ChangesInReviewAssignedToMe dispatcher;
+ private ChangesInReviewAssignedToMeOrCreatedByMe dispatcher;
@Before
public void setUp() {
context = mock(NotificationDispatcher.Context.class);
- dispatcher = new ChangesInReviewAssignedToMe();
+ dispatcher = new ChangesInReviewAssignedToMeOrCreatedByMe();
}
@Test
- public void dispatchToOldAndNewAssignee() {
- Notification notification = new Notification("review-assignee-changed")
- .setFieldValue("author", "freddy")
+ public void dispatchToCreatorAndAssignee() {
+ Notification notification = new Notification("review-changed")
+ .setFieldValue("author", "olivier")
+ .setFieldValue("creator", "simon")
.setFieldValue("old.assignee", "godin")
- .setFieldValue("assignee", "simon");
-
+ .setFieldValue("assignee", "freddy");
dispatcher.dispatch(notification, context);
- verify(context).addUser("godin");
verify(context).addUser("simon");
+ verify(context).addUser("godin");
+ verify(context).addUser("freddy");
verifyNoMoreInteractions(context);
}
@Test
public void doNotDispatchToAuthorOfChanges() {
- Notification notification = new Notification("review-assignee-changed")
- .setFieldValue("author", "simon")
- .setFieldValue("old.assignee", "simon")
- .setFieldValue("assignee", "godin");
+ dispatcher.dispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("creator", "simon"), context);
+ dispatcher.dispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("assignee", "simon"), context);
+ dispatcher.dispatch(new Notification("review-changed").setFieldValue("author", "simon").setFieldValue("old.assignee", "simon"), context);
- dispatcher.dispatch(notification, context);
-
- verify(context).addUser("godin");
verifyNoMoreInteractions(context);
}
@Test
public void shouldNotDispatch() {
Notification notification = new Notification("other");
-
dispatcher.dispatch(notification, context);
verifyNoMoreInteractions(context);
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMeTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMeTest.java
deleted file mode 100644
index 3f3142ccced..00000000000
--- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMeTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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 static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.notifications.Notification;
-import org.sonar.api.notifications.NotificationDispatcher;
-
-public class ChangesInReviewCreatedByMeTest {
-
- private NotificationDispatcher.Context context;
- private ChangesInReviewCreatedByMe dispatcher;
-
- @Before
- public void setUp() {
- context = mock(NotificationDispatcher.Context.class);
- dispatcher = new ChangesInReviewCreatedByMe();
- }
-
- @Test
- public void dispatchToCreator() {
- Notification notification = new Notification("review-comment-added")
- .setFieldValue("author", "godin")
- .setFieldValue("creator", "simon");
-
- dispatcher.dispatch(notification, context);
-
- verify(context).addUser("simon");
- verifyNoMoreInteractions(context);
- }
-
- @Test
- public void doNotDispatchToAuthorOfChanges() {
- Notification notification = new Notification("review-comment-added")
- .setFieldValue("author", "simon")
- .setFieldValue("creator", "simon");
-
- dispatcher.dispatch(notification, context);
-
- verifyNoMoreInteractions(context);
- }
-
- @Test
- public void shouldNotDispatch() {
- Notification notification = new Notification("other");
-
- dispatcher.dispatch(notification, context);
-
- verifyNoMoreInteractions(context);
- }
-
-}