aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java108
1 files changed, 57 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..a3634141c3 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
@@ -37,8 +37,12 @@
*/
package org.eclipse.jgit.lib;
+import static java.time.Instant.EPOCH;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.time.Instant;
+
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
@@ -49,80 +53,82 @@ 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);
+ assertFalse("last modified shall not be the epoch!",
+ entry.getLastModifiedInstant().equals(EPOCH));
- assertTrue("last modified shall not be zero!",
- entry2.getLastModified() != 0);
+ assertFalse("last modified shall not be the epoch!",
+ entry2.getLastModifiedInstant().equals(EPOCH));
- 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);
+ assertFalse("last modified shall not be the epoch!",
+ entry.getLastModifiedInstant().equals(EPOCH));
- assertTrue("last modified shall not be zero!",
- entry2.getLastModified() != 0);
+ assertFalse("last modified shall not be the epoch!",
+ entry2.getLastModifiedInstant().equals(EPOCH));
+ }
}
@Test
public void testModify() throws Exception {
- Git git = new Git(db);
- String path = "file";
- writeTrashFile(path, "content");
-
- git.add().addFilepattern(path).call();
- git.commit().setMessage("commit").call();
+ try (Git git = new Git(db)) {
+ String path = "file";
+ writeTrashFile(path, "content");
- DirCache dc = db.readDirCache();
- DirCacheEntry entry = dc.getEntry(path);
+ git.add().addFilepattern(path).call();
+ git.commit().setMessage("commit").call();
- long masterLastMod = entry.getLastModified();
+ DirCache dc = db.readDirCache();
+ DirCacheEntry entry = dc.getEntry(path);
- git.checkout().setCreateBranch(true).setName("side").call();
+ Instant masterLastMod = entry.getLastModifiedInstant();
- Thread.sleep(10);
- String path2 = "file2";
- writeTrashFile(path2, "side content");
- git.add().addFilepattern(path2).call();
- git.commit().setMessage("commit").call();
+ git.checkout().setCreateBranch(true).setName("side").call();
- dc = db.readDirCache();
- entry = dc.getEntry(path);
+ Thread.sleep(10);
+ String path2 = "file2";
+ writeTrashFile(path2, "side content");
+ git.add().addFilepattern(path2).call();
+ git.commit().setMessage("commit").call();
- long sideLastMode = entry.getLastModified();
+ dc = db.readDirCache();
+ entry = dc.getEntry(path);
- Thread.sleep(2000);
+ Instant sideLastMod = entry.getLastModifiedInstant();
- writeTrashFile(path, "uncommitted content");
- git.checkout().setName("master").call();
+ Thread.sleep(2000);
- dc = db.readDirCache();
- entry = dc.getEntry(path);
+ writeTrashFile(path, "uncommitted content");
+ git.checkout().setName("master").call();
- 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.equals(sideLastMod));
+ assertTrue("shall have equal master timestamp!",
+ entry.getLastModifiedInstant().equals(masterLastMod));
+ }
}
}