Search in sources :

Example 6 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class SonarExternalAnnotatorTest method createRangeStoredIssue.

private LiveIssue createRangeStoredIssue(int id, int rangeStart, int rangeEnd, String text) {
    Issue issue = SonarLintTestUtils.createIssue(id);
    RangeMarker range = mock(RangeMarker.class);
    when(range.getStartOffset()).thenReturn(rangeStart);
    when(range.getEndOffset()).thenReturn(rangeEnd);
    when(range.isValid()).thenReturn(true);
    when(range.getDocument()).thenReturn(document);
    when(document.getText(any(TextRange.class))).thenReturn(text);
    return new LiveIssue(issue, null, range, Collections.emptyList());
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) TextRange(com.intellij.openapi.util.TextRange) RangeMarker(com.intellij.openapi.editor.RangeMarker)

Example 7 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class LiveIssueCacheTest method error_remove_eldest.

@Test
public void error_remove_eldest() throws IOException {
    doThrow(new IOException()).when(store).save(anyString(), anyCollection());
    LiveIssue issue1 = createTestIssue("r1");
    for (int i = 0; i < LiveIssueCache.MAX_ENTRIES; i++) {
        VirtualFile file = createTestFile("file" + i);
        cache.save(file, Collections.singleton(issue1));
    }
    exception.expect(IllegalStateException.class);
    cache.save(createTestFile("anotherfile"), Collections.singleton(issue1));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class LiveIssueCacheTest method should_flush_if_full.

@Test
public void should_flush_if_full() throws IOException {
    LiveIssue issue1 = createTestIssue("r1");
    VirtualFile file0 = createTestFile("file0");
    cache.save(file0, Collections.singleton(issue1));
    for (int i = 1; i < LiveIssueCache.MAX_ENTRIES; i++) {
        VirtualFile file = createTestFile("file" + i);
        cache.save(file, Collections.singleton(issue1));
    }
    // oldest access should be file1 after this
    assertThat(cache.getLive(file0)).containsOnly(issue1);
    verifyZeroInteractions(store);
    VirtualFile file = createTestFile("anotherfile");
    cache.save(file, Collections.singleton(issue1));
    verify(store).save(eq("file1"), anyCollection());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Test(org.junit.Test)

Example 9 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class LiveIssueCacheTest method should_flush_when_requested.

@Test
public void should_flush_when_requested() throws IOException {
    LiveIssue issue1 = createTestIssue("r1");
    VirtualFile file0 = createTestFile("file0");
    cache.save(file0, Collections.singleton(issue1));
    VirtualFile file1 = createTestFile("file1");
    cache.save(file1, Collections.singleton(issue1));
    cache.flushAll();
    verify(store).save(eq("file0"), anyCollection());
    verify(store).save(eq("file1"), anyCollection());
    verifyNoMoreInteractions(store);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Test(org.junit.Test)

Example 10 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class LiveIssueCacheTest method createTestIssue.

private LiveIssue createTestIssue(String ruleKey) {
    LiveIssue issue = mock(LiveIssue.class);
    when(issue.getRuleKey()).thenReturn(ruleKey);
    when(issue.getAssignee()).thenReturn("assignee");
    when(issue.getRuleName()).thenReturn(ruleKey);
    when(issue.getSeverity()).thenReturn("MAJOR");
    when(issue.getMessage()).thenReturn("msg");
    return issue;
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue)

Aggregations

LiveIssue (org.sonarlint.intellij.issue.LiveIssue)26 Test (org.junit.Test)15 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RangeMarker (com.intellij.openapi.editor.RangeMarker)4 PsiFile (com.intellij.psi.PsiFile)4 CheckinHandler (com.intellij.openapi.vcs.checkin.CheckinHandler)3 AnalysisCallback (org.sonarlint.intellij.analysis.AnalysisCallback)3 IssueNode (org.sonarlint.intellij.ui.nodes.IssueNode)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 UIUtil (com.intellij.util.ui.UIUtil)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 SonarTest (org.sonarlint.intellij.SonarTest)2 IssueManager (org.sonarlint.intellij.issue.IssueManager)2 SonarLintUtils (org.sonarlint.intellij.util.SonarLintUtils)2 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)2 InspectionDescriptionLinkHandler (com.intellij.codeInsight.hint.InspectionDescriptionLinkHandler)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1