]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Feb 2014 14:34:07 +0000 (15:34 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Feb 2014 14:34:07 +0000 (15:34 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java
sonar-batch/src/main/java/org/sonar/batch/debt/RuleDebtCalculator.java
sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java
sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java
sonar-server/src/main/java/org/sonar/server/technicaldebt/DebtService.java

index 6813e1f197101298b3f2886d868e622c2dd14c3a..73695338842ee2ffa2d9f5ef50306bbbc3af960c 100644 (file)
@@ -167,13 +167,9 @@ public final class TechnicalDebtDecorator implements Decorator {
   }
 
   private double computeTechnicalDebt(Metric metric, DecoratorContext context, Requirement requirement, Collection<Issue> issues) {
-    WorkDuration debt = workDurationFactory.createFromWorkingLong(0l);
-//    double value = 0d;
+    WorkDuration debt = workDurationFactory.createFromWorkingValue(0, WorkDuration.UNIT.MINUTES);
     if (issues != null) {
       for (Issue issue : issues) {
-//        if (debt != null) {
-//          value += debt.toWorkingDays();
-//        }
         debt = debt.add(((DefaultIssue) issue).technicalDebt());
       }
     }
index d828a4df799dcd1b441f95d8d942542a36acf2a4..8913edac04bec63161561b9c8f71c8cdd54885c9 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkDurationFactory;
 import org.sonar.api.utils.WorkUnit;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 /**
@@ -47,7 +48,8 @@ public class RuleDebtCalculator implements BatchExtension {
   /**
    * Calculate the technical debt from a requirement
    */
-  public WorkDuration calculateTechnicalDebt(RuleKey ruleKey, Double effortToFix) {
+  @CheckForNull
+  public WorkDuration calculateTechnicalDebt(RuleKey ruleKey, @Nullable Double effortToFix) {
     Requirement requirement = model.requirementsByRule(ruleKey);
     if (requirement != null) {
       if (requirement.function().equals(DefaultRequirement.CONSTANT_ISSUE) && effortToFix != null) {
index 343ec3285cc8b8338203a7c8d08935416a90ef03..57cb94e3ec6cb3a8f81b884aed67854c46f40319 100644 (file)
@@ -90,7 +90,7 @@ public class DefaultRequirementTest {
   }
 
   @Test
-  public void test_hascode() throws Exception {
+  public void test_hashcode() throws Exception {
     DefaultCharacteristic characteristic = new DefaultCharacteristic()
       .setId(1)
       .setKey("MODULARITY")
@@ -102,4 +102,37 @@ public class DefaultRequirementTest {
     assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode())
       .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo2", "rule2")).setCharacteristic(characteristic).hashCode());
   }
+
+  @Test
+  public void test_deprecated_setters_and_getters_for_characteristic() throws Exception {
+    DefaultCharacteristic root = new DefaultCharacteristic().setId(1).setKey("REUSABILITY");
+
+    DefaultCharacteristic characteristic = new DefaultCharacteristic()
+      .setId(1)
+      .setKey("MODULARITY")
+      .setName("Modularity")
+      .setParent(root)
+      .setRoot(root);
+
+    DefaultRequirement requirement = new DefaultRequirement()
+      .setId(3)
+      .setRuleKey(RuleKey.of("repo", "rule"))
+      .setCharacteristic(characteristic)
+      .setRootCharacteristic(root)
+      .setFunction("linear_offset")
+      .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
+      .setOffset(WorkUnit.create(1d, WorkUnit.HOURS));
+
+    assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
+    assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
+
+    assertThat(new DefaultRequirement()
+      .setId(3)
+      .setRuleKey(RuleKey.of("repo", "rule"))
+      .setCharacteristic(characteristic)
+      .setRootCharacteristic(root)
+      .setFunction("linear_offset")
+      .setFactor(WorkUnit.create(2d, WorkUnit.DAYS))
+      .factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.DAYS));
+  }
 }
index 193e5c5b145201f21529e64a342454e2f6857e83..4ae4d77241bfb3d21783364ed5f4d0637cc65fee 100644 (file)
@@ -47,10 +47,8 @@ public class DefaultCharacteristicTest {
     assertThat(characteristic.function()).isNull();
     assertThat(characteristic.factorValue()).isNull();
     assertThat(characteristic.factorUnit()).isNull();
-    assertThat(characteristic.factor()).isNull();
     assertThat(characteristic.offsetValue()).isNull();
     assertThat(characteristic.offsetUnit()).isNull();
-    assertThat(characteristic.offset()).isNull();
     assertThat(characteristic.parentId()).isEqualTo(2);
     assertThat(characteristic.rootId()).isEqualTo(2);
   }
@@ -76,10 +74,8 @@ public class DefaultCharacteristicTest {
     assertThat(requirement.function()).isEqualTo("linear_offset");
     assertThat(requirement.factorValue()).isEqualTo(2);
     assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
-    assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
     assertThat(requirement.offsetValue()).isEqualTo(1);
     assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.HOURS);
-    assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
     assertThat(requirement.parentId()).isEqualTo(2);
     assertThat(requirement.rootId()).isEqualTo(3);
   }
@@ -131,6 +127,24 @@ public class DefaultCharacteristicTest {
     assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode()).isNotEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo2", "rule2")).hashCode());
   }
 
+  @Test
+  public void test_deprecated_setters_and_getters_for_characteristic() throws Exception {
+    DefaultCharacteristic requirement = new DefaultCharacteristic()
+      .setId(1)
+      .setRuleKey(RuleKey.of("repo", "rule"))
+      .setFunction("linear_offset")
+      .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
+      .setOffset(WorkUnit.create(1d, WorkUnit.HOURS));
 
+    assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
+    assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
+
+    assertThat(new DefaultCharacteristic()
+      .setId(1)
+      .setRuleKey(RuleKey.of("repo", "rule"))
+      .setFunction("linear")
+      .setFactor(WorkUnit.create(2d, WorkUnit.DAYS))
+      .factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.DAYS));
+  }
 
 }
index f05964841082b6e475735f1311c016ff59a1b9e0..49f04b0ca7d414a50f672c76691390e361f57604 100644 (file)
@@ -47,6 +47,7 @@ public class DebtService implements ServerComponent {
     return debtFormatter.format(UserSession.get().locale(), technicalDebt);
   }
 
+  @CheckForNull
   public WorkDuration toTechnicalDebt(String technicalDebtInLong) {
     return workDurationFactory.createFromWorkingLong(Long.parseLong(technicalDebtInLong));
   }