Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-04-28 12:12:15 -0400
committerMichael Keppler2019-05-15 06:26:39 -0400
commitba0338dadf704ce24a63cd99a22e3acac7887509 (patch)
tree1dd8c5e78d1e0ad7eebe7fffc8e2b167e13fcc3a /org.eclipse.egit.ui.test/src/org
parent2b5d27f65957c6e0957c3571edc808ff76f2ddd7 (diff)
downloadegit-ba0338dadf704ce24a63cd99a22e3acac7887509.tar.gz
egit-ba0338dadf704ce24a63cd99a22e3acac7887509.tar.xz
egit-ba0338dadf704ce24a63cd99a22e3acac7887509.zip
Use try-finally to dispose clipboard
Clipboard uses system resources. Use try-finally there similarly as we would with any Closable. Change-Id: Ida5bd1ded9d69f904b89a739c888b21fbeaf8526 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java8
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java42
2 files changed, 29 insertions, 21 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
index e45b98ca0..d395a9c4c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
@@ -241,8 +241,12 @@ public class CreatePatchActionTest extends LocalRepositoryTestCase {
@Override
public void run() {
Clipboard clp = new Clipboard(Display.getCurrent());
- value[0] = (String) clp.getContents(TextTransfer.getInstance());
- clp.dispose();
+ try {
+ value[0] = (String) clp
+ .getContents(TextTransfer.getInstance());
+ } finally {
+ clp.dispose();
+ }
}
});
assertEquals(expected, value[0]);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java
index d332f2516..d424c0365 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java
@@ -80,21 +80,26 @@ public class GitRepositoriesViewRepoHandlingTest extends
@Override
public void run() {
Clipboard clp = new Clipboard(Display.getCurrent());
- clp.clearContents();
- clp.setContents(new Object[] { "x" },
- new TextTransfer[] { TextTransfer.getInstance() });
- String value = (String) clp.getContents(TextTransfer
- .getInstance());
- assertEquals("Clipboard content should be x", "x", value);
-
- ContextMenuHelper.clickContextMenuSync(tree, myUtil
- .getPluginLocalizedValue("CopyPathCommand"));
- value = (String) clp.getContents(TextTransfer.getInstance());
- assertTrue("Clipboard content (" + value
- + ")should be a repository path", FileKey
- .isGitRepository(new File(value), FS.DETECTED));
-
- clp.dispose();
+ try {
+ clp.clearContents();
+ clp.setContents(new Object[] { "x" },
+ new TextTransfer[] { TextTransfer.getInstance() });
+ String value = (String) clp
+ .getContents(TextTransfer.getInstance());
+ assertEquals("Clipboard content should be x", "x", value);
+
+ ContextMenuHelper.clickContextMenuSync(tree,
+ myUtil.getPluginLocalizedValue("CopyPathCommand"));
+ value = (String) clp
+ .getContents(TextTransfer.getInstance());
+ assertTrue(
+ "Clipboard content (" + value
+ + ")should be a repository path",
+ FileKey.isGitRepository(new File(value),
+ FS.DETECTED));
+ } finally {
+ clp.dispose();
+ }
}
});
@@ -111,9 +116,9 @@ public class GitRepositoriesViewRepoHandlingTest extends
@Override
public void run() {
- Clipboard clip = null;
+ Clipboard clip = new Clipboard(
+ PlatformUI.getWorkbench().getDisplay());
try {
- clip = new Clipboard(PlatformUI.getWorkbench().getDisplay());
clip.setContents(new Object[] { repositoryFile.getPath() },
new Transfer[] { TextTransfer.getInstance() });
@@ -122,8 +127,7 @@ public class GitRepositoriesViewRepoHandlingTest extends
} catch (Exception e) {
exceptions[0] = e;
} finally {
- if (clip != null)
- clip.dispose();
+ clip.dispose();
}
}
});

Back to the top