Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-12 14:24:41 +0000
committerMichael Keppler2019-05-15 06:00:12 +0000
commit6997c809ef8f6e89dac065d693185286d0af83f6 (patch)
tree7a8a3bbf997d7f38c59b729a9b4b23225695d585 /org.eclipse.egit.ui.test/src
parentf7252caf1b30cd08badd7480a8130f0e55daf723 (diff)
downloadegit-6997c809ef8f6e89dac065d693185286d0af83f6.tar.gz
egit-6997c809ef8f6e89dac065d693185286d0af83f6.tar.xz
egit-6997c809ef8f6e89dac065d693185286d0af83f6.zip
Use try-with-resources
Convert try finally block to try-with-resources Change-Id: I29a482e2bbfe5e9029b41c1fe7a5bf45308905c2 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
Diffstat (limited to 'org.eclipse.egit.ui.test/src')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java9
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java5
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java12
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java17
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java16
5 files changed, 25 insertions, 34 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
index 17e62768b0..a586299bc4 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
@@ -292,14 +292,9 @@ public class TestUtil {
*/
public static void appendFileContent(File file, String content, boolean append)
throws IOException {
- Writer fw = null;
- try {
- fw = new OutputStreamWriter(new FileOutputStream(file, append),
- "UTF-8");
+ try (Writer fw = new OutputStreamWriter(new FileOutputStream(file, append),
+ "UTF-8")) {
fw.append(content);
- } finally {
- if (fw != null)
- fw.close();
}
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
index 27bae49a95..980ba7663d 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
@@ -202,8 +202,7 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase {
"Add to stable");
op.execute(null);
- InputStream is = toBeDeleted.getContents();
- try {
+ try (InputStream is = toBeDeleted.getContents()) {
checkout(new String[] { LOCAL_BRANCHES, "master" });
final SWTBotShell showUndeleted = bot
.shell(UIText.NonDeletedFilesDialog_NonDeletedFilesTitle);
@@ -282,8 +281,6 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase {
UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
showUndeleted.close();
- } finally {
- is.close();
}
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java
index 6be393b081..4229466dd1 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java
@@ -204,12 +204,12 @@ public class CompareActionsTest extends LocalRepositoryTestCase {
Ref newBranch = git.checkout().setCreateBranch(true)
.setStartPoint(commitOfTag.name()).setName("toMerge")
.call();
- ByteArrayInputStream bis = new ByteArrayInputStream(
- "Modified".getBytes("UTF-8"));
- ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
- .getFolder(FOLDER).getFile(FILE2)
- .setContents(bis, false, false, null);
- bis.close();
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(
+ "Modified".getBytes("UTF-8"))) {
+ ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
+ .getFolder(FOLDER).getFile(FILE2)
+ .setContents(bis, false, false, null);
+ }
git.commit().setAll(true).setMessage("To be merged").call();
git.merge().include(masterId).call();
String menuLabel = util
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java
index 6afb055d1f..c59708f2d2 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java
@@ -256,11 +256,10 @@ public class SynchronizeViewGitChangeSetModelTest extends
String name = "non-workspace.txt";
File root = new File(getTestDirectory(), REPO1);
File nonWorkspace = new File(root, name);
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"));
-
- writer.append("file content");
- writer.close();
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"))) {
+ writer.append("file content");
+ }
// TODO Synchronize currently shows "No changes" when the only thing that has
// changed is a non-workspace file, so add another change so that this
// does not happen. When the bug is fixed, this should be removed.
@@ -282,10 +281,10 @@ public class SynchronizeViewGitChangeSetModelTest extends
String name = "non-workspace.txt";
File root = new File(getTestDirectory(), REPO1);
File nonWorkspace = new File(root, name);
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"));
- writer.append(content);
- writer.close();
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"))) {
+ writer.append(content);
+ }
// TODO Synchronize currently shows "No changes" when the only thing that has
// changed is a non-workspace file, so add another change so that this
// does not happen. When the bug is fixed, this should be removed.
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java
index 0d247919a5..4b2cbb8145 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java
@@ -296,10 +296,10 @@ public class SynchronizeViewWorkspaceModelTest extends AbstractSynchronizeViewTe
String name = "non-workspace.txt";
File root = new File(getTestDirectory(), REPO1);
File nonWorkspace = new File(root, name);
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"));
- writer.append("file content");
- writer.close();
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"))) {
+ writer.append("file content");
+ }
// when
launchSynchronization(INITIAL_TAG, HEAD, true);
@@ -319,10 +319,10 @@ public class SynchronizeViewWorkspaceModelTest extends AbstractSynchronizeViewTe
String name = "non-workspace.txt";
File root = new File(getTestDirectory(), REPO1);
File nonWorkspace = new File(root, name);
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
- Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"));
- writer.append(content);
- writer.close();
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ Files.newOutputStream(nonWorkspace.toPath()), "UTF-8"))) {
+ writer.append(content);
+ }
// when
launchSynchronization(INITIAL_TAG, HEAD, true);

Back to the top