aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/FieldDiffs.java22
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java18
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");