aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-06-03 16:32:53 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-06-03 16:32:53 +0200
commitf39271bce5a3a175885d98ba3630932471b580c4 (patch)
tree7eb859ffe6f3050e3e557b1a84aa2b4c051ced7e /sonar-plugin-api/src
parentdb1c1223dfcb54f3771c4918f4363006488312c3 (diff)
downloadsonarqube-f39271bce5a3a175885d98ba3630932471b580c4.tar.gz
sonarqube-f39271bce5a3a175885d98ba3630932471b580c4.zip
SONAR-3755 Remove Action builder and replace it by Actions
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java60
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java45
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/action/ActionTest.java36
3 files changed, 82 insertions, 59 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
index 6da2f1ecbc4..a797d20106c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Action.java
@@ -21,34 +21,46 @@ package org.sonar.api.issue.action;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import org.sonar.api.ServerExtension;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.condition.Condition;
-import java.util.Arrays;
import java.util.List;
-public class Action implements ServerExtension {
+import static com.google.common.collect.Lists.newArrayList;
+
+public class Action {
private final String key;
private final List<Condition> conditions;
private final List<Function> functions;
- private Action(ActionBuilder builder) {
- key = builder.key;
- conditions = builder.conditions;
- functions = builder.functions;
+ public Action(String key) {
+ this.key = key;
+ this.conditions = newArrayList();
+ this.functions = newArrayList();
+
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Action key must be set");
}
public String key() {
return key;
}
+ public Action setConditions(Condition... conditions) {
+ this.conditions.addAll(ImmutableList.copyOf(conditions));
+ return this;
+ }
+
public List<Condition> conditions() {
return conditions;
}
+ public Action setFunctions(Function... functions) {
+ this.functions.addAll(ImmutableList.copyOf(functions));
+ return this;
+ }
+
public List<Function> functions() {
return functions;
}
@@ -87,36 +99,4 @@ public class Action implements ServerExtension {
return key;
}
- public static Action create(String key) {
- return builder(key).build();
- }
-
- public static ActionBuilder builder(String key) {
- return new ActionBuilder(key);
- }
-
- public static class ActionBuilder {
- private final String key;
- private List<Condition> conditions = Lists.newArrayList();
- private List<Function> functions = Lists.newArrayList();
-
- private ActionBuilder(String key) {
- this.key = key;
- }
-
- public ActionBuilder conditions(Condition... c) {
- this.conditions.addAll(Arrays.asList(c));
- return this;
- }
-
- public ActionBuilder functions(Function... f) {
- this.functions.addAll(Arrays.asList(f));
- return this;
- }
-
- public Action build() {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Action key must be set");
- return new Action(this);
- }
- }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java
new file mode 100644
index 00000000000..ae6ccb0e2cb
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/action/Actions.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.api.issue.action;
+
+import org.sonar.api.ServerExtension;
+
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class Actions implements ServerExtension {
+
+ private final List<Action> actions;
+
+ public Actions() {
+ actions = newArrayList();
+ }
+
+ public Action add(String actionKey) {
+ Action action = new Action(actionKey);
+ this.actions.add(action);
+ return action;
+ }
+
+ public List<Action> list() {
+ return actions;
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/action/ActionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/action/ActionTest.java
index d961d134e21..d5a01d3ce6d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/action/ActionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/action/ActionTest.java
@@ -37,21 +37,20 @@ public class ActionTest {
Function function2 = mock(Function.class);
@Test
- public void test_builder() throws Exception {
- Action transition = Action.builder("link-to-jira")
- .conditions(condition1, condition2)
- .functions(function1, function2)
- .build();
- assertThat(transition.key()).isEqualTo("link-to-jira");
- assertThat(transition.conditions()).containsOnly(condition1, condition2);
- assertThat(transition.functions()).containsOnly(function1, function2);
+ public void test_action() throws Exception {
+ Action action = new Action("link-to-jira")
+ .setConditions(condition1, condition2)
+ .setFunctions(function1, function2);
+
+ assertThat(action.key()).isEqualTo("link-to-jira");
+ assertThat(action.conditions()).containsOnly(condition1, condition2);
+ assertThat(action.functions()).containsOnly(function1, function2);
}
-
@Test
public void key_should_be_set() throws Exception {
try {
- Action.builder("").build();
+ new Action("");
fail();
} catch (Exception e) {
assertThat(e).hasMessage("Action key must be set");
@@ -61,24 +60,23 @@ public class ActionTest {
@Test
public void should_verify_conditions() throws Exception {
DefaultIssue issue = new DefaultIssue();
- Action transition = Action.builder("link-to-jira")
- .conditions(condition1, condition2)
- .build();
+ Action action = new Action("link-to-jira")
+ .setConditions(condition1, condition2);
when(condition1.matches(issue)).thenReturn(true);
when(condition2.matches(issue)).thenReturn(false);
- assertThat(transition.supports(issue)).isFalse();
+ assertThat(action.supports(issue)).isFalse();
when(condition1.matches(issue)).thenReturn(true);
when(condition2.matches(issue)).thenReturn(true);
- assertThat(transition.supports(issue)).isTrue();
+ assertThat(action.supports(issue)).isTrue();
}
@Test
public void test_equals_and_hashCode() throws Exception {
- Action t1 = Action.create("link-to-jira");
- Action t2 = Action.create("link-to-jira");
- Action t3 = Action.create("comment");
+ Action t1 = new Action("link-to-jira");
+ Action t2 = new Action("link-to-jira");
+ Action t3 = new Action("comment");
assertThat(t1).isEqualTo(t1);
assertThat(t1).isEqualTo(t2);
@@ -89,7 +87,7 @@ public class ActionTest {
@Test
public void test_toString() throws Exception {
- Action t1 = Action.create("link-to-jira");
+ Action t1 = new Action("link-to-jira");
assertThat(t1.toString()).isEqualTo("link-to-jira");
}