]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2706 Add the condition HasReviewPropertyCondition
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 21 May 2012 13:59:35 +0000 (15:59 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 21 May 2012 14:00:20 +0000 (16:00 +0200)
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/Condition.java
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/NotCondition.java
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/ConditionTest.java
sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasReviewPropertyConditionTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/review/workflow/screen/CommentScreenTest.java [new file with mode: 0644]

index beaa5f559fe3de38741c1ee68e93b8b062648427..dac2503aafcc6a33e10737954083f852efc6585e 100644 (file)
@@ -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 (file)
index 0000000..903db40
--- /dev/null
@@ -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));
+  }
+}
index 524674007e74e8e5d123a680b0ef7b8972511e23..614155b78d5ee6c5c7e0458b7810f7671ecf42cf 100644 (file)
@@ -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;
   }
 
index 505dd533feeb20d06085dc1264b6e6036cc3d3a7..91822ec9fb927d0448b914412979400e5e89220b 100644 (file)
@@ -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 (file)
index 0000000..ebc0fb7
--- /dev/null
@@ -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 (file)
index 0000000..db448b3
--- /dev/null
@@ -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");
+  }
+}