More tolerance in CookieEncoderTest

This commit is contained in:
Trustin Lee 2009-04-16 05:09:03 +00:00
parent f2f09e66aa
commit f61412c828

View File

@ -55,11 +55,21 @@ public class CookieEncoderTest {
String encodedCookie = encoder.encode(); String encodedCookie = encoder.encode();
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
assertTrue( boolean fail = true;
encodedCookie.equals(result.replace("XXX", df.format(new Date(currentTime + 50000)))) || // +/- 10-second tolerance
encodedCookie.equals(result.replace("XXX", df.format(new Date(currentTime + 50750)))) || for (int delta = 0; delta <= 20000; delta += 250) {
encodedCookie.equals(result.replace("XXX", df.format(new Date(currentTime + 49250))))); if (encodedCookie.equals(result.replace(
"XXX", df.format(new Date(currentTime + 40000 + delta))))) {
fail = false;
break;
}
}
if (fail) {
fail("Expected: " + result + ", Actual: " + encodedCookie);
}
} }
@Test @Test
public void testEncodingSingleCookieV1() { public void testEncodingSingleCookieV1() {
String result = "myCookie=myValue;Max-Age=50;Path=\"/apathsomewhere\";Domain=.adomainsomewhere;Secure;Comment=\"this is a Comment\";Version=1"; String result = "myCookie=myValue;Max-Age=50;Path=\"/apathsomewhere\";Domain=.adomainsomewhere;Secure;Comment=\"this is a Comment\";Version=1";