Fix LastModifiedFileListFilterTests timing issue

https://build.spring.io/browse/INT-AT42SIO-365/

* Fix timing issue with the `LastModifiedFileListFilterTests`, when the `age = 1` might not be enough for the file object when we have some delay before checking
* Get rid of any `Thread.sleep()` in the test via mocking age on the file.

 Cherry-picked from the 4ac3a79df7
This commit is contained in:
Artem Bilan
2016-12-12 09:48:11 -05:00
parent 8fa66ca8ed
commit a3c8b0abbd

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.file.filters;
import static org.junit.Assert.assertEquals;
@@ -27,6 +28,7 @@ import org.junit.rules.TemporaryFolder;
/**
* @author Gary Russell
* @author Artem Bilan
* @since 4.2
*
*/
@@ -38,14 +40,14 @@ public class LastModifiedFileListFilterTests {
@Test
public void testAge() throws Exception {
LastModifiedFileListFilter filter = new LastModifiedFileListFilter();
filter.setAge(10, TimeUnit.SECONDS);
filter.setAge(60, TimeUnit.SECONDS);
File foo = this.folder.newFile();
FileOutputStream fileOutputStream = new FileOutputStream(foo);
fileOutputStream.write("x".getBytes());
fileOutputStream.close();
assertEquals(0, filter.filterFiles(new File[] { foo }).size());
filter.setAge(50, TimeUnit.MILLISECONDS);
Thread.sleep(100);
// Make a file as of yesterday's
foo.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
assertEquals(1, filter.filterFiles(new File[] { foo }).size());
}