-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc48fcc
commit 20bc30c
Showing
2 changed files
with
106 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/kotlin/io/snyk/plugin/analytics/AnalyticsScanListenerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.snyk.plugin.analytics | ||
|
||
import com.intellij.openapi.project.Project | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import io.snyk.plugin.pluginSettings | ||
import io.snyk.plugin.services.SnykApplicationSettingsStateService | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNotNull | ||
import org.apache.commons.lang.SystemUtils | ||
import org.eclipse.lsp4j.services.LanguageServer | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import snyk.pluginInfo | ||
|
||
class AnalyticsScanListenerTest { | ||
private val projectMock: Project = mockk() | ||
private val lsMock: LanguageServer = mockk() | ||
Check warning Code scanning / detekt Property is unused and should be removed. Warning test
Private property lsMock is unused.
|
||
private val settings = SnykApplicationSettingsStateService() | ||
|
||
@Before | ||
fun setUp() { | ||
unmockkAll() | ||
mockkStatic("io.snyk.plugin.UtilsKt") | ||
every { pluginSettings() } returns settings | ||
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" | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
unmockkAll() | ||
} | ||
|
||
@Test | ||
fun testGetScanDone() { | ||
val cut = AnalyticsScanListener(projectMock) | ||
val scanDoneEvent = cut.getScanDoneEvent( | ||
1, | ||
"product", | ||
1, | ||
1, | ||
1, | ||
1 | ||
) | ||
assertEquals("1", scanDoneEvent.data.attributes.durationMs) | ||
assertEquals("product", scanDoneEvent.data.attributes.scanType) | ||
assertEquals(1, scanDoneEvent.data.attributes.uniqueIssueCount.critical) | ||
assertEquals(1, scanDoneEvent.data.attributes.uniqueIssueCount.high) | ||
assertEquals(1, scanDoneEvent.data.attributes.uniqueIssueCount.medium) | ||
assertEquals(1, scanDoneEvent.data.attributes.uniqueIssueCount.low) | ||
|
||
assertEquals("Snyk Intellij Plugin", scanDoneEvent.data.attributes.application) | ||
assertEquals("2.4.61", scanDoneEvent.data.attributes.applicationVersion) | ||
assertEquals("IntelliJ IDEA", scanDoneEvent.data.attributes.integrationEnvironment) | ||
assertEquals("2020.3.2", scanDoneEvent.data.attributes.integrationEnvironmentVersion) | ||
assertEquals(SystemUtils.OS_NAME, scanDoneEvent.data.attributes.os) | ||
assertEquals(SystemUtils.OS_ARCH, scanDoneEvent.data.attributes.arch) | ||
|
||
assertEquals("analytics", scanDoneEvent.data.type) | ||
assertEquals("Scan done", scanDoneEvent.data.attributes.eventType) | ||
assertEquals("Succeeded", scanDoneEvent.data.attributes.status) | ||
assertEquals(settings.userAnonymousId, scanDoneEvent.data.attributes.deviceId) | ||
|
||
assertNotNull(scanDoneEvent.data.attributes.timestampFinished) | ||
} | ||
} |