From 329457e672366251b2e68909fa05a8575fe2100e Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Fri, 5 Feb 2021 16:28:13 +0100 Subject: [PATCH] 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). --- .../LastModifiedResourceComparatorTests.java | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java index b61261d614..eabbaaffa5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java @@ -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 @@ /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class LastModifiedResourceComparatorTests { @@ -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))); - } - }