CookieManager implements CookieJar { @Override public void saveFromResponse(HttpUrl url, List<Cookie> cookies) { for (Cookie cookie : cookies) { String key = cookie.domain() + ":" + cookie.path() + ":" + cookie.name(); if (cookie.expiresAt() == Long.MIN_VALUE && "".equals(cookie.value())) { store.remove(key); } else { store.put(key, cookie); } } }  @Override void saveFromResponse(HttpUrl url, List<Cookie> cookies); @Override List<Cookie> loadForRequest(HttpUrl url);  }
@Test void saveFromResponse() { HttpUrl url = HttpUrl.get("http: Cookie cookie1 = Cookie.parse(url, "key1=v1; Path=/;"); Cookie cookie2 = Cookie.parse(url, "key2=v2; Domain=localhost; Max-Age=7200;"); cookieManager.saveFromResponse(url, List.of(cookie1, cookie2)); assertThat(cookieManager.store).hasSize(2); cookie1 = Cookie.parse(url, "key1=; Path=/; Max-Age=0;"); cookieManager.saveFromResponse(url, List.of(cookie1)); assertThat(cookieManager.store).hasSize(1); }