From 5c08b066224505403f10c69acc85ad5416fa4a96 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 23 Jan 2012 10:19:08 +1100 Subject: [PATCH] improved test --- .../org/eclipse/jetty/util/DateCacheTest.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java index 15284fd2493..76a061dbe1c 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import java.util.Locale; import java.util.TimeZone; @@ -69,12 +70,26 @@ public class DateCacheTest // Test string is cached dc = new DateCache(); - String s1=dc.format(System.currentTimeMillis()); - dc.format(1); - String s2=dc.format(System.currentTimeMillis()); - dc.format(System.currentTimeMillis()+10*60*60); - String s3=dc.format(System.currentTimeMillis()); - assertTrue(s1==s2 || s2==s3); + long now = 1000L*(System.currentTimeMillis()%1000L)+123; + // format a time for now + String s1=dc.format(now); + + // format a time in the past (this should not reset cached date) + dc.format(now-2000); + + // format a time a little later than now + String s2=dc.format(now+10); + + // format a time in future (this should reset cached data) + dc.format(now+2000); + + // format time a little later than now + String s3=dc.format(now+20); + + assertEquals(s1,s2); + assertEquals(s2,s3); + assertTrue(s1==s2); + assertFalse(s2==s3); } }