summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-15 14:51:42 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-15 14:51:42 +0900
commit217760fee5c8f40ad52b2f07e89a1a14b30f1cbd (patch)
treef54862f0b5afc2e3aeb1fac24b45fd6d3b0d72f3
parentde73fbf5972589462674c83f4e48ada9037b0405 (diff)
downloadjgit-217760fee5c8f40ad52b2f07e89a1a14b30f1cbd.tar.gz
jgit-217760fee5c8f40ad52b2f07e89a1a14b30f1cbd.zip
IndexModificationTimesTest: Open Git instances in try-with-resource
Change-Id: If52c071b71f5df822b1ac276a6f665515f6c9d00 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java103
1 files 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);
+ }
}
}