aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-08-10 17:57:10 +0200
committerSonarTech <sonartech@sonarsource.com>2018-08-21 20:21:04 +0200
commit35f53579966194ac83fcb0c4b7b570de572ec5cd (patch)
tree85a9211620dae24b3da6f3c5d788a62b758b30a9 /sonar-core
parente20b703430b7c270d81d1d4f14b5ccdc79a7a7ca (diff)
downloadsonarqube-35f53579966194ac83fcb0c4b7b570de572ec5cd.tar.gz
sonarqube-35f53579966194ac83fcb0c4b7b570de572ec5cd.zip
SONAR-8368 fix issue change log diff parsing for old value alone
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java17
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java28
2 files changed, 25 insertions, 20 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java b/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
index a5e23f42689..6f579501284 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java
@@ -20,7 +20,6 @@
package org.sonar.core.issue;
import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import java.io.Serializable;
import java.util.Date;
@@ -28,6 +27,7 @@ import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.isNullOrEmpty;
/**
@@ -119,16 +119,13 @@ public class FieldDiffs implements Serializable {
for (String field : fields) {
String[] keyValues = field.split("=");
if (keyValues.length == 2) {
- String[] values = keyValues[1].split("\\|");
- String oldValue = "";
- String newValue = "";
- if (values.length == 1) {
- newValue = Strings.nullToEmpty(values[0]);
- } else if (values.length == 2) {
- oldValue = Strings.nullToEmpty(values[0]);
- newValue = Strings.nullToEmpty(values[1]);
+ String values = keyValues[1];
+ int split = values.indexOf('|');
+ if (split > -1) {
+ diffs.setDiff(keyValues[0], values.substring(0, split), values.substring(split +1));
+ } else {
+ diffs.setDiff(keyValues[0], "", emptyToNull(values));
}
- diffs.setDiff(keyValues[0], oldValue, newValue);
} else {
diffs.setDiff(keyValues[0], "", "");
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java b/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java
index f94229ea677..962dcae300e 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/FieldDiffsTest.java
@@ -33,7 +33,7 @@ public class FieldDiffsTest {
}
@Test
- public void test_diff() throws Exception {
+ public void test_diff() {
diffs.setDiff("severity", "BLOCKER", "INFO");
diffs.setDiff("resolution", "OPEN", "FIXED");
@@ -67,7 +67,7 @@ public class FieldDiffsTest {
}
@Test
- public void test_diff_by_key() throws Exception {
+ public void test_diff_by_key() {
diffs.setDiff("severity", "BLOCKER", "INFO");
diffs.setDiff("resolution", "OPEN", "FIXED");
@@ -92,7 +92,7 @@ public class FieldDiffsTest {
}
@Test
- public void test_toString() throws Exception {
+ public void test_toString() {
diffs.setDiff("severity", "BLOCKER", "INFO");
diffs.setDiff("resolution", "OPEN", "FIXED");
@@ -100,7 +100,7 @@ public class FieldDiffsTest {
}
@Test
- public void test_toString_with_null_values() throws Exception {
+ public void test_toString_with_null_values() {
diffs.setDiff("severity", null, "INFO");
diffs.setDiff("assignee", "user1", null);
@@ -108,9 +108,9 @@ public class FieldDiffsTest {
}
@Test
- public void test_parse() throws Exception {
- diffs = FieldDiffs.parse("severity=BLOCKER|INFO,resolution=OPEN|FIXED");
- assertThat(diffs.diffs()).hasSize(2);
+ public void test_parse() {
+ diffs = FieldDiffs.parse("severity=BLOCKER|INFO,resolution=OPEN|FIXED,donut=|new,acme=old|");
+ assertThat(diffs.diffs()).hasSize(4);
FieldDiffs.Diff diff = diffs.diffs().get("severity");
assertThat(diff.oldValue()).isEqualTo("BLOCKER");
@@ -119,10 +119,18 @@ public class FieldDiffsTest {
diff = diffs.diffs().get("resolution");
assertThat(diff.oldValue()).isEqualTo("OPEN");
assertThat(diff.newValue()).isEqualTo("FIXED");
+
+ diff = diffs.diffs().get("donut");
+ assertThat(diff.oldValue()).isEqualTo("");
+ assertThat(diff.newValue()).isEqualTo("new");
+
+ diff = diffs.diffs().get("acme");
+ assertThat(diff.oldValue()).isEqualTo("old");
+ assertThat(diff.newValue()).isEqualTo("");
}
@Test
- public void test_parse_empty_values() throws Exception {
+ public void test_parse_empty_values() {
diffs = FieldDiffs.parse("severity=INFO,resolution=");
assertThat(diffs.diffs()).hasSize(2);
@@ -136,13 +144,13 @@ public class FieldDiffsTest {
}
@Test
- public void test_parse_null() throws Exception {
+ public void test_parse_null() {
diffs = FieldDiffs.parse(null);
assertThat(diffs.diffs()).isEmpty();
}
@Test
- public void test_parse_empty() throws Exception {
+ public void test_parse_empty() {
diffs = FieldDiffs.parse("");
assertThat(diffs.diffs()).isEmpty();
}