Skip to content

Commit 6dfb39a

Browse files
fix: test and visibility
1 parent 9756541 commit 6dfb39a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/main/kotlin/io/snyk/plugin/services/download/CliDownloaderService.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import java.time.LocalDate
1616
import java.time.temporal.ChronoUnit
1717
import java.util.Date
1818

19+
@Suppress("MemberVisibilityCanBePrivate")
1920
@Service
2021
class SnykCliDownloaderService {
2122

@@ -129,13 +130,13 @@ class SnykCliDownloaderService {
129130
return pluginSettings().currentLSProtocolVersion == pluginSettings().requiredLsProtocolVersion
130131
}
131132

132-
private fun isFourDaysPassedSinceLastCheck(): Boolean {
133+
fun isFourDaysPassedSinceLastCheck(): Boolean {
133134
val previousDate = pluginSettings().getLastCheckDate() ?: return true
134135

135136
return ChronoUnit.DAYS.between(previousDate, LocalDate.now()) >= NUMBER_OF_DAYS_BETWEEN_RELEASE_CHECK
136137
}
137138

138-
private fun isNewVersionAvailable(currentCliVersion: String?, newCliVersion: String?): Boolean {
139+
fun isNewVersionAvailable(currentCliVersion: String?, newCliVersion: String?): Boolean {
139140
val cliVersionsNullOrEmpty =
140141
currentCliVersion == null || newCliVersion == null ||
141142
currentCliVersion.isEmpty() || newCliVersion.isEmpty()

src/test/kotlin/io/snyk/plugin/analytics/AnalyticsScanListenerTest.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.snyk.plugin.analytics
22

3+
import com.intellij.openapi.application.Application
4+
import com.intellij.openapi.application.ApplicationManager
35
import com.intellij.openapi.project.Project
46
import com.intellij.openapi.vfs.VirtualFile
57
import io.mockk.every
@@ -14,6 +16,7 @@ import io.snyk.plugin.getOS
1416
import io.snyk.plugin.pluginSettings
1517
import io.snyk.plugin.services.SnykApplicationSettingsStateService
1618
import io.snyk.plugin.toVirtualFile
19+
import io.snyk.plugin.ui.toolwindow.SnykPluginDisposable
1720
import junit.framework.TestCase.assertEquals
1821
import junit.framework.TestCase.assertNotNull
1922
import org.junit.After
@@ -29,16 +32,22 @@ class AnalyticsScanListenerTest {
2932
private val projectMock: Project = mockk()
3033
private val settings = SnykApplicationSettingsStateService()
3134
private val languageServerWrapper: LanguageServerWrapper = mockk()
35+
private val applicationMock: Application = mockk(relaxed = true)
3236

3337
@Before
3438
fun setUp() {
3539
unmockkAll()
3640

41+
mockkStatic(ApplicationManager::class)
42+
every { ApplicationManager.getApplication() } returns applicationMock
43+
every { applicationMock.getService(SnykPluginDisposable::class.java) } returns mockk(relaxed = true)
44+
3745
mockkStatic("io.snyk.plugin.UtilsKt")
3846
every { pluginSettings() } returns settings
3947

4048
mockkObject(LanguageServerWrapper.Companion)
4149
every { LanguageServerWrapper.getInstance() } returns languageServerWrapper
50+
every { languageServerWrapper.notAuthenticated() } returns false
4251
justRun { languageServerWrapper.sendReportAnalyticsCommand(any()) }
4352

4453
mockkStatic("snyk.PluginInformationKt")
@@ -104,6 +113,6 @@ class AnalyticsScanListenerTest {
104113
fun `testScanListener scanningContainerFinished should call language server to report analytics`() {
105114
cut.snykScanListener.scanningContainerFinished(mockk(relaxed = true))
106115

107-
verify { languageServerWrapper.sendReportAnalyticsCommand(any()) }
116+
verify(timeout = 3000) { languageServerWrapper.sendReportAnalyticsCommand(any()) }
108117
}
109118
}

0 commit comments

Comments
 (0)