From 98f23e758f5e923262f629e6f8881f56c0cd4604 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Wed, 27 Jul 2011 17:42:09 +0400 Subject: [PATCH] SONAR-2607 Should be only one dispatcher - ChangesInReviewAssignedToMeOrCreatedByMe --- .../EmailNotificationsPlugin.java | 12 ++- ...gesInReviewAssignedToMeOrCreatedByMe.java} | 12 ++- .../reviews/ChangesInReviewCreatedByMe.java | 44 ----------- ...nReviewAssignedToMeOrCreatedByMeTest.java} | 30 ++++---- .../ChangesInReviewCreatedByMeTest.java | 74 ------------------- .../resources/org/sonar/i18n/core.properties | 3 +- 6 files changed, 27 insertions(+), 148 deletions(-) rename plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/{ChangesInReviewAssignedToMe.java => ChangesInReviewAssignedToMeOrCreatedByMe.java} (77%) delete mode 100644 plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMe.java rename plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/{ChangesInReviewAssignedToMeTest.java => ChangesInReviewAssignedToMeOrCreatedByMeTest.java} (67%) delete mode 100644 plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMeTest.java 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 similarity index 77% rename from plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMe.java rename to 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 similarity index 67% rename from plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeTest.java rename to 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); - } - -} diff --git a/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties index a266ae44fdb..b7b6cdb319e 100644 --- a/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties +++ b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties @@ -682,8 +682,7 @@ email_configuration.test.send=Send test email email_configuration.test.email_was_sent_to_x=Email was sent to {0} notification.channel.EmailNotificationChannel=Email -notification.dispatcher.ChangesInReviewAssignedToMe=Changes in review assigned to me -notification.dispatcher.ChangesInReviewCreatedByMe=Changes in review created by me +notification.dispatcher.ChangesInReviewAssignedToMeOrCreatedByMe=Changes in review assigned to me or created by me #------------------------------------------------------------------------------ -- 2.39.5