From ba0aca8277e513e0e7ac1d9a2d683319d8a3f803 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Mon, 5 Feb 2024 20:03:59 -0600 Subject: [PATCH] fix:improve tests --- .../ghmanager/data/WorkflowDataContextService.kt | 2 +- .../ghmanager/TestWindowTabController.kt | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt index 05a10213..22ffa548 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt @@ -92,7 +92,7 @@ class WorkflowDataContextService(project: Project) { settingsService.state.apiToken } - val requestExecutor = GithubApiRequestExecutor.Factory.Companion.getInstance().create(token) + val requestExecutor = GithubApiRequestExecutor.Factory.Companion.getInstance().create(token=token) val singleRunDataLoader = SingleRunDataLoader(requestExecutor) requestExecutor.addListener(singleRunDataLoader) { singleRunDataLoader.invalidateAllData() diff --git a/src/test/kotlin/com/dsoftware/ghmanager/TestWindowTabController.kt b/src/test/kotlin/com/dsoftware/ghmanager/TestWindowTabController.kt index a5be5b03..3fa942f1 100644 --- a/src/test/kotlin/com/dsoftware/ghmanager/TestWindowTabController.kt +++ b/src/test/kotlin/com/dsoftware/ghmanager/TestWindowTabController.kt @@ -11,6 +11,7 @@ import io.mockk.every import io.mockk.mockk import io.mockk.mockkObject import io.mockk.mockkStatic +import io.mockk.verify import junit.framework.TestCase import org.jetbrains.plugins.github.api.GithubApiRequest import org.jetbrains.plugins.github.api.GithubApiRequestExecutor @@ -28,6 +29,11 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() { mockGhActionsService(setOf("http://github.com/owner/repo"), setOf("account1")) mockkStatic(GHCompatibilityUtil::class) every { GHCompatibilityUtil.getOrRequestToken(any(), any()) } returns "token" + executorMock = mockk(relaxed = true) {} + mockkObject(GithubApiRequestExecutor.Factory) + every { GithubApiRequestExecutor.Factory.getInstance() } returns mockk { + every { create(token = any()) } returns executorMock + } workflowDataContextService = project.service() factory.init(toolWindow) executeSomeCoroutineTasksAndDispatchAllInvocationEvents(project) @@ -48,6 +54,9 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() { val workflowRunSelectionContext: WorkflowRunSelectionContext = workflowDataContextService.repositories.values.first().value.get() TestCase.assertEquals(0, workflowRunSelectionContext.runsListModel.size) + verify { + executorMock.execute(any(), ofType(GithubApiRequest::class)) + } } private fun mockGithubApiRequestExecutor( @@ -69,7 +78,7 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() { branch }) val workflowTypesResponse = WorkflowTypes(workflowTypes.size, workflowTypes.toList()) - executorMock = mockk(relaxed = true) { + executorMock.apply { every { execute(any(), any>()) } returns WorkflowRuns(workflowRunsList.size, workflowRunsList.toList()) @@ -83,9 +92,6 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() { execute(any(), any>()) } returns workflowTypesResponse } - mockkObject(GithubApiRequestExecutor.Factory) - every { GithubApiRequestExecutor.Factory.getInstance() } returns mockk { - every { create(token = any()) } returns executorMock - } + } } \ No newline at end of file