Skip to content

Commit 8290adf

Browse files
author
Stephen Colebourne
committed
Fix tests to handle last modified date behaviour on Win2k
bug 38130, from Niall Pemberton git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@369049 13f79535-47bb-0310-9956-ffa450edef68
1 parent 22db7fe commit 8290adf

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/test/org/apache/commons/io/FileUtilsFileNewerTestCase.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2003,2004 The Apache Software Foundation.
2+
* Copyright 2003-2006 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,11 +67,11 @@ public void testIsFileNewer() {
6767
throw new IllegalStateException("The m_testFile1 should exist");
6868

6969
long fileLastModified = m_testFile1.lastModified();
70-
final long ONE_SECOND = 1000;
70+
final long TWO_SECOND = 2000;
7171

72-
testIsFileNewer("one second earlier is not newer" , m_testFile1, fileLastModified + ONE_SECOND, false);
72+
testIsFileNewer("two second earlier is not newer" , m_testFile1, fileLastModified + TWO_SECOND, false);
7373
testIsFileNewer("same time is not newer" , m_testFile1, fileLastModified, false);
74-
testIsFileNewer("one second later is newer" , m_testFile1, fileLastModified - ONE_SECOND, true);
74+
testIsFileNewer("two second later is newer" , m_testFile1, fileLastModified - TWO_SECOND, true);
7575
}
7676

7777
/**
@@ -86,7 +86,7 @@ public void testIsFileNewerImaginaryFile() {
8686
if (imaginaryFile.exists())
8787
throw new IllegalStateException("The imaginary File exists");
8888

89-
testIsFileNewer("imaginary file can be newer" , imaginaryFile, 0, false);
89+
testIsFileNewer("imaginary file can be newer" , imaginaryFile, m_testFile2.lastModified(), false);
9090
}
9191

9292
/**
@@ -118,8 +118,7 @@ protected void testIsFileNewer(String description, File file, long time, boolean
118118
File temporaryFile = m_testFile2;
119119

120120
temporaryFile.setLastModified(time);
121-
if (temporaryFile.lastModified() != time)
122-
throw new IllegalStateException("The temporary file hasn't the right last modification date");
121+
assertEquals("The temporary file hasn't the right last modification date", time, temporaryFile.lastModified());
123122
assertEquals(description + " - file", wantedResult, FileUtils.isFileNewer(file, temporaryFile));
124123
}
125124

src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public void testMakeSVNAware() throws Exception {
461461
public void testAgeFilter() throws Exception {
462462
File oldFile = new File(getTestDirectory(), "old.txt");
463463
createFile(oldFile, 0);
464-
spin();
464+
spin(oldFile.lastModified());
465465
long now = System.currentTimeMillis();
466466
IOFileFilter filter1 = FileFilterUtils.ageFileFilter(now);
467467
IOFileFilter filter2 = FileFilterUtils.ageFileFilter(now, true);
@@ -475,7 +475,7 @@ public void testAgeFilter() throws Exception {
475475
IOFileFilter filter7 = FileFilterUtils.ageFileFilter(reference);
476476
IOFileFilter filter8 = FileFilterUtils.ageFileFilter(reference, true);
477477
IOFileFilter filter9 = FileFilterUtils.ageFileFilter(reference, false);
478-
spin();
478+
spin(reference.lastModified());
479479
File newFile = new File(getTestDirectory(), "new.txt");
480480
createFile(newFile, 0);
481481

@@ -523,8 +523,7 @@ public void testSizeFilter() throws Exception {
523523
}
524524
}
525525

526-
private void spin() {
527-
long now = System.currentTimeMillis();
526+
private void spin(long now) {
528527
while (System.currentTimeMillis() <= now);
529528
}
530529

0 commit comments

Comments
 (0)