diff --git a/src/main/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandler.java b/src/main/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandler.java index 315154a5c..2050c477d 100644 --- a/src/main/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandler.java +++ b/src/main/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandler.java @@ -20,6 +20,7 @@ package org.sonarlint.intellij.trigger; import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.UnnamedConfigurable; import com.intellij.openapi.progress.ProgressIndicator; @@ -241,7 +242,11 @@ private ReturnResult showYesNoCancel(String resultStr) { } private void showChangedFilesTab(AnalysisResult analysisResult) { - runOnUiThread(project, () -> getService(project, SonarLintToolWindow.class).openReportTab(analysisResult)); + if (ApplicationManager.getApplication().isUnitTestMode()) { + getService(project, SonarLintToolWindow.class).openReportTab(analysisResult); + } else { + runOnUiThread(project, () -> getService(project, SonarLintToolWindow.class).openReportTab(analysisResult)); + } } private class MyRefreshableOnComponent implements RefreshableOnComponent, UnnamedConfigurable { diff --git a/src/test/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandlerTests.java b/src/test/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandlerTests.java index 154b1ceed..e34e02d72 100644 --- a/src/test/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandlerTests.java +++ b/src/test/java/org/sonarlint/intellij/trigger/SonarLintCheckinHandlerTests.java @@ -118,7 +118,7 @@ void testIssues() { assertThat(result).isEqualTo(CheckinHandler.ReturnResult.CLOSE_WINDOW); assertThat(messages).containsExactly("SonarLint analysis on 1 file found 1 issue"); ArgumentCaptor analysisResultCaptor = ArgumentCaptor.forClass(AnalysisResult.class); - verify(toolWindow).openReportTab(analysisResultCaptor.capture()); + verify(toolWindow, timeout(1000)).openReportTab(analysisResultCaptor.capture()); var analysisResult = analysisResultCaptor.getValue(); assertThat(analysisResult.getFindings().getIssuesPerFile()).containsEntry(file, Set.of(issue)); verify(analysisSubmitter, timeout(1000)).analyzeFilesPreCommit(Collections.singleton(file)); @@ -152,7 +152,7 @@ void testSecretsIssues() { "\n" + "SonarLint analysis found 1 secret. Committed secrets may lead to unauthorized system access."); ArgumentCaptor analysisResultCaptor = ArgumentCaptor.forClass(AnalysisResult.class); - verify(toolWindow).openReportTab(analysisResultCaptor.capture()); + verify(toolWindow, timeout(1000)).openReportTab(analysisResultCaptor.capture()); var analysisResult = analysisResultCaptor.getValue(); assertThat(analysisResult.getFindings().getIssuesPerFile()).containsEntry(file, Set.of(issue)); verify(analysisSubmitter, timeout(1000)).analyzeFilesPreCommit(Collections.singleton(file));