aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-08-10 13:45:26 +0200
committerSonarTech <sonartech@sonarsource.com>2018-08-21 20:21:04 +0200
commit03d23244002a8ff71de2e9bfc8cd7b039899599a (patch)
treeaf1f8957e1918d5251a421a11219f19b8d98d926 /server/sonar-server-common
parent2fdab0c755a5f4cf22a3cd15843703d5947c9b15 (diff)
downloadsonarqube-03d23244002a8ff71de2e9bfc8cd7b039899599a.tar.gz
sonarqube-03d23244002a8ff71de2e9bfc8cd7b039899599a.zip
SONAR-8368 fix misleading Function.Context#setCloseDate(boolean)
by replacing it by two methods: setCloseDate() and unsetCloseDate()
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/Function.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/SetCloseDate.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/UnsetCloseDate.java29
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/UnsetCloseDateTest.java37
6 files changed, 85 insertions, 15 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/Function.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/Function.java
index 77d24bc593e..0a161a335f5 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/Function.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/Function.java
@@ -32,7 +32,9 @@ interface Function {
Context setResolution(@Nullable String s);
- Context setCloseDate(boolean b);
+ Context setCloseDate();
+
+ Context unsetCloseDate();
Context setLine(@Nullable Integer line);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java
index d92fa575d80..8d3f65e7c7f 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java
@@ -77,8 +77,14 @@ public class FunctionExecutor {
}
@Override
- public Function.Context setCloseDate(boolean b) {
- updater.setCloseDate(issue, b ? changeContext.date() : null, changeContext);
+ public Function.Context setCloseDate() {
+ updater.setCloseDate(issue, changeContext.date(), changeContext);
+ return this;
+ }
+
+ @Override
+ public Function.Context unsetCloseDate() {
+ updater.setCloseDate(issue, null, changeContext);
return this;
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java
index d2a3bf1c671..a56d991b9fc 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java
@@ -216,25 +216,25 @@ public class IssueWorkflow implements Startable {
.transition(Transition.builder(AUTOMATIC_CLOSE_TRANSITION)
.from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED)
.conditions(IsBeingClosed.INSTANCE)
- .functions(SetClosed.INSTANCE, new SetCloseDate(true))
+ .functions(SetClosed.INSTANCE, SetCloseDate.INSTANCE)
.automatic()
.build())
.transition(Transition.builder(AUTOMATIC_CLOSE_TRANSITION)
.from(Issue.STATUS_REOPENED).to(Issue.STATUS_CLOSED)
.conditions(IsBeingClosed.INSTANCE)
- .functions(SetClosed.INSTANCE, new SetCloseDate(true))
+ .functions(SetClosed.INSTANCE, SetCloseDate.INSTANCE)
.automatic()
.build())
.transition(Transition.builder(AUTOMATIC_CLOSE_TRANSITION)
.from(Issue.STATUS_CONFIRMED).to(Issue.STATUS_CLOSED)
.conditions(IsBeingClosed.INSTANCE)
- .functions(SetClosed.INSTANCE, new SetCloseDate(true))
+ .functions(SetClosed.INSTANCE, SetCloseDate.INSTANCE)
.automatic()
.build())
.transition(Transition.builder(AUTOMATIC_CLOSE_TRANSITION)
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_CLOSED)
.conditions(IsBeingClosed.INSTANCE)
- .functions(SetClosed.INSTANCE, new SetCloseDate(true))
+ .functions(SetClosed.INSTANCE, SetCloseDate.INSTANCE)
.automatic()
.build())
@@ -242,7 +242,7 @@ public class IssueWorkflow implements Startable {
.transition(Transition.builder("automaticreopen")
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED)
.conditions(new NotCondition(IsBeingClosed.INSTANCE), new HasResolution(Issue.RESOLUTION_FIXED), IsNotHotspotNorManualVulnerability.INSTANCE)
- .functions(new SetResolution(null), new SetCloseDate(false))
+ .functions(new SetResolution(null), UnsetCloseDate.INSTANCE)
.automatic()
.build());
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/SetCloseDate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/SetCloseDate.java
index 25610f66fa0..331ef847ce1 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/SetCloseDate.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/SetCloseDate.java
@@ -19,15 +19,11 @@
*/
package org.sonar.server.issue.workflow;
-class SetCloseDate implements Function {
- private final boolean set;
-
- public SetCloseDate(boolean set) {
- this.set = set;
- }
+enum SetCloseDate implements Function {
+ INSTANCE;
@Override
public void execute(Context context) {
- context.setCloseDate(set);
+ context.setCloseDate();
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/UnsetCloseDate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/UnsetCloseDate.java
new file mode 100644
index 00000000000..e9a17a9b6c0
--- /dev/null
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/UnsetCloseDate.java
@@ -0,0 +1,29 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.issue.workflow;
+
+enum UnsetCloseDate implements Function {
+ INSTANCE;
+
+ @Override
+ public void execute(Context context) {
+ context.unsetCloseDate();
+ }
+}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/UnsetCloseDateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/UnsetCloseDateTest.java
new file mode 100644
index 00000000000..01cb4d9fdcc
--- /dev/null
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/UnsetCloseDateTest.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.issue.workflow;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class UnsetCloseDateTest {
+ @Test
+ public void should_unset_close_date() {
+ UnsetCloseDate function = UnsetCloseDate.INSTANCE;
+ Function.Context context = mock(Function.Context.class);
+ function.execute(context);
+ verify(context, times(1)).unsetCloseDate();
+ }
+
+}