@@ -32,6 +32,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.refreshToke
3232import software.aws.toolkits.jetbrains.services.codemodernizer.utils.validateSctMetadata
3333import software.aws.toolkits.jetbrains.utils.notifyStickyWarn
3434import software.aws.toolkits.jetbrains.utils.rules.addFileToModule
35+ import software.aws.toolkits.resources.message
3536import java.util.concurrent.atomic.AtomicBoolean
3637import kotlin.io.path.createTempFile
3738
@@ -120,17 +121,23 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase
120121
121122 @Test
122123 fun `show re-auth notification on invalid grant exception` () {
124+ val mockInvalidGrantException = Mockito .mock(InvalidGrantException ::class .java)
125+
123126 mockkStatic(::notifyStickyWarn)
127+ every { notifyStickyWarn(any(), any(), any(), any(), any()) } just runs
124128
125- val mockMessageListener = mockk<CodeTransformMessageListener >()
126- mockkObject(CodeTransformMessageListener )
127- every { CodeTransformMessageListener .instance } returns mockMessageListener
128- every { mockMessageListener.onCheckAuth() } just runs
129+ Mockito .doThrow(
130+ mockInvalidGrantException
131+ ).doReturn(
132+ exampleGetCodeMigrationResponse,
133+ exampleGetCodeMigrationResponse.replace(TransformationStatus .STARTED ),
134+ exampleGetCodeMigrationResponse.replace(TransformationStatus .COMPLETED ),
135+ ).whenever(clientAdaptorSpy).getCodeModernizationJob(any())
129136
130- val mockInvalidGrantException = Mockito .mock(InvalidGrantException ::class .java)
131- Mockito .doThrow(mockInvalidGrantException)
132- .whenever(clientAdaptorSpy).getCodeModernizationJob(any())
137+ Mockito .doReturn(exampleGetCodeMigrationPlanResponse)
138+ .whenever(clientAdaptorSpy).getCodeModernizationPlan(any())
133139
140+ val mutableList = mutableListOf<TransformationStatus >()
134141 runBlocking {
135142 jobId.pollTransformationStatusAndPlan(
136143 CodeTransformType .LANGUAGE_UPGRADE ,
@@ -141,18 +148,17 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase
141148 0 ,
142149 AtomicBoolean (false ),
143150 project
144- ) { _, _, _ -> }
151+ ) { _, status, _ ->
152+ mutableList.add(status)
153+ }
145154 }
146-
147- verify {
148- notifyStickyWarn(
149- " Your connection to Q has expired" ,
150- " Unable to check transformation status as your credentials expired." ,
151- project,
152- any()
155+ val expected =
156+ listOf<TransformationStatus >(
157+ exampleGetCodeMigrationResponse.transformationJob().status(),
158+ TransformationStatus .STARTED ,
153159 )
154- }
155- verify { mockMessageListener.onCheckAuth( ) }
160+ assertThat(expected).isEqualTo(mutableList)
161+ verify { notifyStickyWarn(message( " codemodernizer.notification.warn.expired_credentials.title " ), any(), any(), any(), any() ) }
156162 }
157163
158164 @Test
0 commit comments