33
44package software.aws.toolkits.jetbrains.services.amazonq.webview
55
6- import com.google.gson.Gson
6+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
77import com.intellij.openapi.editor.Document
88import com.intellij.openapi.fileEditor.FileDocumentManager
99import com.intellij.openapi.vfs.LocalFileSystem
@@ -41,31 +41,31 @@ class BrowserConnectorTest : AmazonQTestBase() {
4141 override fun setup () {
4242 super .setup()
4343 fixture = projectRule.fixture
44-
44+
4545 mockCodeScanManager = mock()
4646 mockLocalFileSystem = mock()
4747 mockFileDocumentManager = mock()
48-
48+
4949 project.replaceService(CodeWhispererCodeScanManager ::class .java, mockCodeScanManager, disposableRule.disposable)
50-
50+
5151 browserConnector = spy(BrowserConnector (project = project))
5252 }
5353
5454 @Test
5555 fun `parseFindingsMessages should handle empty additionalMessages` () {
5656 val messagesMap = mapOf<String , Any >()
57-
57+
5858 browserConnector.parseFindingsMessages(messagesMap)
59-
59+
6060 verify(mockCodeScanManager, never()).addOnDemandIssues(any(), any(), any())
6161 }
6262
6363 @Test
6464 fun `parseFindingsMessages should handle null additionalMessages` () {
6565 val messagesMap = mapOf (" additionalMessages" to null )
66-
66+
6767 browserConnector.parseFindingsMessages(messagesMap)
68-
68+
6969 verify(mockCodeScanManager, never()).addOnDemandIssues(any(), any(), any())
7070 }
7171
@@ -81,9 +81,9 @@ class BrowserConnectorTest : AmazonQTestBase() {
8181 )
8282 val additionalMessages = mutableListOf<Map <String , Any >>(findingsMessage, otherMessage)
8383 val messagesMap = mapOf (" additionalMessages" to additionalMessages)
84-
84+
8585 browserConnector.parseFindingsMessages(messagesMap)
86-
86+
8787 assert (additionalMessages.size == 1 )
8888 assert (additionalMessages[0 ] == otherMessage)
8989 }
@@ -96,9 +96,9 @@ class BrowserConnectorTest : AmazonQTestBase() {
9696 )
9797 val additionalMessages = mutableListOf<Map <String , Any >>(findingsMessage)
9898 val messagesMap = mapOf (" additionalMessages" to additionalMessages)
99-
99+
100100 browserConnector.parseFindingsMessages(messagesMap)
101-
101+
102102 assert (additionalMessages.isEmpty())
103103 }
104104
@@ -112,16 +112,16 @@ class BrowserConnectorTest : AmazonQTestBase() {
112112 on { getLineStartOffset(0 ) } doReturn 0
113113 on { getLineEndOffset(0 ) } doReturn 10
114114 }
115-
115+
116116 mockStatic(LocalFileSystem ::class .java).use { localFileSystemMock ->
117117 localFileSystemMock.`when `<LocalFileSystem > { LocalFileSystem .getInstance() }.thenReturn(mockLocalFileSystem)
118118 whenever(mockLocalFileSystem.findFileByIoFile(any())) doReturn mockVirtualFile
119-
119+
120120 mockStatic(FileDocumentManager ::class .java).use { fileDocumentManagerMock ->
121121 fileDocumentManagerMock.`when `<FileDocumentManager > { FileDocumentManager .getInstance() } doReturn mockFileDocumentManager
122122 whenever(mockFileDocumentManager.getDocument(mockVirtualFile)) doReturn mockDocument
123123 whenever(mockCodeScanManager.isIgnoredIssue(any(), any(), any(), any())) doReturn false
124-
124+
125125 val issue = BrowserConnector .FlareCodeScanIssue (
126126 startLine = 1 , endLine = 1 , comment = " Test comment" , title = " Test Issue" ,
127127 description = Description (" Test description" , " Test text" ), detectorId = " test-detector" ,
@@ -132,24 +132,24 @@ class BrowserConnectorTest : AmazonQTestBase() {
132132 scanJobId = " test-job-id" , language = " kotlin" , autoDetected = false ,
133133 filePath = " /test/file.kt" , findingContext = " test context"
134134 )
135-
135+
136136 val aggregatedIssue = BrowserConnector .AggregatedCodeScanIssue (" /test/file.kt" , listOf (issue))
137137 val findingsMessage = mapOf (
138138 " messageId" to " test_codeReviewFindings" ,
139- " body" to Gson ().toJson (listOf (aggregatedIssue))
139+ " body" to jacksonObjectMapper ().writeValueAsString (listOf (aggregatedIssue))
140140 )
141141 val additionalMessages = mutableListOf<Map <String , Any >>(findingsMessage)
142142 val messagesMap = mapOf (" additionalMessages" to additionalMessages)
143-
143+
144144 browserConnector.parseFindingsMessages(messagesMap)
145-
145+
146146 val issuesCaptor = argumentCaptor<List <CodeWhispererCodeScanIssue >>()
147147 verify(mockCodeScanManager).addOnDemandIssues(
148148 issuesCaptor.capture(),
149149 any(),
150150 eq(CodeWhispererConstants .CodeAnalysisScope .AGENTIC )
151151 )
152-
152+
153153 assert (additionalMessages.isEmpty())
154154 assert (issuesCaptor.firstValue.isNotEmpty())
155155 assert (issuesCaptor.firstValue[0 ].title == " Test Issue" )
@@ -160,11 +160,11 @@ class BrowserConnectorTest : AmazonQTestBase() {
160160 @Test
161161 fun `parseFindingsMessages should skip directory files and not populate mappedFindings` () {
162162 val mockDirectoryFile = mock<VirtualFile > { on { isDirectory } doReturn true }
163-
163+
164164 mockStatic(LocalFileSystem ::class .java).use { localFileSystemMock ->
165165 localFileSystemMock.`when `<LocalFileSystem > { LocalFileSystem .getInstance() } doReturn mockLocalFileSystem
166166 whenever(mockLocalFileSystem.findFileByIoFile(any())) doReturn mockDirectoryFile
167-
167+
168168 val issue = BrowserConnector .FlareCodeScanIssue (
169169 startLine = 1 , endLine = 1 , comment = null , title = " Test Issue" ,
170170 description = Description (" Test description" , " Test text" ), detectorId = " test-detector" ,
@@ -174,15 +174,15 @@ class BrowserConnectorTest : AmazonQTestBase() {
174174 scanJobId = " test-job-id" , language = " kotlin" , autoDetected = true ,
175175 filePath = " /test/directory" , findingContext = " test context"
176176 )
177-
177+
178178 val aggregatedIssue = BrowserConnector .AggregatedCodeScanIssue (" /test/directory" , listOf (issue))
179179 val findingsMessage = mapOf (
180180 " messageId" to " test_displayFindings" ,
181- " body" to Gson ().toJson (listOf (aggregatedIssue))
181+ " body" to jacksonObjectMapper ().writeValueAsString (listOf (aggregatedIssue))
182182 )
183183 val additionalMessages = mutableListOf<Map <String , Any >>(findingsMessage)
184184 val messagesMap = mapOf (" additionalMessages" to additionalMessages)
185-
185+
186186 browserConnector.parseFindingsMessages(messagesMap)
187187
188188 val issuesCaptor = argumentCaptor<List <CodeWhispererCodeScanIssue >>()
@@ -205,9 +205,9 @@ class BrowserConnectorTest : AmazonQTestBase() {
205205 )
206206 val additionalMessages = mutableListOf<Map <String , Any >>(findingsMessage)
207207 val messagesMap = mapOf (" additionalMessages" to additionalMessages)
208-
208+
209209 browserConnector.parseFindingsMessages(messagesMap)
210-
210+
211211 assert (additionalMessages.isEmpty())
212212 }
213213}
0 commit comments