]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2607 Should be only one dispatcher - ChangesInReviewAssignedToMeOrCreatedByMe
authorEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 27 Jul 2011 13:42:09 +0000 (17:42 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 27 Jul 2011 14:45:30 +0000 (18:45 +0400)
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMe.java [deleted file]
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMe.java [new file with mode: 0644]
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMe.java [deleted file]
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java [new file with mode: 0644]
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeTest.java [deleted file]
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewCreatedByMeTest.java [deleted file]
plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties

index c5cc4ccc7de4c54297642a058e7ad62b6aa844f4..a63cbaa7caf04f07616a6bbf26afa3ec215406c7 100644 (file)
  */
 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/ChangesInReviewAssignedToMe.java
deleted file mode 100644 (file)
index c5859ee..0000000
+++ /dev/null
@@ -1,48 +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 assigned to me".
- * 
- * @since 2.10
- */
-public class ChangesInReviewAssignedToMe 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 oldAssignee = notification.getFieldValue("old.assignee"); // previous assignee
-      String assignee = notification.getFieldValue("assignee"); // current assignee
-      if (!StringUtils.equals(author, oldAssignee)) {
-        context.addUser(oldAssignee);
-      }
-      if (!StringUtils.equals(author, assignee)) {
-        context.addUser(assignee);
-      }
-    }
-  }
-
-}
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
new file mode 100644 (file)
index 0000000..0b0387c
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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 assigned to me or created by me".
+ * 
+ * @since 2.10
+ */
+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 (creator != null && !StringUtils.equals(author, creator)) {
+        context.addUser(creator);
+      }
+      if (oldAssignee != null && !StringUtils.equals(author, oldAssignee)) {
+        context.addUser(oldAssignee);
+      }
+      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 (file)
index 85f1046..0000000
+++ /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/ChangesInReviewAssignedToMeOrCreatedByMeTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeOrCreatedByMeTest.java
new file mode 100644 (file)
index 0000000..b4c63dc
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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 ChangesInReviewAssignedToMeOrCreatedByMeTest {
+
+  private NotificationDispatcher.Context context;
+  private ChangesInReviewAssignedToMeOrCreatedByMe dispatcher;
+
+  @Before
+  public void setUp() {
+    context = mock(NotificationDispatcher.Context.class);
+    dispatcher = new ChangesInReviewAssignedToMeOrCreatedByMe();
+  }
+
+  @Test
+  public void dispatchToCreatorAndAssignee() {
+    Notification notification = new Notification("review-changed")
+        .setFieldValue("author", "olivier")
+        .setFieldValue("creator", "simon")
+        .setFieldValue("old.assignee", "godin")
+        .setFieldValue("assignee", "freddy");
+    dispatcher.dispatch(notification, context);
+
+    verify(context).addUser("simon");
+    verify(context).addUser("godin");
+    verify(context).addUser("freddy");
+    verifyNoMoreInteractions(context);
+  }
+
+  @Test
+  public void doNotDispatchToAuthorOfChanges() {
+    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);
+
+    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/ChangesInReviewAssignedToMeTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ChangesInReviewAssignedToMeTest.java
deleted file mode 100644 (file)
index e9b169c..0000000
+++ /dev/null
@@ -1,78 +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 ChangesInReviewAssignedToMeTest {
-
-  private NotificationDispatcher.Context context;
-  private ChangesInReviewAssignedToMe dispatcher;
-
-  @Before
-  public void setUp() {
-    context = mock(NotificationDispatcher.Context.class);
-    dispatcher = new ChangesInReviewAssignedToMe();
-  }
-
-  @Test
-  public void dispatchToOldAndNewAssignee() {
-    Notification notification = new Notification("review-assignee-changed")
-        .setFieldValue("author", "freddy")
-        .setFieldValue("old.assignee", "godin")
-        .setFieldValue("assignee", "simon");
-
-    dispatcher.dispatch(notification, context);
-
-    verify(context).addUser("godin");
-    verify(context).addUser("simon");
-    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(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 (file)
index 3f3142c..0000000
+++ /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);
-  }
-
-}
index a266ae44fdbd051e9090b16fa796d83c2f2924a5..b7b6cdb319e254e6af76f5d0e2a35320a28283b1 100644 (file)
@@ -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
 
 
 #------------------------------------------------------------------------------