Skip to content

Commit abab1d9

Browse files
committed
Fix warnings in tests about not closed autoclosables
1 parent af029a9 commit abab1d9

File tree

4 files changed

+399
-413
lines changed

4 files changed

+399
-413
lines changed
Lines changed: 92 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2023 Red Hat Inc. and others.
2+
* Copyright (c) 2019, 2024 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -16,8 +16,6 @@
1616
import static org.junit.jupiter.api.Assertions.assertEquals;
1717
import static org.junit.jupiter.api.Assertions.assertTrue;
1818

19-
import java.io.BufferedReader;
20-
import java.io.InputStreamReader;
2119
import java.util.Arrays;
2220
import java.util.stream.Collectors;
2321

@@ -42,106 +40,104 @@
4240
import org.junit.jupiter.api.Test;
4341

4442
public class TestAngular {
45-
static IProject project;
46-
static IFolder appFolder;
43+
static IProject project;
44+
static IFolder appFolder;
4745

48-
@BeforeAll
49-
public static void setUp() throws Exception {
50-
AllCleanRule.closeIntro();
51-
AllCleanRule.enableLogging();
46+
@BeforeAll
47+
public static void setUp() throws Exception {
48+
AllCleanRule.closeIntro();
49+
AllCleanRule.enableLogging();
5250

53-
project = Utils.provisionTestProject("angular-app");
54-
ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts")
55-
.directory(project.getLocation().toFile());
56-
Process process = builder.start();
57-
System.out.println(builder.command().toString());
58-
String result = new BufferedReader(new InputStreamReader(process.getErrorStream())).lines()
59-
.collect(Collectors.joining("\n"));
60-
System.out.println("Error Stream: >>>\n" + result + "\n<<<");
51+
project = Utils.provisionTestProject("angular-app");
52+
ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts")
53+
.directory(project.getLocation().toFile());
54+
Process process = builder.start();
55+
System.out.println(builder.command().toString());
56+
String result = process.errorReader().lines().collect(Collectors.joining("\n"));
57+
System.out.println("Error Stream: >>>\n" + result + "\n<<<");
6158

62-
result = new BufferedReader(new InputStreamReader(process.getInputStream())).lines()
63-
.collect(Collectors.joining("\n"));
64-
System.out.println("Output Stream: >>>\n" + result + "\n<<<");
59+
result = process.inputReader().lines().collect(Collectors.joining("\n"));
60+
System.out.println("Output Stream: >>>\n" + result + "\n<<<");
6561

66-
assertEquals(0, process.waitFor(), "npm install didn't complete property");
62+
assertEquals(0, process.waitFor(), "npm install didn't complete property");
6763

68-
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
69-
assertTrue(project.exists());
70-
appFolder = project.getFolder("src").getFolder("app");
71-
assertTrue(appFolder.exists());
72-
}
64+
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
65+
assertTrue(project.exists());
66+
appFolder = project.getFolder("src").getFolder("app");
67+
assertTrue(appFolder.exists());
68+
}
7369

74-
@BeforeEach
75-
public void setUpTestCase() {
76-
AllCleanRule.enableLogging();
77-
}
70+
@BeforeEach
71+
public void setUpTestCase() {
72+
AllCleanRule.enableLogging();
73+
}
7874

79-
@AfterAll
80-
public static void tearDown() throws Exception {
81-
new AllCleanRule().afterEach(null);
82-
}
75+
@AfterAll
76+
public static void tearDown() throws Exception {
77+
new AllCleanRule().afterEach(null);
78+
}
8379

84-
@Test
85-
void testAngularTs() throws Exception {
86-
IFile appComponentFile = appFolder.getFile("app.component.ts");
87-
TextEditor editor = (TextEditor) IDE
88-
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
89-
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
90-
// didChange
91-
assertTrue(new DisplayHelper() {
92-
@Override
93-
protected boolean condition() {
94-
try {
95-
return Arrays
96-
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true,
97-
IResource.DEPTH_ZERO))
98-
.anyMatch(marker -> marker.getAttribute(IMarker.LINE_NUMBER, -1) == 5
99-
&& marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
100-
} catch (CoreException e) {
101-
e.printStackTrace();
102-
return false;
103-
}
104-
}
105-
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
106-
"Diagnostic not published in standalone component file");
107-
editor.close(false);
108-
}
80+
@Test
81+
void testAngularTs() throws Exception {
82+
IFile appComponentFile = appFolder.getFile("app.component.ts");
83+
TextEditor editor = (TextEditor) IDE
84+
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
85+
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
86+
// didChange
87+
assertTrue(new DisplayHelper() {
88+
@Override
89+
protected boolean condition() {
90+
try {
91+
return Arrays
92+
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true,
93+
IResource.DEPTH_ZERO))
94+
.anyMatch(marker -> marker.getAttribute(IMarker.LINE_NUMBER, -1) == 5
95+
&& marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
96+
} catch (CoreException e) {
97+
e.printStackTrace();
98+
return false;
99+
}
100+
}
101+
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
102+
"Diagnostic not published in standalone component file");
103+
editor.close(false);
104+
}
109105

110-
@Test
111-
void testAngularHtml() throws Exception {
112-
TextEditor editor = (TextEditor) IDE.openEditor(
113-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
114-
appFolder.getFile("app.componentWithHtml.ts"));
115-
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
116-
// didChange
117-
IFile appComponentHTML = appFolder.getFile("app.componentWithHtml.html");
118-
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
119-
appComponentHTML);
120-
// Give some time for LS to load
121-
DisplayHelper.sleep(2000);
122-
// then make an edit
123-
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
124-
document.set(document.get() + "\n");
125-
assertTrue(new DisplayHelper() {
126-
@Override
127-
protected boolean condition() {
128-
IMarker[] markers;
129-
try {
130-
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO);
131-
return Arrays.stream(markers)
132-
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
133-
} catch (CoreException e) {
134-
e.printStackTrace();
135-
return false;
136-
}
137-
}
138-
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
139-
"No error found on erroneous HTML component file");
140-
// test completion
141-
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
142-
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
143-
document.get().indexOf("}}"));
144-
proposals[0].apply(document);
145-
assertEquals("<h1>{{title}}</h1>\n", document.get(), "Incorrect completion insertion");
146-
}
106+
@Test
107+
void testAngularHtml() throws Exception {
108+
TextEditor editor = (TextEditor) IDE.openEditor(
109+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
110+
appFolder.getFile("app.componentWithHtml.ts"));
111+
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
112+
// didChange
113+
IFile appComponentHTML = appFolder.getFile("app.componentWithHtml.html");
114+
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
115+
appComponentHTML);
116+
// Give some time for LS to load
117+
DisplayHelper.sleep(2000);
118+
// then make an edit
119+
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
120+
document.set(document.get() + "\n");
121+
assertTrue(new DisplayHelper() {
122+
@Override
123+
protected boolean condition() {
124+
IMarker[] markers;
125+
try {
126+
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO);
127+
return Arrays.stream(markers)
128+
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
129+
} catch (CoreException e) {
130+
e.printStackTrace();
131+
return false;
132+
}
133+
}
134+
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
135+
"No error found on erroneous HTML component file");
136+
// test completion
137+
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
138+
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
139+
document.get().indexOf("}}"));
140+
proposals[0].apply(document);
141+
assertEquals("<h1>{{title}}</h1>\n", document.get(), "Incorrect completion insertion");
142+
}
147143
}

0 commit comments

Comments
 (0)