]> source.dussan.org Git - jgit.git/commitdiff
LockFileTest: Open Git instance in try-with-resource 80/66580/1
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Mon, 15 Feb 2016 05:48:02 +0000 (14:48 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Mon, 15 Feb 2016 05:48:02 +0000 (14:48 +0900)
Change-Id: Ie2b0e55e606f50c46e21227f23de74dbea8388e5
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java

index 1a3a567f9f27cc4e71ca7033823892f47afe9a8d..520721b6aab10d472ccdf905d6715ef9553c659f 100644 (file)
@@ -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();
+                       }
                }
        }
 }