From: Eric Giffon Date: Tue, 28 Feb 2023 09:45:39 +0000 (+0100) Subject: SONAR-18267 Fix duplicate issue changes X-Git-Tag: 10.0.0.68432~188 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d088cb12d8c61d794e809c6151c3cb2c9ca75f0f;p=sonarqube.git SONAR-18267 Fix duplicate issue changes --- diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index 931746fa44f..08b92350a10 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -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; } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java index f295cdf7cc6..763be4b20ad 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java @@ -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();