From: Julien Lancelot Date: Thu, 6 Feb 2014 09:20:06 +0000 (+0100) Subject: Fix quality flaws X-Git-Tag: 4.2~233 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a5184d1f9883111a6c9db6d188845cbe21ea81a;p=sonarqube.git Fix quality flaws --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java index e1272f3b91a..453f1fc43b6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java @@ -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; } } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java index 5b9ba0c15cb..10dba57cd7f 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java @@ -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"); + } } diff --git a/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java index bec6ebda16e..dd00d55dcc5 100644 --- a/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/measure/db/MeasureDataDaoTest.java @@ -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 index 00000000000..393825770e4 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureDataDaoTest/find_by_component_key_and_metric_key_without_text.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java index 55772eac07d..8b0d89c0c8e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java @@ -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; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java index f634ce38110..68ae2c1365c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java @@ -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()); } } diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java index feb12e107e8..464521a9627 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java @@ -201,8 +201,7 @@ public class ProfilesBackup { while (reader.hasMoreChildren()) { reader.moveDown(); Map 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(); } diff --git a/sonar-server/src/main/java/org/sonar/server/rule/Rule.java b/sonar-server/src/main/java/org/sonar/server/rule/Rule.java index 169cc179dda..cdbb13f3beb 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/Rule.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/Rule.java @@ -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; diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleDocumentParser.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleDocumentParser.java index d45f9f1b8b2..e9d9846ba47 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/RuleDocumentParser.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleDocumentParser.java @@ -33,21 +33,24 @@ import static com.google.common.collect.Lists.newArrayList; public class RuleDocumentParser { - public static Rule parse(Map 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 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 ruleNoteDocument = (Map) ruleSource.get(RuleDocument.FIELD_NOTE); @@ -62,10 +65,10 @@ public class RuleDocumentParser { List params = Lists.newArrayList(); if (ruleSource.containsKey(RuleDocument.FIELD_PARAMS)) { Map> ruleParams = Maps.newHashMap(); - for (Map ruleParam: (List>) ruleSource.get(RuleDocument.FIELD_PARAMS)) { + for (Map ruleParam : (List>) ruleSource.get(RuleDocument.FIELD_PARAMS)) { ruleParams.put((String) ruleParam.get(RuleDocument.FIELD_PARAM_KEY), ruleParam); } - for(Map.Entry> ruleParam: ruleParams.entrySet()) { + for (Map.Entry> 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 systemTags = newArrayList(); if (ruleSource.containsKey(RuleDocument.FIELD_SYSTEM_TAGS)) { - for (String tag: (List) ruleSource.get(RuleDocument.FIELD_SYSTEM_TAGS)) { + for (String tag : (List) ruleSource.get(RuleDocument.FIELD_SYSTEM_TAGS)) { systemTags.add(tag); } } @@ -87,7 +90,7 @@ public class RuleDocumentParser { List adminTags = newArrayList(); if (ruleSource.containsKey(RuleDocument.FIELD_ADMIN_TAGS)) { - for (String tag: (List) ruleSource.get(RuleDocument.FIELD_ADMIN_TAGS)) { + for (String tag : (List) ruleSource.get(RuleDocument.FIELD_ADMIN_TAGS)) { adminTags.add(tag); } } diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleShowWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleShowWsHandler.java index 627397c5ffe..f3537f60e53 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleShowWsHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleShowWsHandler.java @@ -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 index 00000000000..4b141dbc216 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTest.java @@ -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 index 00000000000..e749e0ae4e9 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleTest.java @@ -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(); + } +} + + diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java index 96d86a945ae..e20156d9ba9 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java @@ -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"); diff --git a/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java b/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java index 00ae724b6fc..e88120fdba6 100644 --- a/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java @@ -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);