Time Keeps Ticking

September 9, 2013
testing java

A note so that I never forget again: the time used by a ZipEntry instance in Java appears to keep ticking.

ZipEntry entry = new ZipEntry("foo");  
long expected = System.currentTimeMillis();  
entry.setTime(expected);  
Thread.sleep(3000);  
long seen = entry.getTime()  
  
// This fails  
assertEquals(expected, seen);

Update: it turns out that the problem turns out to be that DOS timestamps only store seconds with a precision of 2 seconds. The above could be reduced to:

ZipEntry entry = new ZipEntry("foo");  
  
// Note: we set the seconds to an odd number  
long expected = Calendar.getInstance()  
    .set(2013, SEPTEMBER, 10, 12, 14, 1)  
    .getTimeInMillis();  
entry.setTime(expected);  
long seen = entry.getTime()  
  
// This fails  
assertEquals(expected, seen);  

More on MSDN.

More recently On the Naming of Tests     On Managing Time and Direct Emails About Selenium Less recently

Android: Forking Java by Mistake

February 26, 2015
tech java

The UNIX Philosophy, WebDriver and HTTP Status Codes

June 24, 2013
selenium testing

Why I Care About Automated Testing

May 22, 2013
tech testing