Code example for CookieManager

0
public class CookiesTest extends TestCase {
 
    private static final Map<String, List<String>> EMPTY_COOKIES_MAP = Collections.emptyMap();
 
    public void testNetscapeResponse() throws Exception { 
        CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
        CookieHandler.setDefault(cookieManager);
        MockWebServer server = new MockWebServer();
        server.play();
 
        server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; "
                + "expires=Fri, 31-Dec-9999 23:59:59 GMT; " 
                + "path=/path; " 
                + "domain=.local; " 
                + "secure")); 
        get(server, "/path/foo");
 
        List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();
        assertEquals(1, cookies.size());
        HttpCookie cookie = cookies.get(0);
        assertEquals("a", cookie.getName());