]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 10 Feb 2014 07:35:43 +0000 (08:35 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 10 Feb 2014 07:35:43 +0000 (08:35 +0100)
sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java

index 3bb7b5bae7d94176c6d220e33340339ef82b6d71..78d3157cd2410d465b5510ff953991b084f9f017 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.sonar.core.technicaldebt;
 
+
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
@@ -73,6 +74,9 @@ public class DefaultTechnicalDebtManager implements TechnicalDebtManager {
     CharacteristicDto requirementDto = dao.selectByRuleId(ruleId);
     if (requirementDto != null) {
       Rule rule = ruleFinder.findById(ruleId);
+      if (rule == null) {
+        throw new IllegalArgumentException(String.format("Rule with id '%s' do not exists.", ruleId));
+      }
       return toCharacteristic(requirementDto, RuleKey.of(rule.getRepositoryKey(), rule.getKey()));
     }
     return null;
index 7ac3d43530930179904400f312a19d136eb90d2c..a69517c7c9951f75e0b17acca2769762fc5658b3 100644 (file)
@@ -37,6 +37,7 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -163,4 +164,17 @@ public class DefaultTechnicalDebtManagerTest {
 
     assertThat(finder.findRequirementByRuleId(1)).isNull();
   }
+
+  @Test
+  public void fail_to_find_requirement_by_rule_id_if_unknown_rule_id() throws Exception {
+    when(dao.selectByRuleId(1)).thenReturn(
+      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear").setFactorValue(30.0).setFactorUnit("mn"));
+    when(ruleFinder.findById(1)).thenReturn(null);
+    try {
+      finder.findRequirementByRuleId(1);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalArgumentException.class);
+    }
+  }
 }