aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-05-21 15:59:35 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-05-21 16:00:20 +0200
commit58c878b9e5c913d84d21f3b5bac8375161f50ad0 (patch)
tree11c6ee1b38859d821d49f2934e6da859dcdc6b53 /sonar-core/src
parenta56700ea6f11ba00e535dfcf723be120fdfcc94f (diff)
downloadsonarqube-58c878b9e5c913d84d21f3b5bac8375161f50ad0.tar.gz
sonarqube-58c878b9e5c913d84d21f3b5bac8375161f50ad0.zip
SONAR-2706 Add the condition HasReviewPropertyCondition
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java45
-rw-r--r--sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java62
-rw-r--r--sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java37
6 files changed, 153 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java
index beaa5f559fe..dac2503aafc 100644
--- a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java
+++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java
@@ -24,14 +24,14 @@ import org.sonar.core.review.workflow.review.WorkflowContext;
public abstract class Condition {
- private final boolean oncePerProject;
+ private final boolean oncePerGroup;
- protected Condition(boolean oncePerProject) {
- this.oncePerProject = oncePerProject;
+ protected Condition(boolean oncePerGroup) {
+ this.oncePerGroup = oncePerGroup;
}
- public final boolean isOncePerProject() {
- return oncePerProject;
+ public final boolean isOncePerGroup() {
+ return oncePerGroup;
}
public abstract boolean doVerify(Review review, WorkflowContext context);
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java
new file mode 100644
index 00000000000..903db40658d
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java
@@ -0,0 +1,45 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.review.workflow.condition;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import org.sonar.core.review.workflow.review.Review;
+import org.sonar.core.review.workflow.review.WorkflowContext;
+
+public class HasReviewPropertyCondition extends Condition {
+
+ private final String propertyKey;
+
+ protected HasReviewPropertyCondition(String propertyKey) {
+ super(false);
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey));
+ this.propertyKey = propertyKey;
+ }
+
+ protected final String getPropertyKey() {
+ return propertyKey;
+ }
+
+ @Override
+ public boolean doVerify(Review review, WorkflowContext context) {
+ return !Strings.isNullOrEmpty(review.getProperties().get(propertyKey));
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java
index 524674007e7..614155b78d5 100644
--- a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java
+++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java
@@ -27,7 +27,7 @@ public final class NotCondition extends Condition {
private Condition condition;
public NotCondition(Condition c) {
- super(c.isOncePerProject());
+ super(c.isOncePerGroup());
this.condition = c;
}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java
index 505dd533fee..91822ec9fb9 100644
--- a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java
@@ -27,14 +27,14 @@ import static org.fest.assertions.Assertions.assertThat;
public class ConditionTest {
@Test
- public void checkedOncePerProject() {
+ public void checkedOncePerGroupOfReviews() {
Condition condition = new Condition(true) {
@Override
public boolean doVerify(Review review, WorkflowContext context) {
return false;
}
};
- assertThat(condition.isOncePerProject()).isTrue();
+ assertThat(condition.isOncePerGroup()).isTrue();
}
@Test
@@ -45,7 +45,7 @@ public class ConditionTest {
return false;
}
};
- assertThat(condition.isOncePerProject()).isFalse();
+ assertThat(condition.isOncePerGroup()).isFalse();
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java
new file mode 100644
index 00000000000..ebc0fb7d042
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java
@@ -0,0 +1,62 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.review.workflow.condition;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.core.review.workflow.review.DefaultReview;
+import org.sonar.core.review.workflow.review.DefaultWorkflowContext;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class HasReviewPropertyConditionTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void doVerify() {
+ HasReviewPropertyCondition condition = new HasReviewPropertyCondition("foo");
+
+ DefaultWorkflowContext context = new DefaultWorkflowContext();
+ assertThat(condition.doVerify(new DefaultReview(), context)).isFalse();
+ assertThat(condition.doVerify(new DefaultReview().setProperty("foo", ""), context)).isFalse();
+ assertThat(condition.doVerify(new DefaultReview().setProperty("foo", "bar"), context)).isTrue();
+ }
+
+ @Test
+ public void getPropertyKey() {
+ HasReviewPropertyCondition condition = new HasReviewPropertyCondition("foo");
+ assertThat(condition.getPropertyKey()).isEqualTo("foo");
+ }
+
+ @Test
+ public void failIfNullProperty() {
+ thrown.expect(IllegalArgumentException.class);
+ new HasReviewPropertyCondition(null);
+ }
+
+ @Test
+ public void failIfEmptyProperty() {
+ thrown.expect(IllegalArgumentException.class);
+ new HasReviewPropertyCondition("");
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java
new file mode 100644
index 00000000000..db448b37d7a
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.review.workflow.screen;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class CommentScreenTest {
+ @Test
+ public void testCommentScreen() {
+ CommentScreen screen = new CommentScreen();
+
+ assertThat(screen.getKey()).isEqualTo("comment");
+
+ assertThat(screen.getCommandKey()).isNull();
+ assertThat(screen.setCommandKey("create-jira-issue"));
+ assertThat(screen.getCommandKey()).isEqualTo("create-jira-issue");
+ }
+}