]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 6 Feb 2014 09:20:06 +0000 (10:20 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 6 Feb 2014 09:20:16 +0000 (10:20 +0100)
14 files changed:
sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java
sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java
sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/find_by_component_key_and_metric_key_without_text.xml [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/rule/Rule.java
sonar-server/src/main/java/org/sonar/server/rule/RuleDocumentParser.java
sonar-server/src/main/java/org/sonar/server/rule/ws/RuleShowWsHandler.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule/RuleTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java
sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java

index e1272f3b91a20a7bc7f5831d96a468f54b913f31..453f1fc43b65b6c9bb4f9f43e14636d67eeac494 100644 (file)
@@ -78,19 +78,31 @@ public class ModuleIssues {
   private boolean initAndAddIssue(DefaultIssue issue, @Nullable Violation violation) {
     RuleKey ruleKey = issue.ruleKey();
     Rule rule = ruleFinder.findByKey(ruleKey);
+    validateRule(issue, rule);
+    ActiveRule activeRule = qProfile.getActiveRule(ruleKey.repository(), ruleKey.rule());
+    if (activeRule == null || activeRule.getRule() == null) {
+      // rule does not exist or is not enabled -> ignore the issue
+      return false;
+    }
+    updateIssue(issue, rule, activeRule);
+    if (filters.accept(issue, violation)) {
+      cache.put(issue);
+      return true;
+    }
+    return false;
+  }
+
+  private void validateRule(DefaultIssue issue, Rule rule){
+    RuleKey ruleKey = issue.ruleKey();
     if (rule == null) {
       throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey));
     }
     if (Strings.isNullOrEmpty(rule.getName()) && Strings.isNullOrEmpty(issue.message())) {
       throw MessageException.of(String.format("The rule '%s' has no name and the related issue has no message.", ruleKey));
     }
+  }
 
-    ActiveRule activeRule = qProfile.getActiveRule(ruleKey.repository(), ruleKey.rule());
-    if (activeRule == null || activeRule.getRule() == null) {
-      // rule does not exist or is not enabled -> ignore the issue
-      return false;
-    }
-
+  private void updateIssue(DefaultIssue issue, Rule rule, ActiveRule activeRule ){
     if (Strings.isNullOrEmpty(issue.message())) {
       issue.setMessage(rule.getName());
     }
@@ -100,12 +112,6 @@ public class ModuleIssues {
       issue.setSeverity(activeRule.getSeverity().name());
     }
     issue.setTechnicalDebt(technicalDebtCalculator.calculTechnicalDebt(issue));
-
-    if (filters.accept(issue, violation)) {
-      cache.put(issue);
-      return true;
-    }
-    return false;
   }
 
 }
