Skip to content

Commit

Permalink
Remove irrelevant test
Browse files Browse the repository at this point in the history
The test `testCompareNewWithOldAfterCopy` does
not work on linux/unix unless a `Thread.sleep`
is added before the file copying (see cbcf28c).

This test does not work on windows neither,
because it is based on apache commons
`FileUtils.copyFile` which does not honor
`preserveFileDate=false` on windows.

The following test works on linux/unix
but not on windows:

```
@test
public void testLastModifiedAfterCopy() throws IOException {
    File existing = new FileSystemResource(FILE_PATH).getFile();
    File temp = new File("target/temp.txt");
    assertFalse(temp.exists());
    FileUtils.copyFile(existing, temp, false);
    assertTrue(temp.lastModified() > existing.lastModified());
}
```

On windows, even though `preserveFileDate=false`,
the last modification date of the copy is equal
(ie preserved) to the one of the original file,
which is not the case on linux/unix. Trying to
use an alternative like `java.nio.file.Files#copy`
does not work since it only offers the ability
to either copy file attributes or replace the
existing file (which is not the idea of this test).

This test does not add any value and should have
been removed since a long time (see TODO in 12d6613).
  • Loading branch information
fmbenhassine committed Feb 5, 2021
1 parent 2cc807d commit 329457e
Showing 1 changed file with 2 additions and 20 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@

/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class LastModifiedResourceComparatorTests {
Expand Down Expand Up @@ -58,23 +59,4 @@ public void testCompareNewWithOld() throws IOException {
assertEquals(1, comparator.compare(new FileSystemResource(temp), new FileSystemResource(FILE_PATH)));
}

@Test
public void testCompareNewWithOldAfterCopy() throws Exception {
File temp1 = new File("target/temp1.txt");
File temp2 = new File("target/temp2.txt");
if (temp1.exists()) temp1.delete();
if (temp2.exists()) temp2.delete();
temp1.getParentFile().mkdirs();
temp2.createNewFile();
assertTrue(!temp1.exists() && temp2.exists());
// For Linux sleep here otherwise files show same
// modified date
Thread.sleep(1000);
// Need to explicitly ask not to preserve the last modified date when we
// copy...

FileUtils.copyFile(new FileSystemResource(FILE_PATH).getFile(), temp1, false);
assertEquals(1, comparator.compare(new FileSystemResource(temp1), new FileSystemResource(temp2)));
}

}

0 comments on commit 329457e

Please sign in to comment.