-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLLS-281 distinguish added and modified files
- Loading branch information
1 parent
51d86ce
commit 12f9c09
Showing
7 changed files
with
106 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/test/java/org/sonarsource/sonarlint/ls/folders/ModuleEventsProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.sonarsource.sonarlint.ls.folders; | ||
|
||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.sonarsource.sonarlint.core.rpc.protocol.common.Language; | ||
import org.sonarsource.sonarlint.ls.backend.BackendServiceFacade; | ||
import org.sonarsource.sonarlint.ls.file.FileTypeClassifier; | ||
import org.sonarsource.sonarlint.ls.file.VersionedOpenFile; | ||
import org.sonarsource.sonarlint.ls.java.JavaConfigCache; | ||
import org.sonarsource.sonarlint.ls.settings.SettingsManager; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ModuleEventsProcessorTest { | ||
ModuleEventsProcessor moduleEventsProcessor; | ||
WorkspaceFoldersManager workspaceFoldersManager = mock(WorkspaceFoldersManager.class); | ||
FileTypeClassifier fileTypeClassifier = mock(FileTypeClassifier.class); | ||
JavaConfigCache javaConfigCache = mock(JavaConfigCache.class); | ||
BackendServiceFacade backendServiceFacade = mock(BackendServiceFacade.class); | ||
SettingsManager settingsManager = mock(SettingsManager.class); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
moduleEventsProcessor = new ModuleEventsProcessor(workspaceFoldersManager, fileTypeClassifier, javaConfigCache, backendServiceFacade, settingsManager); | ||
} | ||
|
||
@Test | ||
void should_get_client_file_dto_outside_workspace_folder() { | ||
var content = "print('Hello, World!')"; | ||
var testFile1 = new VersionedOpenFile(URI.create("file:///tmp/test.py"), "python", 1, content); | ||
|
||
var clientFileDto = moduleEventsProcessor.getClientFileDto(testFile1); | ||
|
||
assertThat(clientFileDto).isNotNull(); | ||
assertThat(clientFileDto.getDetectedLanguage()).isEqualTo(Language.PYTHON); | ||
assertThat(clientFileDto.getContent()).isEqualTo(content); | ||
assertThat(clientFileDto.getConfigScopeId()).isEqualTo(BackendServiceFacade.ROOT_CONFIGURATION_SCOPE); | ||
assertThat(clientFileDto.getUri()).hasToString(testFile1.getUri().toString()); | ||
assertThat(clientFileDto.getCharset()).isEqualTo(StandardCharsets.UTF_8.name()); | ||
} | ||
|
||
@Test | ||
void should_get_client_file_dto_inside_workspace_folder() { | ||
var content = "print('Hello, World!')"; | ||
var fileUri = URI.create("file:///tmp/test.py"); | ||
var mockFolder = mock(WorkspaceFolderWrapper.class); | ||
when(workspaceFoldersManager.findFolderForFile(fileUri)).thenReturn(Optional.of(mockFolder)); | ||
when(mockFolder.getRootPath()).thenReturn(Path.of(URI.create("file:///tmp/").getPath())); | ||
when(mockFolder.getUri()).thenReturn(URI.create("file:///tmp/")); | ||
when(mockFolder.getSettings()).thenReturn(null); | ||
var testFile1 = new VersionedOpenFile(fileUri, "python", 1, content); | ||
|
||
var clientFileDto = moduleEventsProcessor.getClientFileDto(testFile1); | ||
|
||
assertThat(clientFileDto).isNotNull(); | ||
assertThat(clientFileDto.getDetectedLanguage()).isEqualTo(Language.PYTHON); | ||
assertThat(clientFileDto.getContent()).isEqualTo(content); | ||
assertThat(clientFileDto.getConfigScopeId()).isEqualTo("file:///tmp/"); | ||
assertThat(clientFileDto.getUri()).hasToString(testFile1.getUri().toString()); | ||
assertThat(clientFileDto.getCharset()).isEqualTo(StandardCharsets.UTF_8.name()); | ||
} | ||
} |