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);
--- /dev/null
+/*
+ * 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));
+ }
+}
private Condition condition;
public NotCondition(Condition c) {
- super(c.isOncePerProject());
+ super(c.isOncePerGroup());
this.condition = c;
}
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
return false;
}
};
- assertThat(condition.isOncePerProject()).isFalse();
+ assertThat(condition.isOncePerGroup()).isFalse();
}
}
--- /dev/null
+/*
+ * 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("");
+ }
+}
--- /dev/null
+/*
+ * 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");
+ }
+}