Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-06-22 15:42:13 +0000
committerAlexander Kurtakov2017-06-22 15:42:13 +0000
commit6e0300fbe0155dd09a58b195b9310342162bc7b8 (patch)
treea6b1a743aeb93d2f3118f9eea784591e6eab99e6 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository
parent2db6317e308a86a23c3e7b1dd252f6583b0c5bc9 (diff)
downloadrt.equinox.p2-6e0300fbe0155dd09a58b195b9310342162bc7b8.tar.gz
rt.equinox.p2-6e0300fbe0155dd09a58b195b9310342162bc7b8.tar.xz
rt.equinox.p2-6e0300fbe0155dd09a58b195b9310342162bc7b8.zip
Bug 518587 - Modernize o.e.equinox.p2.testsI20170623-0110I20170622-2000
Use try-with-resources. Change-Id: I6c1d3efb7f0fd4f5dd0f014d8801ec8e375355f9 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java32
2 files changed, 21 insertions, 24 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java
index 2deccbcf8..7ba30e182 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java
@@ -1,10 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Cloudsmith Inc and others.
- * All rights reserved. This program and the accompanying materials
+ * Copyright (c) 2009, 2017 Cloudsmith Inc and others.
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cloudsmith Inc - initial API and implementation
*******************************************************************************/
@@ -50,8 +50,9 @@ public class FileReaderTest extends AbstractTestServerClientCase {
RepositoryTransport transport = new RepositoryTransport();
URI toDownload = new URI(getBaseURL() + "/public/index.html");
final NullProgressMonitor monitor = new NullProgressMonitor();
- InputStream stream = transport.stream(toDownload, monitor);
- stream.close();
+ try (InputStream stream = transport.stream(toDownload, monitor)) {
+ //
+ }
assertFalse("1.0", monitor.isCanceled());
}
@@ -72,5 +73,5 @@ public class FileReaderTest extends AbstractTestServerClientCase {
// redirected many times = login
// handling of incorrect file size
- //
+ //
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java
index 8158c44e8..ef1bc96a4 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java
@@ -189,8 +189,6 @@ public class FileReaderTest2 extends AbstractProvisioningTest {
private void doFileReaderTest(final PauseJob pauseJob, IProgressMonitor monitor) throws IOException, CoreException {
final String testRemoteFileURL = "http://download.eclipse.org/releases/juno/201206270900/content.jar";
- OutputStream out = null;
- OutputStream out1 = null;
File tmpFolder = getTempFolder();
File tmpFile = new File(tmpFolder, "testDownloadPauseResume.zip");
File tmpFile1 = new File(tmpFolder, "testDownloadWithoutPause.zip");
@@ -209,25 +207,23 @@ public class FileReaderTest2 extends AbstractProvisioningTest {
getEventBus().addListener(listener);
try {
tmpFile1.createNewFile();
- out1 = new FileOutputStream(tmpFile1);
- FileReader readerWithoutPausing = new FileReader(null, null);
- readerWithoutPausing.readInto(URI.create(testRemoteFileURL), out1, null);
- assertNotNull(readerWithoutPausing.getResult());
- assertTrue(readerWithoutPausing.getResult().isOK());
- tmpFile.createNewFile();
- out = new FileOutputStream(tmpFile);
- FileReader reader = pauseJob.getReader();
- reader.readInto(URI.create(testRemoteFileURL), out, monitor);
- assertNotNull(reader.getResult());
- assertTrue(reader.getResult().isOK());
- assertEquals("File with pausing/resuming is not identical with file without pausing.", tmpFile1.length(), tmpFile.length());
+ try (OutputStream out1 = new FileOutputStream(tmpFile1)) {
+ FileReader readerWithoutPausing = new FileReader(null, null);
+ readerWithoutPausing.readInto(URI.create(testRemoteFileURL), out1, null);
+ assertNotNull(readerWithoutPausing.getResult());
+ assertTrue(readerWithoutPausing.getResult().isOK());
+ tmpFile.createNewFile();
+ try (OutputStream out = new FileOutputStream(tmpFile)) {
+ FileReader reader = pauseJob.getReader();
+ reader.readInto(URI.create(testRemoteFileURL), out, monitor);
+ assertNotNull(reader.getResult());
+ assertTrue(reader.getResult().isOK());
+ assertEquals("File with pausing/resuming is not identical with file without pausing.", tmpFile1.length(), tmpFile.length());
+ }
+ }
} finally {
getEventBus().removeListener(listener);
- if (out1 != null)
- out1.close();
tmpFile1.delete();
- if (out != null)
- out.close();
tmpFile.delete();
delete(tmpFolder);
}

Back to the top