forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompletionBaseTests.java
More file actions
63 lines (53 loc) · 1.71 KB
/
Copy pathCompletionBaseTests.java
File metadata and controls
63 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.completion;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import com.microsoft.copilot.eclipse.ui.utils.SwtUtils;
/**
* Base class for completion tests.
*/
public abstract class CompletionBaseTests {
protected IProject project;
@BeforeEach
void setUp() throws Exception {
project = ResourcesPlugin.getWorkspace().getRoot().getProject("TestProject");
project.create(null);
project.open(null);
}
@AfterEach
void tearDown() throws Exception {
project.delete(true, null);
}
/**
* Opens the editor for the given file.
*
* @param file the file to open
* @return the editor part
*/
protected IEditorPart getEditorPartFor(IFile file) {
AtomicReference<IEditorPart> ref = new AtomicReference<>();
SwtUtils.invokeOnDisplayThread(() -> {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
try {
ref.set(window.getActivePage().openEditor(new org.eclipse.ui.part.FileEditorInput(file),
"org.eclipse.ui.DefaultTextEditor"));
} catch (PartInitException e) {
// do nothing
}
}
});
return ref.get();
}
}