Remove irrelevant test

The test `testCompareNewWithOldAfterCopy` does
not work on linux/unix unless a `Thread.sleep`
is added before the file copying (see cbcf28c3).

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).
This commit is contained in:
Mahmoud Ben Hassine
2021-02-05 16:28:13 +01:00
parent 2cc807de62
commit 329457e672

View File

@@ -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.
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class LastModifiedResourceComparatorTests {
@@ -58,23 +59,4 @@ public class LastModifiedResourceComparatorTests {
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)));
}
}