diff --git a/src/test/kotlin/io/snyk/plugin/analytics/AnalyticsScanListenerTest.kt b/src/test/kotlin/io/snyk/plugin/analytics/AnalyticsScanListenerTest.kt index e894ddce1..2fd915b34 100644 --- a/src/test/kotlin/io/snyk/plugin/analytics/AnalyticsScanListenerTest.kt +++ b/src/test/kotlin/io/snyk/plugin/analytics/AnalyticsScanListenerTest.kt @@ -2,7 +2,9 @@ package io.snyk.plugin.analytics import com.intellij.openapi.project.Project import io.mockk.every +import io.mockk.justRun import io.mockk.mockk +import io.mockk.mockkObject import io.mockk.mockkStatic import io.mockk.unmockkAll import io.mockk.verify @@ -13,32 +15,36 @@ import io.snyk.plugin.services.SnykApplicationSettingsStateService import io.snyk.plugin.services.SnykTaskQueueService import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNotNull -import org.eclipse.lsp4j.ExecuteCommandParams -import org.eclipse.lsp4j.services.LanguageServer import org.junit.After import org.junit.Before import org.junit.Test import snyk.common.lsp.LanguageServerWrapper import snyk.pluginInfo -import java.util.concurrent.CompletableFuture class AnalyticsScanListenerTest { private lateinit var cut: AnalyticsScanListener private val projectMock: Project = mockk() - private val lsMock: LanguageServer = mockk() private val settings = SnykApplicationSettingsStateService() + private val languageServerWrapper: LanguageServerWrapper = mockk() @Before fun setUp() { unmockkAll() + mockkStatic("io.snyk.plugin.UtilsKt") every { pluginSettings() } returns settings + + mockkObject(SnykTaskQueueService.Companion) + every { SnykTaskQueueService.ls } returns languageServerWrapper + justRun { languageServerWrapper.sendReportAnalyticsCommand(any()) } + mockkStatic("snyk.PluginInformationKt") every { pluginInfo } returns mockk(relaxed = true) every { pluginInfo.integrationName } returns "Snyk Intellij Plugin" every { pluginInfo.integrationVersion } returns "2.4.61" every { pluginInfo.integrationEnvironment } returns "IntelliJ IDEA" every { pluginInfo.integrationEnvironmentVersion } returns "2020.3.2" + cut = AnalyticsScanListener(projectMock) } @@ -81,57 +87,29 @@ class AnalyticsScanListenerTest { @Test fun `testScanListener scanningIacFinished should call language server to report analytics`() { - val languageServerWrapper = LanguageServerWrapper("dummy") - languageServerWrapper.languageServer = lsMock - every { SnykTaskQueueService?.ls } returns languageServerWrapper - every { - lsMock.workspaceService.executeCommand(any()) - } returns CompletableFuture.completedFuture(null) - cut.snykScanListener.scanningIacFinished(mockk(relaxed = true)) - verify { lsMock.workspaceService.executeCommand(any()) } + verify { languageServerWrapper.sendReportAnalyticsCommand(any()) } } @Test fun `testScanListener scanningOssFinished should call language server to report analytics`() { - val languageServerWrapper = LanguageServerWrapper("dummy") - languageServerWrapper.languageServer = lsMock - every { SnykTaskQueueService?.ls } returns languageServerWrapper - every { - lsMock.workspaceService.executeCommand(any()) - } returns CompletableFuture.completedFuture(null) - cut.snykScanListener.scanningOssFinished(mockk(relaxed = true)) - verify { lsMock.workspaceService.executeCommand(any()) } + verify { languageServerWrapper.sendReportAnalyticsCommand(any()) } } @Test fun `testScanListener scanningCodeFinished should call language server to report analytics`() { - val languageServerWrapper = LanguageServerWrapper("dummy") - languageServerWrapper.languageServer = lsMock - every { SnykTaskQueueService?.ls } returns languageServerWrapper - every { - lsMock.workspaceService.executeCommand(any()) - } returns CompletableFuture.completedFuture(null) - cut.snykScanListener.scanningSnykCodeFinished(mockk(relaxed = true)) - verify { lsMock.workspaceService.executeCommand(any()) } + verify { languageServerWrapper.sendReportAnalyticsCommand(any()) } } @Test fun `testScanListener scanningContainerFinished should call language server to report analytics`() { - val languageServerWrapper = LanguageServerWrapper("dummy") - languageServerWrapper.languageServer = lsMock - every { SnykTaskQueueService?.ls } returns languageServerWrapper - every { - lsMock.workspaceService.executeCommand(any()) - } returns CompletableFuture.completedFuture(null) - cut.snykScanListener.scanningContainerFinished(mockk(relaxed = true)) - verify { lsMock.workspaceService.executeCommand(any()) } + verify { languageServerWrapper.sendReportAnalyticsCommand(any()) } } } diff --git a/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt b/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt index 24f87972f..b756d1ff3 100644 --- a/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt +++ b/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt @@ -37,7 +37,6 @@ import snyk.oss.OssService import snyk.trust.confirmScanningAndSetWorkspaceTrustedStateIfNeeded import java.util.concurrent.TimeUnit -@Suppress("FunctionName") class SnykTaskQueueServiceTest : LightPlatformTestCase() { private lateinit var ossServiceMock: OssService