|
35 | 35 | @ExtendWith(AllCleanRule.class) |
36 | 36 | public class TestHTML { |
37 | 37 |
|
38 | | - @Test |
39 | | - public void testHTMLFile() throws Exception { |
40 | | - final IProject project = ResourcesPlugin.getWorkspace().getRoot() |
41 | | - .getProject("testHTMLFile" + System.currentTimeMillis()); |
42 | | - project.create(null); |
43 | | - project.open(null); |
44 | | - final IFile file = project.getFile("blah.html"); |
45 | | - file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); |
46 | | - ITextEditor editor = (ITextEditor) IDE |
47 | | - .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); |
48 | | - editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><"); |
49 | | - assertTrue(new DisplayHelper() { |
50 | | - @Override |
51 | | - protected boolean condition() { |
52 | | - try { |
53 | | - return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; |
54 | | - } catch (CoreException e) { |
55 | | - return false; |
56 | | - } |
57 | | - } |
58 | | - }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published"); |
59 | | - } |
| 38 | + @Test |
| 39 | + public void testHTMLFile() throws Exception { |
| 40 | + final IProject project = ResourcesPlugin.getWorkspace().getRoot() |
| 41 | + .getProject("testHTMLFile" + System.currentTimeMillis()); |
| 42 | + project.create(null); |
| 43 | + project.open(null); |
| 44 | + final IFile file = project.getFile("blah.html"); |
| 45 | + file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); |
| 46 | + ITextEditor editor = (ITextEditor) IDE |
| 47 | + .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); |
| 48 | + editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><"); |
| 49 | + assertTrue(DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, () -> { |
| 50 | + try { |
| 51 | + return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; |
| 52 | + } catch (CoreException e) { |
| 53 | + return false; |
| 54 | + } |
| 55 | + }), "Diagnostic not published"); |
| 56 | + } |
60 | 57 |
|
61 | | - @Test |
62 | | - public void testFormat() throws Exception { |
63 | | - final IProject project = ResourcesPlugin.getWorkspace().getRoot() |
64 | | - .getProject("testHTMLFile" + System.currentTimeMillis()); |
65 | | - project.create(null); |
66 | | - project.open(null); |
67 | | - final IFile file = project.getFile("blah.html"); |
68 | | - file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null); |
69 | | - ITextEditor editor = (ITextEditor) IDE |
70 | | - .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); |
71 | | - editor.setFocus(); |
72 | | - editor.getSelectionProvider().setSelection(new TextSelection(0, 0)); |
73 | | - IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class); |
| 58 | + @Test |
| 59 | + public void testFormat() throws Exception { |
| 60 | + final IProject project = ResourcesPlugin.getWorkspace().getRoot() |
| 61 | + .getProject("testHTMLFile" + System.currentTimeMillis()); |
| 62 | + project.create(null); |
| 63 | + project.open(null); |
| 64 | + final IFile file = project.getFile("blah.html"); |
| 65 | + file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null); |
| 66 | + ITextEditor editor = (ITextEditor) IDE |
| 67 | + .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); |
| 68 | + editor.setFocus(); |
| 69 | + editor.getSelectionProvider().setSelection(new TextSelection(0, 0)); |
| 70 | + IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class); |
74 | 71 | // assertTrue(PlatformUI.getWorkbench().getService(ICommandService.class).getCommand("org.eclipse.lsp4e.format") |
75 | 72 | // .isEnabled()); |
76 | | - new DisplayHelper() { |
77 | | - @Override |
78 | | - protected boolean condition() { |
79 | | - try { |
80 | | - return PlatformUI.getWorkbench().getService(ICommandService.class) |
81 | | - .getCommand("org.eclipse.lsp4e.format").isEnabled(); |
82 | | - } catch (Exception e) { |
83 | | - return false; |
84 | | - } |
85 | | - } |
86 | | - }.waitForCondition(editor.getSite().getShell().getDisplay(), 3000); |
| 73 | + DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000, () -> { |
| 74 | + try { |
| 75 | + return PlatformUI.getWorkbench().getService(ICommandService.class) |
| 76 | + .getCommand("org.eclipse.lsp4e.format").isEnabled(); |
| 77 | + } catch (Exception e) { |
| 78 | + return false; |
| 79 | + } |
| 80 | + }); |
87 | 81 |
|
88 | 82 | // AtomicReference<Exception> ex = new AtomicReference<>(); |
89 | | - new DisplayHelper() { |
90 | | - @Override |
91 | | - protected boolean condition() { |
92 | | - try { |
93 | | - handlerService.executeCommand("org.eclipse.lsp4e.format", null); |
94 | | - return true; |
95 | | - } catch (Exception e) { |
96 | | - return false; |
97 | | - } |
98 | | - } |
99 | | - }.waitForCondition(editor.getSite().getShell().getDisplay(), 3000); |
| 83 | + DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000, () -> { |
| 84 | + try { |
| 85 | + handlerService.executeCommand("org.eclipse.lsp4e.format", null); |
| 86 | + return true; |
| 87 | + } catch (Exception e) { |
| 88 | + return false; |
| 89 | + } |
| 90 | + }); |
100 | 91 | // if (ex.get() != null) { |
101 | 92 | // throw ex.get(); |
102 | 93 | // } |
103 | | - new DisplayHelper() { |
104 | | - @Override |
105 | | - protected boolean condition() { |
106 | | - return editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1; |
107 | | - } |
108 | | - }.waitForCondition(editor.getSite().getShell().getDisplay(), 3000); |
109 | | - } |
| 94 | + DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 3000, |
| 95 | + () -> editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1); |
| 96 | + } |
110 | 97 |
|
111 | | - @Test |
112 | | - public void autoCloseTags() throws Exception { |
113 | | - final IProject project = ResourcesPlugin.getWorkspace().getRoot() |
114 | | - .getProject("testHTMLFile" + System.currentTimeMillis()); |
115 | | - project.create(null); |
116 | | - project.open(null); |
117 | | - final IFile file = project.getFile("autoCloseTags.html"); |
118 | | - file.create(new ByteArrayInputStream("<foo".getBytes()), true, null); |
119 | | - ITextEditor editor = (ITextEditor) IDE |
120 | | - .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); |
121 | | - IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
122 | | - document.replace(4, 0, ">"); |
123 | | - assertTrue(new DisplayHelper() { |
124 | | - @Override |
125 | | - protected boolean condition() { |
126 | | - return "<foo></foo>".equals(document.get()); |
127 | | - } |
128 | | - }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Autoclose not done"); |
129 | | - } |
| 98 | + @Test |
| 99 | + public void autoCloseTags() throws Exception { |
| 100 | + final IProject project = ResourcesPlugin.getWorkspace().getRoot() |
| 101 | + .getProject("testHTMLFile" + System.currentTimeMillis()); |
| 102 | + project.create(null); |
| 103 | + project.open(null); |
| 104 | + final IFile file = project.getFile("autoCloseTags.html"); |
| 105 | + file.create(new ByteArrayInputStream("<foo".getBytes()), true, null); |
| 106 | + ITextEditor editor = (ITextEditor) IDE |
| 107 | + .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); |
| 108 | + IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
| 109 | + document.replace(4, 0, ">"); |
| 110 | + assertTrue( |
| 111 | + DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, |
| 112 | + () -> "<foo></foo>".equals(document.get())), |
| 113 | + "Autoclose not done"); |
| 114 | + } |
130 | 115 | } |
0 commit comments