From 217760fee5c8f40ad52b2f07e89a1a14b30f1cbd Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 14:51:42 +0900 Subject: [PATCH] IndexModificationTimesTest: Open Git instances in try-with-resource Change-Id: If52c071b71f5df822b1ac276a6f665515f6c9d00 Signed-off-by: David Pursehouse --- .../jgit/lib/IndexModificationTimesTest.java | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java index c6f02f4a49..b9bbbeb9e5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java @@ -49,80 +49,81 @@ public class IndexModificationTimesTest extends RepositoryTestCase { @Test public void testLastModifiedTimes() throws Exception { - Git git = new Git(db); - String path = "file"; - writeTrashFile(path, "content"); - String path2 = "file2"; - writeTrashFile(path2, "content2"); + try (Git git = new Git(db)) { + String path = "file"; + writeTrashFile(path, "content"); + String path2 = "file2"; + writeTrashFile(path2, "content2"); - git.add().addFilepattern(path).call(); - git.add().addFilepattern(path2).call(); - git.commit().setMessage("commit").call(); + git.add().addFilepattern(path).call(); + git.add().addFilepattern(path2).call(); + git.commit().setMessage("commit").call(); - DirCache dc = db.readDirCache(); - DirCacheEntry entry = dc.getEntry(path); - DirCacheEntry entry2 = dc.getEntry(path); + DirCache dc = db.readDirCache(); + DirCacheEntry entry = dc.getEntry(path); + DirCacheEntry entry2 = dc.getEntry(path); - assertTrue("last modified shall not be zero!", - entry.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry.getLastModified() != 0); - assertTrue("last modified shall not be zero!", - entry2.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry2.getLastModified() != 0); - writeTrashFile(path, "new content"); - git.add().addFilepattern(path).call(); - git.commit().setMessage("commit2").call(); + writeTrashFile(path, "new content"); + git.add().addFilepattern(path).call(); + git.commit().setMessage("commit2").call(); - dc = db.readDirCache(); - entry = dc.getEntry(path); - entry2 = dc.getEntry(path); + dc = db.readDirCache(); + entry = dc.getEntry(path); + entry2 = dc.getEntry(path); - assertTrue("last modified shall not be zero!", - entry.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry.getLastModified() != 0); - assertTrue("last modified shall not be zero!", - entry2.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry2.getLastModified() != 0); + } } @Test public void testModify() throws Exception { - Git git = new Git(db); - String path = "file"; - writeTrashFile(path, "content"); + try (Git git = new Git(db)) { + String path = "file"; + writeTrashFile(path, "content"); - git.add().addFilepattern(path).call(); - git.commit().setMessage("commit").call(); + git.add().addFilepattern(path).call(); + git.commit().setMessage("commit").call(); - DirCache dc = db.readDirCache(); - DirCacheEntry entry = dc.getEntry(path); + DirCache dc = db.readDirCache(); + DirCacheEntry entry = dc.getEntry(path); - long masterLastMod = entry.getLastModified(); + long masterLastMod = entry.getLastModified(); - git.checkout().setCreateBranch(true).setName("side").call(); + git.checkout().setCreateBranch(true).setName("side").call(); - Thread.sleep(10); - String path2 = "file2"; - writeTrashFile(path2, "side content"); - git.add().addFilepattern(path2).call(); - git.commit().setMessage("commit").call(); + Thread.sleep(10); + String path2 = "file2"; + writeTrashFile(path2, "side content"); + git.add().addFilepattern(path2).call(); + git.commit().setMessage("commit").call(); - dc = db.readDirCache(); - entry = dc.getEntry(path); + dc = db.readDirCache(); + entry = dc.getEntry(path); - long sideLastMode = entry.getLastModified(); + long sideLastMode = entry.getLastModified(); - Thread.sleep(2000); + Thread.sleep(2000); - writeTrashFile(path, "uncommitted content"); - git.checkout().setName("master").call(); + writeTrashFile(path, "uncommitted content"); + git.checkout().setName("master").call(); - dc = db.readDirCache(); - entry = dc.getEntry(path); - - assertTrue("shall have equal mod time!", masterLastMod == sideLastMode); - assertTrue("shall not equal master timestamp!", - entry.getLastModified() == masterLastMod); + dc = db.readDirCache(); + entry = dc.getEntry(path); + assertTrue("shall have equal mod time!", masterLastMod == sideLastMode); + assertTrue("shall not equal master timestamp!", + entry.getLastModified() == masterLastMod); + } } } -- 2.39.5