From a8f27792af5016bf9457fa225d80ef549ebc778f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 15 Apr 2022 16:01:59 +0200 Subject: [PATCH] SLE-521 Fix issue severity when severity is changed on the QP --- .../core/internal/tracking/IssueTrackerTest.java | 12 +++++------- .../core/internal/tracking/PreviousTrackable.java | 12 +++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/org.sonarlint.eclipse.core.tests/src/test/java/org/sonarlint/eclipse/core/internal/tracking/IssueTrackerTest.java b/org.sonarlint.eclipse.core.tests/src/test/java/org/sonarlint/eclipse/core/internal/tracking/IssueTrackerTest.java index 40bb48a70..71ea37a89 100644 --- a/org.sonarlint.eclipse.core.tests/src/test/java/org/sonarlint/eclipse/core/internal/tracking/IssueTrackerTest.java +++ b/org.sonarlint.eclipse.core.tests/src/test/java/org/sonarlint/eclipse/core/internal/tracking/IssueTrackerTest.java @@ -514,14 +514,12 @@ public void should_clear_server_issue_details_if_disappeared() { var serverIssueKey = "dummy serverIssueKey"; var resolved = true; var assignee = "dummy assignee"; - var base = builder().ruleKey("dummy ruleKey").severity("CRITICAL").rawSeverity("CRITICAL"); - - var start = System.currentTimeMillis(); + var base = builder().ruleKey("dummy ruleKey").lineHash(123).severity("CRITICAL").rawSeverity("CRITICAL"); // First analysis cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackAsNew(file1, List.of(base.build()))); cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackServerIssues(file1, - List.of(base.copy().serverIssueKey(serverIssueKey).resolved(true).assignee(assignee).severity("BLOCKER").build()))); + List.of(base.copy().serverIssueKey(serverIssueKey).creationDate(456789L).resolved(true).assignee(assignee).severity("BLOCKER").build()))); // Second analysis with no more issue on server side cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackAsNew(file1, List.of(base.build()))); @@ -529,9 +527,9 @@ public void should_clear_server_issue_details_if_disappeared() { var trackables = cache.getCurrentTrackables(DUMMY_FILE1_PATH); assertThat(trackables) - .extracting("serverIssueKey", "resolved", "assignee", "severity") - .containsExactly(tuple(null, !resolved, "", "CRITICAL")); - assertThat(trackables.iterator().next().getCreationDate()).isGreaterThanOrEqualTo(start); + .extracting("serverIssueKey", "resolved", "assignee", "severity", "creationDate") + // Resolution and severity are reset, but creationDate stay the same + .containsExactly(tuple(null, !resolved, "", "CRITICAL", 456789L)); } @Test diff --git a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/tracking/PreviousTrackable.java b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/tracking/PreviousTrackable.java index 711aa7f23..542dd2f10 100644 --- a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/tracking/PreviousTrackable.java +++ b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/tracking/PreviousTrackable.java @@ -19,8 +19,6 @@ */ package org.sonarlint.eclipse.core.internal.tracking; -import org.sonarlint.eclipse.core.internal.utils.StringUtils; - /** * Combine a new Trackable ("raw") with a previous state ("base") */ @@ -43,9 +41,13 @@ public PreviousTrackable(Trackable base, Trackable raw) { this.resolved = base.isResolved(); this.assignee = base.getAssignee(); this.markerId = base.getMarkerId(); - // Migration: severity & type were initially not stored in protobuf file - this.severity = StringUtils.isBlank(base.getSeverity()) ? raw.getSeverity() : base.getSeverity(); - this.type = StringUtils.isBlank(base.getType()) ? raw.getType() : base.getType(); + if (base.getServerIssueKey() != null) { + this.severity = base.getSeverity(); + this.type = base.getType(); + } else { + this.severity = raw.getSeverity(); + this.type = raw.getType(); + } } @Override