From 11a9bf1ee41fe31ae2819e7c42a5d920f2832d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kroi=C3=9F=2C=20Florian?= Date: Sun, 1 Mar 2026 14:14:00 +0100 Subject: [PATCH] refactor: directly use Path in test instead of converting to File first --- .../eclipse/lsp4e/test/outline/OutlineContentTest.java | 4 ++-- .../lsp4e/test/outline/OutlineViewerInputTest.java | 2 +- .../src/org/eclipse/lsp4e/test/utils/TestUtils.java | 9 ++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineContentTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineContentTest.java index a03e5b9ac..ba616b5f7 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineContentTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineContentTest.java @@ -60,7 +60,7 @@ public void testExternalFile(@TempDir Path tempDir) throws CoreException, IOExce MockLanguageServer.INSTANCE.setDocumentSymbols(symbolCow); - final var editor = (ITextEditor) TestUtils.openExternalFileInEditor(testFile.toFile()); + final var editor = (ITextEditor) TestUtils.openExternalFileInEditor(testFile); final var outlinePage = (CNFOutlinePage) new EditorToOutlineAdapterFactory().getAdapter(editor, IContentOutlinePage.class); final var shell = new Shell(editor.getEditorSite().getWorkbenchWindow().getShell()); @@ -90,7 +90,7 @@ public void testExternalFileOpenedOnFileStore(@TempDir Path tempDir) throws Core MockLanguageServer.INSTANCE.setDocumentSymbols(symbolCow); - final var editor = (ITextEditor) TestUtils.openExternalFileOnFileStore(testFile.toFile()); + final var editor = (ITextEditor) TestUtils.openExternalFileOnFileStore(testFile); final var outlinePage = (CNFOutlinePage) new EditorToOutlineAdapterFactory().getAdapter(editor, IContentOutlinePage.class); final var shell = new Shell(editor.getEditorSite().getWorkbenchWindow().getShell()); diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineViewerInputTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineViewerInputTest.java index 964a36f03..dec5f87da 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineViewerInputTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/outline/OutlineViewerInputTest.java @@ -62,7 +62,7 @@ public void testDocumentURIAbsolutePathForExternalFile(@TempDir Path tempDir) th var tempFile = Files.writeString(tempDir.resolve("externalTest.lspt"), "external file content for testing absolute paths"); // Open the external file in an editor - var editor = (ITextEditor) TestUtils.openExternalFileInEditor(tempFile.toFile()); + var editor = (ITextEditor) TestUtils.openExternalFileInEditor(tempFile); var document = LSPEclipseUtils.getDocument(editor); // Create OutlineViewerInput and verify documentURI diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/TestUtils.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/TestUtils.java index 50d16e17e..713530540 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/TestUtils.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/TestUtils.java @@ -15,7 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -101,20 +100,20 @@ public static List splitActiveEditor() { return List.of(page.getEditorReferences()); } - public static IEditorPart openExternalFileInEditor(File file) throws PartInitException { + public static IEditorPart openExternalFileInEditor(Path file) throws PartInitException { IWorkbenchWindow workbenchWindow = UI.getActiveWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); - IEditorPart part = IDE.openEditor(page, file.toURI(), "org.eclipse.ui.genericeditor.GenericEditor", false); + IEditorPart part = IDE.openEditor(page, file.toUri(), "org.eclipse.ui.genericeditor.GenericEditor", false); if (part != null) { part.setFocus(); } return part; } - public static IEditorPart openExternalFileOnFileStore(File file) throws PartInitException { + public static IEditorPart openExternalFileOnFileStore(Path file) throws PartInitException { IWorkbenchWindow workbenchWindow = UI.getActiveWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); - IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI()); + IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toUri()); IEditorPart part = IDE.openEditorOnFileStore(page, fileStore); if (part != null) { part.setFocus();