Skip to content

Commit

Permalink
Stop using deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Nov 6, 2024
1 parent e57ebdb commit 40cad8b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/sonarsource/sonarlint/ls/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
import javax.annotation.CheckForNull;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.IssueFlowDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.QuickFixDto;
import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.RuleType;
import org.sonarsource.sonarlint.core.rpc.protocol.common.Either;
import org.sonarsource.sonarlint.core.rpc.protocol.common.MQRModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.StandardModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.TextRangeDto;

public interface Issue {

UUID getIssueId();

IssueSeverity getSeverity();

RuleType getType();
Either<StandardModeDetails, MQRModeDetails> getSeverityDetails();

String getRuleKey();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import java.util.List;
import java.util.UUID;
import javax.annotation.CheckForNull;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.ImpactDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.IssueFlowDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.QuickFixDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaisedFindingDto;
import org.sonarsource.sonarlint.core.rpc.protocol.common.CleanCodeAttribute;
import org.sonarsource.sonarlint.core.rpc.protocol.common.Either;
import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.MQRModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.RuleType;
import org.sonarsource.sonarlint.core.rpc.protocol.common.StandardModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.TextRangeDto;
import org.sonarsource.sonarlint.ls.Issue;

Expand All @@ -43,37 +44,32 @@ public class DelegatingFinding implements Issue {
protected final RaisedFindingDto finding;
protected boolean isOnNewCode;
protected URI fileUri;
protected Either<StandardModeDetails, MQRModeDetails> severityDetails;

private DelegatingFinding(RaisedFindingDto finding) {
this.issueId = finding.getId();
this.severity = finding.getSeverity();
this.type = finding.getType();
this.severity = finding.getSeverityMode().isLeft() ? finding.getSeverityMode().getLeft().getSeverity() : null;
this.type = finding.getSeverityMode().isLeft() ? finding.getSeverityMode().getLeft().getType() : null;
this.isOnNewCode = finding.isOnNewCode();
this.finding = finding;
this.serverIssueKey = finding.getServerKey();
this.resolved = finding.isResolved();
this.severityDetails = finding.getSeverityMode();
}

public DelegatingFinding(RaisedFindingDto rawFinding, URI fileUri) {
this(rawFinding);
this.fileUri = fileUri;
}

@CheckForNull
public IssueSeverity getSeverity() {
return severity;
return severityDetails.isLeft() ? severityDetails.getLeft().getSeverity() : null;
}

@CheckForNull
public RuleType getType() {
return type;
}

public CleanCodeAttribute getCleanCodeAttribute() {
return finding.getCleanCodeAttribute();
}

public List<ImpactDto> getImpacts() {
return finding.getImpacts();
return severityDetails.isLeft() ? severityDetails.getLeft().getType() : null;
}

@CheckForNull
Expand Down Expand Up @@ -144,6 +140,11 @@ public UUID getIssueId() {
return issueId;
}

@Override
public Either<StandardModeDetails, MQRModeDetails> getSeverityDetails() {
return severityDetails;
}

public boolean isResolved() {
return resolved;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void showQuickFixFromAnalyzerForNotebook() {
when(fix.message()).thenReturn("Fix the issue!");
when(fix.fileEdits()).thenReturn(List.of(edit));
when(issue.getQuickFixes()).thenReturn(List.of(fix));
when(issue.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)));
var rawIssue = mock(DelegatingFinding.class);
when(rawIssue.quickFixes()).thenReturn(List.of(fix));
when(rawIssue.getFinding()).thenReturn(issue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaisedFindingDto;
import org.sonarsource.sonarlint.core.rpc.protocol.common.Either;
import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.RuleType;
import org.sonarsource.sonarlint.core.rpc.protocol.common.StandardModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.TextRangeDto;
import org.sonarsource.sonarlint.ls.connected.DelegatingFinding;
import org.sonarsource.sonarlint.ls.connected.TaintVulnerabilitiesCache;
Expand Down Expand Up @@ -147,7 +150,7 @@ private URI initWithOneSecretIssue() {
var textRange = new TextRangeDto(1, 0, 1, 1);
when(issue.getId()).thenReturn(UUID.randomUUID());
when(issue.getRuleKey()).thenReturn("secrets:123");
when(issue.getSeverity()).thenReturn(IssueSeverity.MAJOR);
when(issue.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)));
when(issue.getPrimaryMessage()).thenReturn("Boo");
when(issue.getTextRange()).thenReturn(textRange);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import org.junit.jupiter.api.Test;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.IssueFlowDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaisedFindingDto;
import org.sonarsource.sonarlint.core.rpc.protocol.common.Either;
import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.RuleType;
import org.sonarsource.sonarlint.core.rpc.protocol.common.StandardModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.TextRangeDto;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -40,7 +43,7 @@ class DelegatingIssueTests {

@BeforeEach
public void prepare() {
when(issue.getSeverity()).thenReturn(IssueSeverity.BLOCKER);
when(issue.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)));
when(issue.getPrimaryMessage()).thenReturn("don't do this");
when(issue.getRuleKey()).thenReturn("squid:123");
when(issue.getTextRange()).thenReturn(textRange);
Expand All @@ -54,20 +57,20 @@ public void prepare() {

@Test
void testGetSeverity() {
assertThat(delegatingFinding.getSeverity()).isEqualTo(issue.getSeverity());
assertThat(delegatingFinding.getSeverity()).isEqualTo(issue.getSeverityMode().getLeft().getSeverity());
}

@Test
void testGetUserSeverity() {
when(issue.getSeverity()).thenReturn(IssueSeverity.INFO);
when(issue.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.INFO, RuleType.BUG)));
var delegatingIssueWithUserSeverity = new DelegatingFinding(issue, URI.create("file:///myFile.py"));

assertThat(delegatingIssueWithUserSeverity.getSeverity()).isEqualTo(IssueSeverity.INFO);
}

@Test
void testGetType() {
assertThat(delegatingFinding.getType()).isEqualTo(issue.getType());
assertThat(delegatingFinding.getType()).isEqualTo(issue.getSeverityMode().getLeft().getType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TaintVulnerabilityDto;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TextRangeWithHashDto;
import org.sonarsource.sonarlint.core.rpc.protocol.common.CleanCodeAttribute;
import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.RuleType;
import org.sonarsource.sonarlint.core.rpc.protocol.common.StandardModeDetails;
import org.sonarsource.sonarlint.ls.domain.TaintIssue;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -64,13 +65,12 @@ void testIssueConversion(String taintSource, boolean isOnNewCode, boolean focusO
var issueId = UUID.randomUUID();
when(issue.getId()).thenReturn(issueId);
when(issue.getTextRange()).thenReturn(new TextRangeWithHashDto(1, 0, 0, 0, ""));
when(issue.getSeverity()).thenReturn(IssueSeverity.BLOCKER);
when(issue.getSeverityMode()).thenReturn(org.sonarsource.sonarlint.core.rpc.protocol.common.Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)));
when(issue.getRuleKey()).thenReturn("ruleKey");
when(issue.getMessage()).thenReturn("message");
when(issue.getSonarServerKey()).thenReturn("issueKey");
when(issue.getFlows()).thenReturn(List.of(flow));
when(issue.getSource()).thenReturn(taintSource);
when(issue.getCleanCodeAttribute()).thenReturn(CleanCodeAttribute.CONVENTIONAL);
when(issue.isOnNewCode()).thenReturn(isOnNewCode);

var diagnostic = convert(issue, focusOnNewCode).get();
Expand Down Expand Up @@ -117,15 +117,15 @@ void testCacheOnlyUnresolvedTaintVulnerabilities() throws Exception {
when(taint.getRuleKey()).thenReturn("key1");
when(taint.getRuleKey()).thenReturn(SAMPLE_SECURITY_RULE_KEY);
when(taint.isResolved()).thenReturn(false);
when(taint.getSeverity()).thenReturn(IssueSeverity.BLOCKER);
when(taint.getSeverityMode()).thenReturn(org.sonarsource.sonarlint.core.rpc.protocol.common.Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.VULNERABILITY)));
when(taint.getTextRange()).thenReturn(new TextRangeWithHashDto(1, 1, 1, 1, ""));
when(taint.getMessage()).thenReturn("Boo");

var resolvedTaint = mock(TaintIssue.class);
when(resolvedTaint.getId()).thenReturn(UUID.randomUUID());
when(resolvedTaint.getRuleKey()).thenReturn(SAMPLE_SECURITY_RULE_KEY);
when(resolvedTaint.isResolved()).thenReturn(true);
when(resolvedTaint.getSeverity()).thenReturn(IssueSeverity.BLOCKER);
when(resolvedTaint.getSeverityMode()).thenReturn(org.sonarsource.sonarlint.core.rpc.protocol.common.Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.VULNERABILITY)));
when(resolvedTaint.getTextRange()).thenReturn(new TextRangeWithHashDto(1, 1, 1, 1, ""));
when(resolvedTaint.getMessage()).thenReturn("Foo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
import org.junit.jupiter.api.Test;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.IssueFlowDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaisedIssueDto;
import org.sonarsource.sonarlint.core.rpc.protocol.common.Either;
import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.RuleType;
import org.sonarsource.sonarlint.core.rpc.protocol.common.StandardModeDetails;
import org.sonarsource.sonarlint.core.rpc.protocol.common.TextRangeDto;
import org.sonarsource.sonarlint.ls.DiagnosticPublisher;
import org.sonarsource.sonarlint.ls.IssuesCache;
Expand Down Expand Up @@ -191,7 +194,7 @@ private DelegatingFinding createFakeBlockerIssue() {
var issue = mock(RaisedIssueDto.class);
TextRangeDto textRangeDto = new TextRangeDto(2, 0, 2, 5);
TextRangeDto textRange = new TextRangeDto(2, 0, 2, 5);
when(issue.getSeverity()).thenReturn(IssueSeverity.BLOCKER);
when(issue.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)));
when(issue.getPrimaryMessage()).thenReturn("don't do this");
when(issue.getRuleKey()).thenReturn("squid:123");
when(issue.getTextRange()).thenReturn(textRangeDto);
Expand All @@ -205,7 +208,7 @@ private DelegatingFinding createFakeMinorIssue() {
TextRangeDto textRangeDto = new TextRangeDto(1, 0, 1, 3);
TextRangeDto textRange = new TextRangeDto(1, 0, 1, 3);

when(issue.getSeverity()).thenReturn(IssueSeverity.MINOR);
when(issue.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.MINOR, RuleType.BUG)));
when(issue.getPrimaryMessage()).thenReturn("don't do this please");
when(issue.getRuleKey()).thenReturn("squid:122");
when(issue.getTextRange()).thenReturn(textRangeDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void shouldConvertToCellIssue() {
private static RaisedFindingDto mockRaisedFinding(@Nullable TextRangeDto textRange) {
RaisedFindingDto raisedFinding = mock(RaisedFindingDto.class);

when(raisedFinding.getSeverity()).thenReturn(IssueSeverity.BLOCKER);
when(raisedFinding.getSeverityMode()).thenReturn(Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)));
when(raisedFinding.getPrimaryMessage()).thenReturn("don't do this");
when(raisedFinding.getRuleKey()).thenReturn("squid:123");
when(raisedFinding.getTextRange()).thenReturn(textRange);
Expand Down

0 comments on commit 40cad8b

Please sign in to comment.