From cb5aa0067d5775c5ada1b751adc502ad2375352b Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Tue, 26 Jul 2016 17:52:37 +0000 Subject: Fixed JavaIoFileSystem.setLastModifiedTime to actually match its documented behavior (passing -1 modified time should use system time). -- MOS_MIGRATED_REVID=128489592 --- .../build/lib/vfs/JavaIoFileSystemTest.java | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/test/java/com/google/devtools') diff --git a/src/test/java/com/google/devtools/build/lib/vfs/JavaIoFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/JavaIoFileSystemTest.java index 3251b09bee..efbd5b0dbf 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/JavaIoFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/JavaIoFileSystemTest.java @@ -13,6 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.vfs; +import static org.junit.Assert.assertEquals; + +import com.google.devtools.build.lib.testutil.ManualClock; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -25,16 +29,34 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class JavaIoFileSystemTest extends SymlinkAwareFileSystemTest { + private ManualClock clock; + @Override public FileSystem getFreshFileSystem() { - return new JavaIoFileSystem(); + clock = new ManualClock(); + return new JavaIoFileSystem(clock); } - // The tests are just inherited from the FileSystemTest + // Tests are inherited from the FileSystemTest // JavaIoFileSystem incorrectly throws a FileNotFoundException for all IO errors. This means that // statIfFound incorrectly suppresses those errors. @Override @Test public void testBadPermissionsThrowsExceptionOnStatIfFound() {} + + @Test + public void testSetLastModifiedTime() throws Exception { + Path file = xEmptyDirectory.getChild("new-file"); + FileSystemUtils.createEmptyFile(file); + + file.setLastModifiedTime(1000L); + assertEquals(1000L, file.getLastModifiedTime()); + file.setLastModifiedTime(0L); + assertEquals(0L, file.getLastModifiedTime()); + + clock.advanceMillis(42000L); + file.setLastModifiedTime(-1L); + assertEquals(42000L, file.getLastModifiedTime()); + } } -- cgit v1.2.3