@@ -31,10 +31,13 @@ import org.eclipse.lsp4j.CreateFilesParams
31
31
import org.eclipse.lsp4j.DeleteFilesParams
32
32
import org.eclipse.lsp4j.DidChangeWatchedFilesParams
33
33
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams
34
+ import org.eclipse.lsp4j.DidCloseTextDocumentParams
35
+ import org.eclipse.lsp4j.DidOpenTextDocumentParams
34
36
import org.eclipse.lsp4j.FileChangeType
35
37
import org.eclipse.lsp4j.RenameFilesParams
36
38
import org.eclipse.lsp4j.WorkspaceFolder
37
39
import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage
40
+ import org.eclipse.lsp4j.services.TextDocumentService
38
41
import org.eclipse.lsp4j.services.WorkspaceService
39
42
import org.junit.jupiter.api.BeforeEach
40
43
import org.junit.jupiter.api.Test
@@ -50,13 +53,15 @@ class WorkspaceServiceHandlerTest {
50
53
private lateinit var project: Project
51
54
private lateinit var mockLanguageServer: AmazonQLanguageServer
52
55
private lateinit var mockWorkspaceService: WorkspaceService
56
+ private lateinit var mockTextDocumentService: TextDocumentService
53
57
private lateinit var sut: WorkspaceServiceHandler
54
58
private lateinit var mockApplication: Application
55
59
56
60
@BeforeEach
57
61
fun setup () {
58
62
project = mockk<Project >()
59
63
mockWorkspaceService = mockk<WorkspaceService >()
64
+ mockTextDocumentService = mockk<TextDocumentService >()
60
65
mockLanguageServer = mockk<AmazonQLanguageServer >()
61
66
62
67
mockApplication = mockk<Application >()
@@ -89,6 +94,11 @@ class WorkspaceServiceHandlerTest {
89
94
every { mockWorkspaceService.didChangeWatchedFiles(any()) } returns Unit
90
95
every { mockWorkspaceService.didChangeWorkspaceFolders(any()) } returns Unit
91
96
97
+ // Mock textDocument service (for didRename calls)
98
+ every { mockLanguageServer.textDocumentService } returns mockTextDocumentService
99
+ every { mockTextDocumentService.didOpen(any()) } returns Unit
100
+ every { mockTextDocumentService.didClose(any()) } returns Unit
101
+
92
102
// Mock message bus
93
103
val messageBus = mockk<MessageBus >()
94
104
every { project.messageBus } returns messageBus
@@ -389,6 +399,15 @@ class WorkspaceServiceHandlerTest {
389
399
// Act
390
400
sut.after(listOf (propertyEvent))
391
401
402
+ val closeParams = slot<DidCloseTextDocumentParams >()
403
+ verify { mockTextDocumentService.didClose(capture(closeParams)) }
404
+ assertThat(closeParams.captured.textDocument.uri).isEqualTo(normalizeFileUri(" file:///testDir/$oldName " ))
405
+
406
+ val openParams = slot<DidOpenTextDocumentParams >()
407
+ verify { mockTextDocumentService.didOpen(capture(openParams)) }
408
+ assertThat(openParams.captured.textDocument.uri).isEqualTo(normalizeFileUri(" file:///testDir/$newName " ))
409
+ assertThat(openParams.captured.textDocument.text).isEqualTo(normalizeFileUri(" content" ))
410
+
392
411
// Assert
393
412
val paramsSlot = slot<RenameFilesParams >()
394
413
verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
@@ -411,6 +430,8 @@ class WorkspaceServiceHandlerTest {
411
430
sut.after(listOf (propertyEvent))
412
431
413
432
// Assert
433
+ verify(exactly = 0 ) { mockTextDocumentService.didClose(any()) }
434
+ verify(exactly = 0 ) { mockTextDocumentService.didOpen(any()) }
414
435
verify(exactly = 0 ) { mockWorkspaceService.didRenameFiles(any()) }
415
436
}
416
437
@@ -427,6 +448,8 @@ class WorkspaceServiceHandlerTest {
427
448
sut.after(listOf (propertyEvent))
428
449
429
450
// Assert
451
+ verify(exactly = 0 ) { mockTextDocumentService.didClose(any()) }
452
+ verify(exactly = 0 ) { mockTextDocumentService.didOpen(any()) }
430
453
val paramsSlot = slot<RenameFilesParams >()
431
454
verify { mockWorkspaceService.didRenameFiles(capture(paramsSlot)) }
432
455
with (paramsSlot.captured.files[0 ]) {
@@ -624,6 +647,7 @@ class WorkspaceServiceHandlerTest {
624
647
every { fileSystem } returns mockk {
625
648
every { protocol } returns " file"
626
649
}
650
+ every { this @mockk.inputStream } returns " content" .byteInputStream()
627
651
}
628
652
}
629
653
0 commit comments