diff options
author | Belen Pruvost <belen.pruvost@sonarsource.com> | 2022-03-29 10:40:53 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-03-31 20:02:59 +0000 |
commit | 5db8293aeefbd683b9288bbc5d0dee5d9e407546 (patch) | |
tree | 594fbd37e54080f17fbef1d5740cba2192e89f87 /sonar-core | |
parent | b7df67a2d8bed8bd01baf11368b26ac417a2868b (diff) | |
download | sonarqube-5db8293aeefbd683b9288bbc5d0dee5d9e407546.tar.gz sonarqube-5db8293aeefbd683b9288bbc5d0dee5d9e407546.zip |
SONAR-16039 - Migrate existing issues to new_code table
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java | 18 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java | 57 |
2 files changed, 59 insertions, 16 deletions
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 198bc25d418..b5d3a21c7ba 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 @@ -98,9 +98,6 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. // true if the issue did not exist in the previous scan. private boolean isNew = true; - // true if the issue is on a branch using the reference branch new code strategy - private boolean isOnReferencedBranch = false; - // true if the issue is on a changed line on a branch using the reference branch new code strategy private boolean isOnChangedLine = false; @@ -396,10 +393,6 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return isNew; } - public boolean isOnReferencedBranch() { - return isOnReferencedBranch; - } - public boolean isOnChangedLine() { return isOnChangedLine; } @@ -419,11 +412,6 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } - public DefaultIssue setIsOnReferencedBranch(boolean b) { - isOnReferencedBranch = b; - return this; - } - public DefaultIssue setIsOnChangedLine(boolean b) { isOnChangedLine = b; return this; @@ -554,6 +542,12 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + // true if the issue is new on a reference branch, + // but it's not persisted as such due to being created before the SQ 9.3 migration + public boolean isToBeMigratedAsNewCodeReferenceIssue() { + return isOnChangedLine && !isNewCodeReferenceIssue && !isNoLongerNewCodeReferenceIssue; + } + @CheckForNull public FieldDiffs currentChange() { return currentChange; 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 97797a5a496..53d866457c0 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 @@ -19,7 +19,6 @@ */ package org.sonar.core.issue; -import com.google.common.collect.ImmutableMap; import java.text.SimpleDateFormat; import java.util.List; import org.apache.commons.lang.StringUtils; @@ -29,7 +28,6 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.Duration; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -56,7 +54,6 @@ public class DefaultIssueTest { .setAuthorLogin("steph") .setChecksum("c7b5db46591806455cf082bb348631e8") .setNew(true) - .setIsOnReferencedBranch(true) .setIsOnChangedLine(true) .setIsNewCodeReferenceIssue(true) .setIsNoLongerNewCodeReferenceIssue(true) @@ -87,10 +84,10 @@ public class DefaultIssueTest { assertThat(issue.authorLogin()).isEqualTo("steph"); assertThat(issue.checksum()).isEqualTo("c7b5db46591806455cf082bb348631e8"); assertThat(issue.isNew()).isTrue(); - assertThat(issue.isOnReferencedBranch()).isTrue(); assertThat(issue.isOnChangedLine()).isTrue(); assertThat(issue.isNewCodeReferenceIssue()).isTrue(); assertThat(issue.isNoLongerNewCodeReferenceIssue()).isTrue(); + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); assertThat(issue.isCopied()).isTrue(); assertThat(issue.isBeingClosed()).isTrue(); assertThat(issue.isOnDisabledRule()).isTrue(); @@ -209,6 +206,58 @@ public class DefaultIssueTest { } @Test + public void test_isToBeMigratedAsNewCodeReferenceIssue_is_correctly_calculated() { + issue.setKey("ABCD") + .setIsOnChangedLine(true) + .setIsNewCodeReferenceIssue(false) + .setIsNoLongerNewCodeReferenceIssue(false); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isTrue(); + + issue.setKey("ABCD") + .setIsOnChangedLine(false) + .setIsNewCodeReferenceIssue(false) + .setIsNoLongerNewCodeReferenceIssue(false); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); + + issue.setKey("ABCD") + .setIsOnChangedLine(true) + .setIsNewCodeReferenceIssue(true) + .setIsNoLongerNewCodeReferenceIssue(false); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); + + issue.setKey("ABCD") + .setIsOnChangedLine(false) + .setIsNewCodeReferenceIssue(false) + .setIsNoLongerNewCodeReferenceIssue(true); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); + + issue.setKey("ABCD") + .setIsOnChangedLine(true) + .setIsNewCodeReferenceIssue(true) + .setIsNoLongerNewCodeReferenceIssue(true); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); + + issue.setKey("ABCD") + .setIsOnChangedLine(false) + .setIsNewCodeReferenceIssue(true) + .setIsNoLongerNewCodeReferenceIssue(true); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); + + issue.setKey("ABCD") + .setIsOnChangedLine(true) + .setIsNewCodeReferenceIssue(false) + .setIsNoLongerNewCodeReferenceIssue(true); + + assertThat(issue.isToBeMigratedAsNewCodeReferenceIssue()).isFalse(); + } + + @Test public void isQuickFixAvailable_givenQuickFixAvailable_returnTrue() { DefaultIssue defaultIssue = new DefaultIssue(); |