Skip to content

Commit

Permalink
Fix warnings in tests about not closed autoclosables
Browse files Browse the repository at this point in the history
  • Loading branch information
akurtakov committed Nov 18, 2024
1 parent af029a9 commit abab1d9
Show file tree
Hide file tree
Showing 4 changed files with 399 additions and 413 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Red Hat Inc. and others.
* Copyright (c) 2019, 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -16,8 +16,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Collectors;

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

public class TestAngular {
static IProject project;
static IFolder appFolder;
static IProject project;
static IFolder appFolder;

@BeforeAll
public static void setUp() throws Exception {
AllCleanRule.closeIntro();
AllCleanRule.enableLogging();
@BeforeAll
public static void setUp() throws Exception {
AllCleanRule.closeIntro();
AllCleanRule.enableLogging();

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

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

assertEquals(0, process.waitFor(), "npm install didn't complete property");
assertEquals(0, process.waitFor(), "npm install didn't complete property");

project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
assertTrue(project.exists());
appFolder = project.getFolder("src").getFolder("app");
assertTrue(appFolder.exists());
}
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
assertTrue(project.exists());
appFolder = project.getFolder("src").getFolder("app");
assertTrue(appFolder.exists());
}

@BeforeEach
public void setUpTestCase() {
AllCleanRule.enableLogging();
}
@BeforeEach
public void setUpTestCase() {
AllCleanRule.enableLogging();
}

@AfterAll
public static void tearDown() throws Exception {
new AllCleanRule().afterEach(null);
}
@AfterAll
public static void tearDown() throws Exception {
new AllCleanRule().afterEach(null);
}

@Test
void testAngularTs() throws Exception {
IFile appComponentFile = appFolder.getFile("app.component.ts");
TextEditor editor = (TextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return Arrays
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true,
IResource.DEPTH_ZERO))
.anyMatch(marker -> marker.getAttribute(IMarker.LINE_NUMBER, -1) == 5
&& marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"Diagnostic not published in standalone component file");
editor.close(false);
}
@Test
void testAngularTs() throws Exception {
IFile appComponentFile = appFolder.getFile("app.component.ts");
TextEditor editor = (TextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return Arrays
.stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true,
IResource.DEPTH_ZERO))
.anyMatch(marker -> marker.getAttribute(IMarker.LINE_NUMBER, -1) == 5
&& marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"Diagnostic not published in standalone component file");
editor.close(false);
}

@Test
void testAngularHtml() throws Exception {
TextEditor editor = (TextEditor) IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
appFolder.getFile("app.componentWithHtml.ts"));
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
IFile appComponentHTML = appFolder.getFile("app.componentWithHtml.html");
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
appComponentHTML);
// Give some time for LS to load
DisplayHelper.sleep(2000);
// then make an edit
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.set(document.get() + "\n");
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
IMarker[] markers;
try {
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO);
return Arrays.stream(markers)
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"No error found on erroneous HTML component file");
// test completion
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
document.get().indexOf("}}"));
proposals[0].apply(document);
assertEquals("<h1>{{title}}</h1>\n", document.get(), "Incorrect completion insertion");
}
@Test
void testAngularHtml() throws Exception {
TextEditor editor = (TextEditor) IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
appFolder.getFile("app.componentWithHtml.ts"));
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
IFile appComponentHTML = appFolder.getFile("app.componentWithHtml.html");
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
appComponentHTML);
// Give some time for LS to load
DisplayHelper.sleep(2000);
// then make an edit
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.set(document.get() + "\n");
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
IMarker[] markers;
try {
markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO);
return Arrays.stream(markers)
.anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("not exist"));
} catch (CoreException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"No error found on erroneous HTML component file");
// test completion
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
document.get().indexOf("}}"));
proposals[0].apply(document);
assertEquals("<h1>{{title}}</h1>\n", document.get(), "Incorrect completion insertion");
}
}
Loading

0 comments on commit abab1d9

Please sign in to comment.