diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-18 09:29:07 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-18 13:00:03 +0100 |
commit | b47ff2a3751156db634763f9da7a5033e72f3d1a (patch) | |
tree | 03fc850bb054236afa54f8244cb21617af35b508 /sonar-plugin-api | |
parent | 59200d6dbd6e9adb3ce4e9ad59312e7115541aeb (diff) | |
download | sonarqube-b47ff2a3751156db634763f9da7a5033e72f3d1a.tar.gz sonarqube-b47ff2a3751156db634763f9da7a5033e72f3d1a.zip |
SONAR-4776 Improve calculation of new technical debt from changelog
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/FieldDiffs.java | 22 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java | 18 |
2 files changed, 40 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/FieldDiffs.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/FieldDiffs.java index 7cd29d66d6e..6329f703443 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/FieldDiffs.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/FieldDiffs.java @@ -157,14 +157,36 @@ public class FieldDiffs implements Serializable { } @CheckForNull + public Long oldValueLong() { + return toLong(oldValue); + } + + @CheckForNull public T newValue() { return newValue; } + @CheckForNull + public Long newValueLong() { + return toLong(newValue); + } + void setNewValue(T t) { this.newValue = t; } + @CheckForNull + private Long toLong(Serializable value) { + if (value != null && !"".equals(value)) { + try { + return Long.valueOf((String) value); + } catch (ClassCastException e) { + return (Long) value; + } + } + return null; + } + @Override public String toString() { //TODO escape , and | characters diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java index 6a07ac3cffb..2490d88bdcb 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java @@ -49,6 +49,24 @@ public class FieldDiffsTest { } @Test + public void diff_with_long_values() throws Exception { + diffs.setDiff("technicalDebt", 50l, "100"); + + FieldDiffs.Diff diff = diffs.diffs().get("technicalDebt"); + assertThat(diff.oldValueLong()).isEqualTo(50l); + assertThat(diff.newValueLong()).isEqualTo(100l); + } + + @Test + public void diff_with_empty_long_values() throws Exception { + diffs.setDiff("technicalDebt", null, ""); + + FieldDiffs.Diff diff = diffs.diffs().get("technicalDebt"); + assertThat(diff.oldValueLong()).isNull(); + assertThat(diff.newValueLong()).isNull(); + } + + @Test public void test_diff_by_key() throws Exception { diffs.setDiff("severity", "BLOCKER", "INFO"); diffs.setDiff("resolution", "OPEN", "FIXED"); |