summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-15 14:48:02 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-15 14:48:02 +0900
commit6d33322df42aff5bc25a26f66a19464b46afd826 (patch)
tree2a6d24e8f53c66b36dd340d18bec2d4115b77f5e
parent3a6ed050a4f550b801e10344dace5e52db3ac609 (diff)
downloadjgit-6d33322df42aff5bc25a26f66a19464b46afd826.tar.gz
jgit-6d33322df42aff5bc25a26f66a19464b46afd826.zip
LockFileTest: Open Git instance in try-with-resource
Change-Id: Ie2b0e55e606f50c46e21227f23de74dbea8388e5 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java35
1 files changed, 18 insertions, 17 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
index 1a3a567f9f..520721b6aa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
@@ -61,25 +61,26 @@ public class LockFileTest extends RepositoryTestCase {
@Test
public void lockFailedExceptionRecovery() throws Exception {
- Git git = new Git(db);
- writeTrashFile("file.txt", "content");
- git.add().addFilepattern("file.txt").call();
- RevCommit commit1 = git.commit().setMessage("create file").call();
+ try (Git git = new Git(db)) {
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit commit1 = git.commit().setMessage("create file").call();
- assertNotNull(commit1);
- writeTrashFile("file.txt", "content2");
- git.add().addFilepattern("file.txt").call();
- assertNotNull(git.commit().setMessage("edit file").call());
+ assertNotNull(commit1);
+ writeTrashFile("file.txt", "content2");
+ git.add().addFilepattern("file.txt").call();
+ assertNotNull(git.commit().setMessage("edit file").call());
- LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
- assertTrue(lf.lock());
- try {
- git.checkout().setName(commit1.name()).call();
- fail("JGitInternalException not thrown");
- } catch (JGitInternalException e) {
- assertTrue(e.getCause() instanceof LockFailedException);
- lf.unlock();
- git.checkout().setName(commit1.name()).call();
+ LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
+ assertTrue(lf.lock());
+ try {
+ git.checkout().setName(commit1.name()).call();
+ fail("JGitInternalException not thrown");
+ } catch (JGitInternalException e) {
+ assertTrue(e.getCause() instanceof LockFailedException);
+ lf.unlock();
+ git.checkout().setName(commit1.name()).call();
+ }
}
}
}