From 5d0286eb7c206f95b1c0ffb99294abcd7696faa1 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 8 May 2019 03:25:53 +0200 Subject: [PATCH] Add FileSnapshot test testing recognition of file size changes Change-Id: Ibcd76a5e6e4183ada0be1d4436ce957243f2094d Signed-off-by: Matthias Sohn --- .../internal/storage/file/FileSnapshotTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java index 79ede9691..5ebdeb6e8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java @@ -163,6 +163,23 @@ public void testSimulatePackfileReplacement() throws Exception { save.wasLastModifiedRacilyClean()); } + /** + * Append a character to a file to change its size and set original + * lastModified + * + * @throws Exception + */ + @Test + public void testFileSizeChanged() throws Exception { + File f = createFile("file"); + FileTime timestamp = Files.getLastModifiedTime(f.toPath()); + FileSnapshot save = FileSnapshot.save(f); + append(f, (byte) 'x'); + Files.setLastModifiedTime(f.toPath(), timestamp); + assertTrue(save.isModified(f)); + assertTrue(save.wasSizeChanged()); + } + private File createFile(String string) throws IOException { trash.mkdirs(); File f = File.createTempFile(string, "tdat", trash);