Code example for HttpCookie

Methods: getMaxAge, hasExpired

0
        Locale.setDefault(Locale.KOREA);
        list = HttpCookie
                .parse("Set-Cookie:name=test;max-age=1234;expires=Sun, 30-Oct-2005 19:14:07 GMT;");
        cookie = list.get(0);
        assertEquals(0, cookie.getVersion());
        assertEquals(1234, cookie.getMaxAge());
        assertFalse(cookie.hasExpired());
 
        Locale.setDefault(Locale.TAIWAN);
        list = HttpCookie
                .parse("Set-Cookie:name=test;expires=Sun, 30-Oct-2005 19:14:07 GMT;max-age=-12345;");
        cookie = list.get(0);
        assertEquals(0, cookie.getMaxAge());
        assertTrue(cookie.hasExpired());
 
        // Locale does not affect version 1 cookie. 
        Locale.setDefault(Locale.ITALIAN);
        list = HttpCookie.parse("Set-Cookie2:name=test;max-age=1000");
        cookie = list.get(0);
        assertEquals(1000, cookie.getMaxAge());
        assertFalse(cookie.hasExpired());