index 5b9ba0c15cbc54d0b60b72b9d1d5efe4b74f4d4b..10dba57cd7fc98cd05e56280ce93540000ebbed0 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.utils.DateUtils;
 import static org.fest.assertions.Assertions.assertThat;
 
 public class IssueChangeDtoTest {
+
   @Test
   public void create_from_comment() throws Exception {
     DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
@@ -58,4 +59,29 @@ public class IssueChangeDtoTest {
     assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
     assertThat(dto.getUserLogin()).isEqualTo("emmerik");
   }
+
+  @Test
+  public void create_from_diff_without_date() throws Exception {
+    FieldDiffs diffs = new FieldDiffs();
+    diffs.setDiff("severity", "INFO", "BLOCKER");
+    diffs.setUserLogin("emmerik");
+    diffs.setCreationDate(null);
+
+    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
+
+    assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
+    assertThat(dto.getChangeType()).isEqualTo("diff");
+    assertThat(dto.getCreatedAt()).isNotNull();
+    assertThat(dto.getUpdatedAt()).isNotNull();
+    assertThat(dto.getIssueChangeCreationDate()).isNull();
+    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
+    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+  }
+
+  @Test
+  public void to_string() throws Exception {
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+    IssueChangeDto dto = IssueChangeDto.of(comment);
+    assertThat(dto.toString()).contains("ABCDE");
+  }
 }
index bec6ebda16e411e9012f23c15a70318c87380e2c..dd00d55dcc5e08a203bb3977a018c01d086437b2 100644 (file)
@@ -44,8 +44,21 @@ public class MeasureDataDaoTest extends AbstractDaoTestCase {
     assertThat(result.getMeasureId()).isEqualTo(1);
     assertThat(result.getSnapshotId()).isEqualTo(1);
     assertThat(result.getText()).isNotNull();
+    assertThat(result.getData()).isNotNull();
 
     // FIXME failing because data is returned in wrong format
 //    assertThat(result.getText()).isEqualTo("test");
   }
+
+  @Test
+  public void find_by_component_key_and_metric_key_without_text() throws Exception {
+    setupData("find_by_component_key_and_metric_key_without_text");
+
+    MeasureDataDto result = dao.findByComponentKeyAndMetricKey("org.sonar.core.measure.db.MeasureData", "authors_by_line");
+    assertThat(result.getId()).isEqualTo(1);
+    assertThat(result.getMeasureId()).isEqualTo(1);
+    assertThat(result.getSnapshotId()).isEqualTo(1);
+    assertThat(result.getText()).isNull();
+    assertThat(result.getData()).isNull();
+  }
 }
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/find_by_component_key_and_metric_key_without_text.xml b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/find_by_component_key_and_metric_key_without_text.xml
new file mode 100644 (file)
index 0000000..3938257
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+
+  <snapshots id="1" project_id="1" islast="[true]" />
+  <project_measures id="1" snapshot_id="1" metric_id="1"/>
+  <metrics id="1" name="authors_by_line"/>
+  <projects id="1" kee="org.sonar.core.measure.db.MeasureData" enabled="[true]"/>
+
+  <measure_data id="1" measure_id="1" snapshot_id="1" data="[null]"/>
+
+</dataset>
index 55772eac07d95c5366dbc16ec69d4fb6a4445872..8b0d89c0c8ebeb6cdd11a138850862530bc87687 100644 (file)
@@ -208,7 +208,7 @@ public class ActiveRule implements Cloneable {
   public ActiveRule setParameter(String key, String value) {
     RuleParam ruleParameter = rule.getParam(key);
     if (ruleParameter != null) {
-      activeRuleParams.add(new ActiveRuleParam(this, ruleParameter, key, value));
+      activeRuleParams.add(new ActiveRuleParam(this, ruleParameter, value));
     }
     return this;
   }
index f634ce381108752d2f6da62b48b7ba922236e474..68ae2c1365cd339f2a76b875688e52e24a7529ce 100644 (file)
@@ -67,11 +67,11 @@ public class ActiveRuleParam implements Cloneable {
    * @deprecated visibility should be decreased to protected or package
    */
   @Deprecated
-  public ActiveRuleParam(ActiveRule activeRule, RuleParam ruleParam, String paramKey, String value) {
+  public ActiveRuleParam(ActiveRule activeRule, RuleParam ruleParam, String value) {
     this.activeRule = activeRule;
     this.ruleParam = ruleParam;
     this.value = value;
-    this.paramKey = paramKey;
+    this.paramKey = ruleParam.getKey();
   }
 
   public ActiveRule getActiveRule() {
@@ -138,7 +138,7 @@ public class ActiveRuleParam implements Cloneable {
 
   @Override
   public Object clone() {
-    return new ActiveRuleParam(getActiveRule(), getRuleParam(), getParamKey(), getValue());
+    return new ActiveRuleParam(getActiveRule(), getRuleParam(), getValue());
   }
 
 }
index feb12e107e863d88a395ad18ad2d68d29a831b9a..464521a9627e08d644e98ed45472a42586197a64 100644 (file)
@@ -201,8 +201,7 @@ public class ProfilesBackup {
             while (reader.hasMoreChildren()) {
               reader.moveDown();
               Map<String, String> valuesParam = readNode(reader);
-              ActiveRuleParam activeRuleParam = new ActiveRuleParam(null, new RuleParam(null, valuesParam.get(KEY), null, null), valuesParam.get(KEY),
-                valuesParam.get(VALUE));
+              ActiveRuleParam activeRuleParam = new ActiveRuleParam(null, new RuleParam(null, valuesParam.get(KEY), null, null), valuesParam.get(VALUE));
               params.add(activeRuleParam);
               reader.moveUp();
             }
index 169cc179ddaa3d56c01d5950b63ebecb5b2575f3..cdbb13f3beb4653ff7c5a8de8e91528efebc77dc 100644 (file)
@@ -31,6 +31,8 @@ import java.util.Date;
 
 public class Rule {
 
+  public static final String MANUAL_REPOSITORY_KEY = "manual";
+
   private int id;
   private RuleKey ruleKey;
   private String language;
index d45f9f1b8b23acadb2c62d8bea9a2031eade7d29..e9d9846ba471f2a3956a8a9a12689db0b9006c13 100644 (file)
@@ -33,21 +33,24 @@ import static com.google.common.collect.Lists.newArrayList;
 
 public class RuleDocumentParser {
 
-  public static Rule parse(Map<String, Object> ruleSource) {
-    Rule.Builder ruleBuilder = new Rule.Builder();
+  private void RuleDocumentParser() {
+    // Utility class
+  }
 
-    ruleBuilder.setId((Integer) ruleSource.get(RuleDocument.FIELD_ID));
-    ruleBuilder.setKey((String) ruleSource.get(RuleDocument.FIELD_KEY));
-    ruleBuilder.setLanguage((String) ruleSource.get(RuleDocument.FIELD_LANGUAGE));
-    ruleBuilder.setRepositoryKey((String) ruleSource.get(RuleDocument.FIELD_REPOSITORY_KEY));
-    ruleBuilder.setSeverity((String) ruleSource.get(RuleDocument.FIELD_SEVERITY));
-    ruleBuilder.setName((String) ruleSource.get(RuleDocument.FIELD_NAME));
-    ruleBuilder.setDescription((String) ruleSource.get(RuleDocument.FIELD_DESCRIPTION));
-    ruleBuilder.setStatus((String) ruleSource.get(RuleDocument.FIELD_STATUS));
-    ruleBuilder.setCardinality((String) ruleSource.get("cardinality"));
-    ruleBuilder.setTemplateId((Integer) ruleSource.get(RuleDocument.FIELD_TEMPLATE_ID));
-    ruleBuilder.setCreatedAt(parseOptionalDate(RuleDocument.FIELD_CREATED_AT, ruleSource));
-    ruleBuilder.setUpdatedAt(parseOptionalDate(RuleDocument.FIELD_UPDATED_AT, ruleSource));
+  public static Rule parse(Map<String, Object> ruleSource) {
+    Rule.Builder ruleBuilder = new Rule.Builder()
+      .setId((Integer) ruleSource.get(RuleDocument.FIELD_ID))
+      .setKey((String) ruleSource.get(RuleDocument.FIELD_KEY))
+      .setLanguage((String) ruleSource.get(RuleDocument.FIELD_LANGUAGE))
+      .setRepositoryKey((String) ruleSource.get(RuleDocument.FIELD_REPOSITORY_KEY))
+      .setSeverity((String) ruleSource.get(RuleDocument.FIELD_SEVERITY))
+      .setName((String) ruleSource.get(RuleDocument.FIELD_NAME))
+      .setDescription((String) ruleSource.get(RuleDocument.FIELD_DESCRIPTION))
+      .setStatus((String) ruleSource.get(RuleDocument.FIELD_STATUS))
+      .setCardinality((String) ruleSource.get("cardinality"))
+      .setTemplateId((Integer) ruleSource.get(RuleDocument.FIELD_TEMPLATE_ID))
+      .setCreatedAt(parseOptionalDate(RuleDocument.FIELD_CREATED_AT, ruleSource))
+      .setUpdatedAt(parseOptionalDate(RuleDocument.FIELD_UPDATED_AT, ruleSource));
 
     if (ruleSource.containsKey(RuleDocument.FIELD_NOTE)) {
       Map<String, Object> ruleNoteDocument = (Map<String, Object>) ruleSource.get(RuleDocument.FIELD_NOTE);
@@ -62,10 +65,10 @@ public class RuleDocumentParser {
     List<RuleParam> params = Lists.newArrayList();
     if (ruleSource.containsKey(RuleDocument.FIELD_PARAMS)) {
       Map<String, Map<String, Object>> ruleParams = Maps.newHashMap();
-      for (Map<String, Object> ruleParam: (List<Map<String, Object>>) ruleSource.get(RuleDocument.FIELD_PARAMS)) {
+      for (Map<String, Object> ruleParam : (List<Map<String, Object>>) ruleSource.get(RuleDocument.FIELD_PARAMS)) {
         ruleParams.put((String) ruleParam.get(RuleDocument.FIELD_PARAM_KEY), ruleParam);
       }
-      for(Map.Entry<String, Map<String, Object>> ruleParam: ruleParams.entrySet()) {
+      for (Map.Entry<String, Map<String, Object>> ruleParam : ruleParams.entrySet()) {
         RuleParamType type = RuleParamType.parse((String) ruleParam.getValue().get(RuleDocument.FIELD_PARAM_TYPE));
         params.add(new RuleParam(
           (String) ruleParam.getValue().get(RuleDocument.FIELD_PARAM_KEY),
@@ -79,7 +82,7 @@ public class RuleDocumentParser {
 
     List<String> systemTags = newArrayList();
     if (ruleSource.containsKey(RuleDocument.FIELD_SYSTEM_TAGS)) {
-      for (String tag: (List<String>) ruleSource.get(RuleDocument.FIELD_SYSTEM_TAGS)) {
+      for (String tag : (List<String>) ruleSource.get(RuleDocument.FIELD_SYSTEM_TAGS)) {
         systemTags.add(tag);
       }
     }
@@ -87,7 +90,7 @@ public class RuleDocumentParser {
 
     List<String> adminTags = newArrayList();
     if (ruleSource.containsKey(RuleDocument.FIELD_ADMIN_TAGS)) {
-      for (String tag: (List<String>) ruleSource.get(RuleDocument.FIELD_ADMIN_TAGS)) {
+      for (String tag : (List<String>) ruleSource.get(RuleDocument.FIELD_ADMIN_TAGS)) {
         adminTags.add(tag);
       }
     }
index 627397c5ffed598909e044cc55bc71a3a91a96c7..f3537f60e53942505aab928022f712354e581514 100644 (file)
@@ -73,7 +73,7 @@ public class RuleShowWsHandler implements RequestHandler {
 
   @CheckForNull
   private Rule findRule(RuleKey ruleKey) {
-    if (ruleKey.repository().equals("manual")) {
+    if (ruleKey.repository().equals(Rule.MANUAL_REPOSITORY_KEY)) {
       org.sonar.api.rules.Rule rule = ruleFinder.findByKey(ruleKey);
       if (rule != null) {
         return new Rule.Builder()
diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTest.java
new file mode 100644 (file)
index 0000000..4b141db
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.server.qualityprofile;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class QProfileTest {
+
+  @Test
+  public void test_getters_and_setters() {
+    QProfile profile = new QProfile().setId(1).setName("Default").setLanguage("java").setParent("Parent").setUsed(true).setVersion(1);
+
+    assertThat(profile.id()).isEqualTo(1);
+    assertThat(profile.name()).isEqualTo("Default");
+    assertThat(profile.language()).isEqualTo("java");
+    assertThat(profile.parent()).isEqualTo("Parent");
+    assertThat(profile.used()).isTrue();
+    assertThat(profile.version()).isEqualTo(1);
+  }
+
+  @Test
+  public void to_string() throws Exception {
+    assertThat(new QProfile().setId(1).setName("Default").setLanguage("java").setParent("Parent").setUsed(true).setVersion(1).toString())
+      .contains("[id=1,name=Default,language=java,parent=Parent,version=1,used=true]");
+  }
+
+  @Test
+  public void is_inherited() throws Exception {
+    assertThat(new QProfile().setId(1).setName("Default").setLanguage("java").setParent("Parent").isInherited()).isTrue();
+    assertThat(new QProfile().setId(1).setName("Default").setLanguage("java").setParent(null).isInherited()).isFalse();
+  }
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTest.java
new file mode 100644 (file)
index 0000000..e749e0a
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * 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.server.rule;
+
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.check.Cardinality;
+
+import java.util.Date;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class RuleTest {
+
+  @Test
+  public void test_getters_and_setters() throws Exception {
+    Rule rule = new Rule.Builder()
+      .setId(1)
+      .setKey("AvoidCycle")
+      .setRepositoryKey("squid")
+      .setName("Avoid Cycle")
+      .setDescription("Avoid cycle between packages")
+      .setLanguage("java")
+      .setSeverity(Severity.BLOCKER)
+      .setStatus("BETA")
+      .setCardinality(Cardinality.SINGLE.name())
+      .setTemplateId(2)
+      .setRuleNote(new RuleNote("Some note", "john", new Date(), new Date()))
+      .setAdminTags(newArrayList("AdminTag"))
+      .setSystemTags(newArrayList("SysTag"))
+      .setParams(newArrayList(new RuleParam("key", "desc", "default", RuleParamType.STRING)))
+      .setCreatedAt(new Date())
+      .setUpdatedAt(new Date())
+      .build();
+
+    assertThat(rule.id()).isEqualTo(1);
+    assertThat(rule.ruleKey()).isEqualTo(RuleKey.of("squid", "AvoidCycle"));
+    assertThat(rule.name()).isEqualTo("Avoid Cycle");
+    assertThat(rule.description()).isEqualTo("Avoid cycle between packages");
+    assertThat(rule.language()).isEqualTo("java");
+    assertThat(rule.severity()).isEqualTo("BLOCKER");
+    assertThat(rule.status()).isEqualTo("BETA");
+    assertThat(rule.cardinality()).isEqualTo("SINGLE");
+    assertThat(rule.templateId()).isEqualTo(2);
+    assertThat(rule.ruleNote()).isNotNull();
+    assertThat(rule.adminTags()).hasSize(1);
+    assertThat(rule.systemTags()).hasSize(1);
+    assertThat(rule.params()).hasSize(1);
+    assertThat(rule.createdAt()).isNotNull();
+    assertThat(rule.updatedAt()).isNotNull();
+  }
+
+  @Test
+  public void is_template() throws Exception {
+    assertThat(new Rule.Builder()
+      .setId(1)
+      .setKey("AvoidCycle")
+      .setRepositoryKey("squid")
+      .setName("Avoid Cycle")
+      .setDescription("Avoid cycle between packages")
+      .setLanguage("java")
+      .setSeverity(Severity.BLOCKER)
+      .setStatus("BETA")
+      .setCardinality(Cardinality.MULTIPLE.name())
+      .setCreatedAt(new Date())
+      .build().isTemplate()).isTrue();
+
+    assertThat(new Rule.Builder()
+      .setId(1)
+      .setKey("AvoidCycle")
+      .setRepositoryKey("squid")
+      .setName("Avoid Cycle")
+      .setDescription("Avoid cycle between packages")
+      .setLanguage("java")
+      .setSeverity(Severity.BLOCKER)
+      .setStatus("BETA")
+      .setCardinality(Cardinality.SINGLE.name())
+      .setCreatedAt(new Date())
+      .build().isTemplate()).isFalse();
+  }
+
+  @Test
+  public void is_copy_of_template() throws Exception {
+    assertThat(new Rule.Builder()
+      .setId(1)
+      .setKey("AvoidCycle")
+      .setRepositoryKey("squid")
+      .setName("Avoid Cycle")
+      .setDescription("Avoid cycle between packages")
+      .setLanguage("java")
+      .setSeverity(Severity.BLOCKER)
+      .setStatus("BETA")
+      .setCardinality(Cardinality.MULTIPLE.name())
+      .setTemplateId(null)
+      .setCreatedAt(new Date())
+      .build().isEditable()).isFalse();
+
+    assertThat(new Rule.Builder()
+      .setId(1)
+      .setKey("AvoidCycle")
+      .setRepositoryKey("squid")
+      .setName("Avoid Cycle")
+      .setDescription("Avoid cycle between packages")
+      .setLanguage("java")
+      .setSeverity(Severity.BLOCKER)
+      .setStatus("BETA")
+      .setCardinality(Cardinality.SINGLE.name())
+      .setTemplateId(2)
+      .setCreatedAt(new Date())
+      .build().isEditable()).isTrue();
+  }
+}
+
+
index 96d86a945aee7964b8668c782d06716cdb5ec11b..e20156d9ba953b1afb5445b4bd9754a85e632fe9 100644 (file)
@@ -42,10 +42,7 @@ import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 @RunWith(MockitoJUnitRunner.class)
 public class RulesTest {
@@ -66,7 +63,6 @@ public class RulesTest {
     rules = new Rules(ruleDao, ruleOperations, ruleRegistry);
   }
 
-
   @Test
   public void create_rule_note() throws Exception {
     RuleDto rule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle");
index 00ae724b6fcb7452ee9eb2bb4bdfce95d18b9ed3..e88120fdba687a16e3ab1f8b529bf79627b889dd 100644 (file)
@@ -41,6 +41,17 @@ public class TypeValidationsTest {
     verify(fakeTypeValidation).validate("10", newArrayList("a"));
   }
 
+  @Test
+  public void validate__multiple_values() throws Exception {
+    TypeValidation fakeTypeValidation = mock(TypeValidation.class);
+    when(fakeTypeValidation.key()).thenReturn("Fake");
+
+    TypeValidations typeValidations = new TypeValidations(newArrayList(fakeTypeValidation));
+    typeValidations.validate(newArrayList("10", "11", "12"), "Fake", newArrayList("11"));
+
+    verify(fakeTypeValidation).validate("10", newArrayList("11"));
+  }
+
   @Test
   public void fail_on_unknown_type() throws Exception {
     TypeValidation fakeTypeValidation = mock(TypeValidation.class);