diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-07 22:08:45 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-09 10:13:43 +0200 |
commit | 84c39f50d53f7f4a76fcda6c58b6120875501e40 (patch) | |
tree | 66f3a96fc24de07bdf2cad46debe9f13e85792ee /sonar-db | |
parent | 9953f330120c5d4609dd695bc70885e8d46c5a99 (diff) | |
download | sonarqube-84c39f50d53f7f4a76fcda6c58b6120875501e40.tar.gz sonarqube-84c39f50d53f7f4a76fcda6c58b6120875501e40.zip |
SONAR-6644 fix debt when characteristic is none
Diffstat (limited to 'sonar-db')
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/rule/RuleDto.java | 19 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java | 60 |
2 files changed, 72 insertions, 7 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleDto.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleDto.java index d3188ec87db..2c5a17b4f59 100644 --- a/sonar-db/src/main/java/org/sonar/db/rule/RuleDto.java +++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleDto.java @@ -38,7 +38,7 @@ import org.sonar.db.Dto; public class RuleDto extends Dto<RuleKey> { - public static final Integer DISABLED_CHARACTERISTIC_ID = -1; + public static final int DISABLED_CHARACTERISTIC_ID = -1; public enum Format { HTML, MARKDOWN @@ -259,6 +259,15 @@ public class RuleDto extends Dto<RuleKey> { } @CheckForNull + public Integer getEffectiveSubCharacteristicId() { + Integer effective = subCharacteristicId == null ? defaultSubCharacteristicId : subCharacteristicId; + if (effective != null && effective != DISABLED_CHARACTERISTIC_ID) { + return effective; + } + return null; + } + + @CheckForNull public String getRemediationFunction() { return remediationFunction; } @@ -329,15 +338,11 @@ public class RuleDto extends Dto<RuleKey> { } public Set<String> getTags() { - return tags == null ? - new HashSet<String>() : - new TreeSet<>(Arrays.asList(StringUtils.split(tags, ','))); + return tags == null ? new HashSet<String>() : new TreeSet<>(Arrays.asList(StringUtils.split(tags, ','))); } public Set<String> getSystemTags() { - return systemTags == null ? - new HashSet<String>() : - new TreeSet<>(Arrays.asList(StringUtils.split(systemTags, ','))); + return systemTags == null ? new HashSet<String>() : new TreeSet<>(Arrays.asList(StringUtils.split(systemTags, ','))); } private String getTagsField() { diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java new file mode 100644 index 00000000000..7c170e7c8df --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDtoTest.java @@ -0,0 +1,60 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.db.rule; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.db.rule.RuleDto.DISABLED_CHARACTERISTIC_ID; + +public class RuleDtoTest { + + public static final int FAKE_SUB_CHAR_1 = 27; + public static final int FAKE_SUB_CHAR_2 = 42; + + @Test + public void effective_sub_characteristic_id() { + RuleDto dto = new RuleDto(); + + // characteristic is not set + dto.setSubCharacteristicId(null).setDefaultSubCharacteristicId(null); + assertThat(dto.getEffectiveSubCharacteristicId()).isNull(); + + // default characteristic is set + dto.setSubCharacteristicId(null).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2); + assertThat(dto.getEffectiveSubCharacteristicId()).isEqualTo(FAKE_SUB_CHAR_2); + + // default characteristic is set to "none" + dto.setSubCharacteristicId(null).setDefaultSubCharacteristicId(DISABLED_CHARACTERISTIC_ID); + assertThat(dto.getEffectiveSubCharacteristicId()).isNull(); + + // characteristic is overridden + dto.setSubCharacteristicId(FAKE_SUB_CHAR_1).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2); + assertThat(dto.getEffectiveSubCharacteristicId()).isEqualTo(FAKE_SUB_CHAR_1); + + // characteristic is set, no defaults + dto.setSubCharacteristicId(FAKE_SUB_CHAR_1).setDefaultSubCharacteristicId(null); + assertThat(dto.getEffectiveSubCharacteristicId()).isEqualTo(FAKE_SUB_CHAR_1); + + // characteristic is set to "none" + dto.setSubCharacteristicId(DISABLED_CHARACTERISTIC_ID).setDefaultSubCharacteristicId(FAKE_SUB_CHAR_2); + assertThat(dto.getEffectiveSubCharacteristicId()).isNull(); + } +} |