From 35ecb682573667ce59f9cbeb8b7562f565fc09f7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 6 Mar 2015 09:47:38 +0100 Subject: [PATCH] SONAR-4624 complete "new FP issues" with resolution "won't fix" -> dispatcher becomes "Issues resolved as false positive or won't fix" --- ...va => DoNotFixNotificationDispatcher.java} | 10 ++- .../server/platform/ServerComponents.java | 6 +- ...> DoNotFixNotificationDispatcherTest.java} | 71 ++++++++++--------- .../resources/org/sonar/l10n/core.properties | 2 +- 4 files changed, 45 insertions(+), 44 deletions(-) rename server/sonar-server/src/main/java/org/sonar/server/issue/notification/{NewFalsePositiveNotificationDispatcher.java => DoNotFixNotificationDispatcher.java} (89%) rename server/sonar-server/src/test/java/org/sonar/server/issue/notification/{NewFalsePositiveNotificationDispatcherTest.java => DoNotFixNotificationDispatcherTest.java} (54%) diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java similarity index 89% rename from server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java rename to server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java index be916cfdd42..16b3de6fc05 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java @@ -29,17 +29,15 @@ import java.util.Collection; import java.util.Map; /** - * This dispatcher means: "notify me when someone resolves an issue as false positive". - * - * @since 3.6 + * This dispatcher means: "notify me when an issue is resolved as false positive or won't fix". */ -public class NewFalsePositiveNotificationDispatcher extends NotificationDispatcher { +public class DoNotFixNotificationDispatcher extends NotificationDispatcher { public static final String KEY = "NewFalsePositiveIssue"; private final NotificationManager notifications; - public NewFalsePositiveNotificationDispatcher(NotificationManager notifications) { + public DoNotFixNotificationDispatcher(NotificationManager notifications) { super(IssueChangeNotification.TYPE); this.notifications = notifications; } @@ -58,7 +56,7 @@ public class NewFalsePositiveNotificationDispatcher extends NotificationDispatch @Override public void dispatch(Notification notification, Context context) { String newResolution = notification.getFieldValue("new.resolution"); - if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE)) { + if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equal(newResolution, Issue.RESOLUTION_WONT_FIX)) { String author = notification.getFieldValue("changeAuthor"); String projectKey = notification.getFieldValue("projectKey"); Multimap subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index 1c03d4fb89c..3144159e1ad 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -165,7 +165,7 @@ import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher; import org.sonar.server.issue.notification.IssueChangesEmailTemplate; -import org.sonar.server.issue.notification.NewFalsePositiveNotificationDispatcher; +import org.sonar.server.issue.notification.DoNotFixNotificationDispatcher; import org.sonar.server.issue.notification.NewIssuesEmailTemplate; import org.sonar.server.issue.notification.NewIssuesNotificationDispatcher; import org.sonar.server.issue.ws.ComponentTagsAction; @@ -690,8 +690,8 @@ class ServerComponents { pico.addSingleton(ChangesOnMyIssueNotificationDispatcher.newMetadata()); pico.addSingleton(NewIssuesNotificationDispatcher.class); pico.addSingleton(NewIssuesNotificationDispatcher.newMetadata()); - pico.addSingleton(NewFalsePositiveNotificationDispatcher.class); - pico.addSingleton(NewFalsePositiveNotificationDispatcher.newMetadata()); + pico.addSingleton(DoNotFixNotificationDispatcher.class); + pico.addSingleton(DoNotFixNotificationDispatcher.newMetadata()); // issue filters pico.addSingleton(IssueFilterService.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java similarity index 54% rename from server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java rename to server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java index ac434d62372..0bc96d60002 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java @@ -21,44 +21,29 @@ package org.sonar.server.issue.notification; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.notifications.*; +import org.sonar.api.issue.Issue; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.api.notifications.NotificationDispatcher; +import org.sonar.api.notifications.NotificationDispatcherMetadata; +import org.sonar.api.notifications.NotificationManager; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) -public class NewFalsePositiveNotificationDispatcherTest { - @Mock - NotificationManager notifications; - - @Mock - NotificationDispatcher.Context context; - - @Mock - NotificationChannel emailChannel; - - @Mock - NotificationChannel twitterChannel; - - NewFalsePositiveNotificationDispatcher dispatcher; - - @Before - public void setUp() { - dispatcher = new NewFalsePositiveNotificationDispatcher(notifications); - } +public class DoNotFixNotificationDispatcherTest { + NotificationManager notifications = mock(NotificationManager.class); + NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class); + NotificationChannel emailChannel = mock(NotificationChannel.class); + NotificationChannel twitterChannel = mock(NotificationChannel.class); + DoNotFixNotificationDispatcher sut = new DoNotFixNotificationDispatcher(notifications);; @Test public void test_metadata() throws Exception { - NotificationDispatcherMetadata metadata = NewFalsePositiveNotificationDispatcher.newMetadata(); - assertThat(metadata.getDispatcherKey()).isEqualTo(dispatcher.getKey()); + NotificationDispatcherMetadata metadata = DoNotFixNotificationDispatcher.newMetadata(); + assertThat(metadata.getDispatcherKey()).isEqualTo(sut.getKey()); assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true"); assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true"); } @@ -66,7 +51,7 @@ public class NewFalsePositiveNotificationDispatcherTest { @Test public void should_not_dispatch_if_other_notification_type() throws Exception { Notification notification = new Notification("other"); - dispatcher.performDispatch(notification, context); + sut.performDispatch(notification, context); verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); } @@ -77,13 +62,13 @@ public class NewFalsePositiveNotificationDispatcherTest { recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); - when(notifications.findNotificationSubscribers(dispatcher, "struts")).thenReturn(recipients); + when(notifications.findNotificationSubscribers(sut, "struts")).thenReturn(recipients); - Notification notification = new IssueChangeNotification().setFieldValue("projectKey", "struts") + Notification fpNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "godin") - .setFieldValue("new.resolution", "FALSE-POSITIVE") + .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE) .setFieldValue("assignee", "freddy"); - dispatcher.performDispatch(notification, context); + sut.performDispatch(fpNotif, context); verify(context).addUser("simon", emailChannel); verify(context).addUser("freddy", twitterChannel); @@ -92,4 +77,22 @@ public class NewFalsePositiveNotificationDispatcherTest { verifyNoMoreInteractions(context); } + /** + * Only false positive and won't fix resolutions + */ + @Test + public void ignore_other_resolutions() { + Multimap recipients = HashMultimap.create(); + recipients.put("simon", emailChannel); + recipients.put("freddy", twitterChannel); + when(notifications.findNotificationSubscribers(sut, "struts")).thenReturn(recipients); + + Notification fixedNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts") + .setFieldValue("changeAuthor", "godin") + .setFieldValue("new.resolution", Issue.RESOLUTION_FIXED) + .setFieldValue("assignee", "freddy"); + sut.performDispatch(fixedNotif, context); + + verifyZeroInteractions(context); + } } diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index f7c7f68f0e3..3736c11e312 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2030,7 +2030,7 @@ notification.dispatcher.information=Subscribe to following channels to be notifi notification.dispatcher.ChangesOnMyIssue=Changes in issues assigned to me or reported by me notification.dispatcher.NewIssues=New issues notification.dispatcher.NewAlerts=New quality gate status -notification.dispatcher.NewFalsePositiveIssue=New false positives +notification.dispatcher.NewFalsePositiveIssue=Issues resolved as false positive or won't fix #------------------------------------------------------------------------------ -- 2.39.5