Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Java NIO usage in tests #608

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2017 WindRiver Corporation and others.
* Copyright (c) 2011, 2025 WindRiver Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@

import java.io.*;
import java.net.*;
import java.nio.file.Files;
import java.util.List;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.importexport.IUDetail;
Expand Down Expand Up @@ -71,11 +72,11 @@ public void testExportFeaturesFromRemoteRepository()
IMetadataRepository repo = metaManager.loadRepository(uri, null);
assertNotNull("Fail to load remote repo", repo);
IInstallableUnit iu = AbstractProvisioningTest.createIU("A", Version.create("1.0.0"));
try (OutputStream output = new FileOutputStream(testFile)) {
try (OutputStream output = Files.newOutputStream(testFile.toPath())) {
IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] { iu }, false, null);
assertTrue("Not expected return result.", status.isOK());
}
try (InputStream input = new FileInputStream(testFile)) {
try (InputStream input = Files.newInputStream(testFile.toPath())) {
List<IUDetail> ius = importexportService.importP2F(input);
assertEquals("Exported the number of features is not expected.", 1, ius.size());
assertEquals("Exported feature is not expected.", iu, ius.get(0).getIU());
Expand Down Expand Up @@ -121,11 +122,11 @@ public void testExportFeaturesFromBothRemoteRepositoryAndLocalRepository()
IMetadataRepository repo = metaManager.loadRepository(uri, null);
assertNotNull("Fail to load remote repo", repo);
IInstallableUnit iu = AbstractProvisioningTest.createIU("A", Version.create("1.0.0"));
try (OutputStream output = new FileOutputStream(testFile)) {
try (OutputStream output = Files.newOutputStream(testFile.toPath())) {
IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] { iu }, false, null);
assertTrue("Not expected return result.", status.isOK());
}
try (InputStream input = new FileInputStream(testFile)) {
try (InputStream input = Files.newInputStream(testFile.toPath())) {
List<IUDetail> ius = importexportService.importP2F(input);
assertEquals("Exported the number of features is not expected.", 1, ius.size());
assertEquals("Exported feature is not expected.", iu, ius.get(0).getIU());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2017 WindRiver Corporation and others.
* Copyright (c) 2011, 2025 WindRiver Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,6 +17,7 @@
import static org.junit.Assert.assertThrows;

import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected void tearDown() throws Exception {
public void testLoadP2f() throws IOException {
File p2fFile = getTestData("Error load test file.", "testData/importexport/test.p2f");

try (InputStream input = new FileInputStream(p2fFile)) {
try (InputStream input = Files.newInputStream(p2fFile.toPath())) {
List<IUDetail> iuDetails = importexportService.importP2F(input);
assertEquals("Should load two features from the p2f file.", 2, iuDetails.size());
int counter = 0;
Expand All @@ -88,7 +89,7 @@ public void testLoadP2f() throws IOException {
public void testLoadUnknownP2f() throws IOException {
File p2fFile = getTestData("Error load test file.", "testData/importexport/unknownformat.p2f");

try (InputStream input = new FileInputStream(p2fFile)) {
try (InputStream input = Files.newInputStream(p2fFile.toPath())) {
List<IUDetail> iuDetails = importexportService.importP2F(input);
assertEquals("Should not load any detail.", 0, iuDetails.size());
}
Expand All @@ -97,7 +98,7 @@ public void testLoadUnknownP2f() throws IOException {
public void testIncompatibleP2f() throws IOException {
File p2fFile = getTestData("Error load test file.", "testData/importexport/incompatible.p2f");

try (InputStream input = new FileInputStream(p2fFile)) {
try (InputStream input = Files.newInputStream(p2fFile.toPath())) {
assertThrows("Didn't complain the given file is not supported by current version.",
VersionIncompatibleException.class, () -> importexportService.importP2F(input));
}
Expand All @@ -112,7 +113,7 @@ public void testExportFeaturesInstalledFromLocal()
IMetadataRepository repo = metaManager.loadRepository(localRepoFile.toURI(), null);
assertNotNull("Fail to load local repo", repo);
IInstallableUnit iu = createIU("A", Version.create("1.0.0"));
try (OutputStream output = new FileOutputStream(testFile)) {
try (OutputStream output = Files.newOutputStream(testFile.toPath())) {
IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] { iu }, false, null);
assertFalse("Not expected return result.", status.isOK());
assertTrue("Should be a multiple status", status.isMultiStatus());
Expand All @@ -137,7 +138,7 @@ public void testAllowExportFeaturesInstalledFromLocal()
IMetadataRepository repo = metaManager.loadRepository(localRepoFile.toURI(), null);
assertNotNull("Fail to load local repo", repo);
IInstallableUnit iu = createIU("A", Version.create("1.0.0"));
try (OutputStream output = new FileOutputStream(testFile)) {
try (OutputStream output = Files.newOutputStream(testFile.toPath())) {
IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] { iu }, true, null);
assertTrue(status.isOK());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.equinox.p2.tests.verifier;singleton:=true
Bundle-Version: 1.4.400.qualifier
Bundle-Version: 1.4.500.qualifier
Export-Package: org.eclipse.equinox.internal.p2.tests.verifier;x-internal:=true
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.equinox.p2.core,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2018 IBM Corporation and others.
* Copyright (c) 2009, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,6 +17,7 @@

import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.util.*;
import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
Expand Down Expand Up @@ -124,7 +125,7 @@ private void processArguments(String[] args) {
*/
private Properties readProperties(File file) throws IOException {
Properties result = new Properties();
try (InputStream input = new BufferedInputStream(new FileInputStream(file))) {
try (BufferedReader input = Files.newBufferedReader(file.toPath())) {
result.load(input);
return result;
}
Expand Down
Loading