]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18267 Fix duplicate issue changes
authorEric Giffon <eric.giffon@sonarsource.com>
Tue, 28 Feb 2023 09:45:39 +0000 (10:45 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 28 Feb 2023 20:03:06 +0000 (20:03 +0000)
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java

index 931746fa44f6ca7c847f5e0b73702cbc9ad81eb7..08b92350a10964e31d4f86c48856fe1d79b499a0 100644 (file)
@@ -503,10 +503,10 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
         currentChange.setCreationDate(context.date());
         currentChange.setWebhookSource(context.getWebhookSource());
         currentChange.setExternalUser(context.getExternalUser());
+        addChange(currentChange);
       }
       currentChange.setDiff(field, oldValue, newValue);
     }
-    addChange(currentChange);
     return this;
   }
 
index f295cdf7cc68156fc3f111750c27b55b6891a8db..763be4b20add783117c8adeafd74ab6b46be6ec2 100644 (file)
@@ -206,6 +206,25 @@ public class DefaultIssueTest {
     assertThat(actualDiffs.webhookSource()).contains(issueChangeContext.getWebhookSource());
   }
 
+  @Test
+  public void setFieldChange_whenAddingChange_shouldUpdateCurrentChange() {
+    IssueChangeContext issueChangeContext = mock(IssueChangeContext.class);
+    DefaultIssue issue = new DefaultIssue().setKey("AAA");
+
+    issue.setFieldChange(issueChangeContext, "actionPlan", "1.0", "1.1");
+    assertThat(issue.changes()).hasSize(1);
+    FieldDiffs currentChange = issue.currentChange();
+    assertThat(currentChange).isNotNull();
+    assertThat(currentChange.get("actionPlan")).isNotNull();
+    assertThat(currentChange.get("authorLogin")).isNull();
+
+    issue.setFieldChange(issueChangeContext, "authorLogin", null, "testuser");
+    assertThat(issue.changes()).hasSize(1);
+    assertThat(currentChange.get("actionPlan")).isNotNull();
+    assertThat(currentChange.get("authorLogin")).isNotNull();
+    assertThat(currentChange.get("authorLogin").newValue()).isEqualTo("testuser");
+  }
+
   @Test
   public void adding_null_change_has_no_effect() {
     DefaultIssue issue = new DefaultIssue();