From 424475b26b6fbecad27b653da87c3c08e3039b8b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 22 May 2012 16:22:59 +0200 Subject: [PATCH] SONAR-2706 add support of default values in HasProjectPropertyCondition --- .../condition/HasProjectPropertyCondition.java | 4 +++- .../HasProjectPropertyConditionTest.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java index 1715f63617a..354915cff0e 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java +++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java @@ -19,6 +19,7 @@ */ package org.sonar.core.review.workflow.condition; +import org.sonar.api.config.Settings; import org.sonar.core.review.workflow.review.Review; import org.sonar.core.review.workflow.review.WorkflowContext; @@ -33,6 +34,7 @@ public final class HasProjectPropertyCondition extends ProjectPropertyCondition @Override public boolean doVerify(Review review, WorkflowContext context) { - return context.getProjectSettings().hasKey(getPropertyKey()); + Settings settings = context.getProjectSettings(); + return settings.hasKey(getPropertyKey()) || settings.getDefaultValue(getPropertyKey())!=null; } } diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java index 5edf7099a0f..541188cb47b 100644 --- a/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java +++ b/sonar-core/src/test/java/org/sonar/core/review/workflow/condition/HasProjectPropertyConditionTest.java @@ -20,6 +20,9 @@ package org.sonar.core.review.workflow.condition; import org.junit.Test; +import org.sonar.api.Properties; +import org.sonar.api.Property; +import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; import org.sonar.core.review.workflow.review.DefaultReview; import org.sonar.core.review.workflow.review.DefaultWorkflowContext; @@ -42,4 +45,19 @@ public class HasProjectPropertyConditionTest { context.setSettings(new Settings()); assertThat(condition.doVerify(new DefaultReview(), context)).isFalse(); } + + @Test + public void returnTrueIfDefaultValue() { + HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url"); + DefaultWorkflowContext context = new DefaultWorkflowContext(); + context.setSettings(new Settings(new PropertyDefinitions().addComponent(WithDefaultValue.class))); + assertThat(condition.doVerify(new DefaultReview(), context)).isTrue(); + } + + @Properties({ + @Property(key = "jira.url", name = "JIRA URL", defaultValue = "http://jira.com") + }) + private static class WithDefaultValue { + + } } -- 2.39.5