}
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());
}
}
import org.sonar.api.utils.WorkDurationFactory;
import org.sonar.api.utils.WorkUnit;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
/**
/**
* 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) {
}
@Test
- public void test_hascode() throws Exception {
+ public void test_hashcode() throws Exception {
DefaultCharacteristic characteristic = new DefaultCharacteristic()
.setId(1)
.setKey("MODULARITY")
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));
+ }
}
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);
}
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);
}
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));
+ }
}
return debtFormatter.format(UserSession.get().locale(), technicalDebt);
}
+ @CheckForNull
public WorkDuration toTechnicalDebt(String technicalDebtInLong) {
return workDurationFactory.createFromWorkingLong(Long.parseLong(technicalDebtInLong));
}