1919import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
2020import static org .junit .jupiter .api .Assertions .assertEquals ;
2121import static org .junit .jupiter .api .Assertions .assertFalse ;
22+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
2223import static org .junit .jupiter .api .Assertions .assertNotNull ;
2324import static org .junit .jupiter .api .Assertions .assertNull ;
2425import static org .junit .jupiter .api .Assertions .assertSame ;
@@ -1144,16 +1145,12 @@ public void testIsFileNewerOlder() throws Exception {
11441145 public void testCopyFile1 () throws Exception {
11451146 final File destination = new File (temporaryFolder , "copy1.txt" );
11461147
1147- //Thread.sleep(LAST_MODIFIED_DELAY);
1148- //This is to slow things down so we can catch if
1149- //the lastModified date is not ok
1148+ backDateFile (testFile1 ); // set test file back 10 minutes
11501149
11511150 FileUtils .copyFile (testFile1 , destination );
11521151 assertTrue (destination .exists (), "Check Exist" );
11531152 assertEquals (testFile1Size , destination .length (), "Check Full copy" );
1154- /* disabled: Thread.sleep doesn't work reliantly for this case
1155- assertTrue("Check last modified date preserved",
1156- testFile1.lastModified() == destination.lastModified());*/
1153+ assertEquals (testFile1 .lastModified (), destination .lastModified (), "Check last modified date preserved" );
11571154 }
11581155
11591156 @ Test
@@ -1196,15 +1193,12 @@ public void testCopyFileLarge() throws Exception {
11961193 public void testCopyFile2 () throws Exception {
11971194 final File destination = new File (temporaryFolder , "copy2.txt" );
11981195
1199- //Thread.sleep(LAST_MODIFIED_DELAY);
1200- //This is to slow things down so we can catch if
1201- //the lastModified date is not ok
1196+ backDateFile (testFile1 ); // set test file back 10 minutes
12021197
12031198 FileUtils .copyFile (testFile1 , destination );
12041199 assertTrue (destination .exists (), "Check Exist" );
12051200 assertEquals (testFile2Size , destination .length (), "Check Full copy" );
1206- /* disabled: Thread.sleep doesn't work reliably for this case
1207- assertTrue(testFile1.lastModified() == destination.lastModified(), "Check last modified date preserved");*/
1201+ assertEquals (testFile1 .lastModified () , destination .lastModified (), "Check last modified date preserved" );
12081202 }
12091203
12101204 @ Test
@@ -1225,16 +1219,15 @@ public void testCopyToSelf() throws Exception {
12251219 public void testCopyFile2WithoutFileDatePreservation () throws Exception {
12261220 final File destination = new File (temporaryFolder , "copy2.txt" );
12271221
1228- //Thread.sleep(LAST_MODIFIED_DELAY);
1229- //This is to slow things down so we can catch if
1230- //the lastModified date is not ok
1222+ backDateFile (testFile1 ); // set test file back 10 minutes
12311223
1224+ final long now = new Date ().getTime ()-1000L ; // destination file time should not be less than this (allowing for granularity)
12321225 FileUtils .copyFile (testFile1 , destination , false );
12331226 assertTrue (destination .exists (), "Check Exist" );
12341227 assertEquals (testFile2Size , destination .length (), "Check Full copy" );
1235- /* disabled: Thread.sleep doesn't work reliantly for this case
1236- assertTrue( "Check last modified date modified",
1237- testFile1.lastModified() != destination.lastModified());*/
1228+ final long destLastMod = destination . lastModified ();
1229+ assertNotEquals ( testFile1 . lastModified (), destLastMod , "Check last modified date not same as input" );
1230+ assertTrue ( destLastMod > now , destLastMod + " > " + now );
12381231 }
12391232
12401233 @ Test
@@ -3083,6 +3076,12 @@ public void testIncorrectOutputSize() throws Exception {
30833076 }
30843077 }
30853078
3079+ private void backDateFile (File testFile ){
3080+ final long mins10 = 1000 *60 *10 ;
3081+ final long lastModified1 = testFile .lastModified ();
3082+ testFile .setLastModified (lastModified1 -mins10 );
3083+ assertNotEquals (testFile .lastModified (), lastModified1 , "Should have changed source date" ); // ensure it was changed
3084+ }
30863085 /**
30873086 * DirectoryWalker implementation that recursively lists all files and directories.
30883087 */
0 commit comments