CookieManager implements CookieJar { @Override public List<Cookie> loadForRequest(HttpUrl url) { List<Cookie> matchingCookies = new ArrayList<>(); Iterator<Map.Entry<String, Cookie>> iterator = store.entrySet().iterator(); while (iterator.hasNext()) { Cookie cookie = iterator.next().getValue(); if (cookie.expiresAt() < System.currentTimeMillis()) { iterator.remove(); } else if (cookie.matches(url)) { matchingCookies.add(cookie); } } return matchingCookies; }  @Override void saveFromResponse(HttpUrl url, List<Cookie> cookies); @Override List<Cookie> loadForRequest(HttpUrl url);  }
@Test void loadForRequest() { HttpUrl url = HttpUrl.get("http: Cookie cookie1 = Cookie.parse(url, "key1=v1; Path=/;"); Cookie cookie2 = Cookie.parse(url, "key2=v2; Domain=localhost; Max-Age=0;"); cookieManager.saveFromResponse(url, List.of(cookie1, cookie2)); List<Cookie> cookies = cookieManager.loadForRequest(url); assertThat(cookies).hasSize(1); assertThat(cookieManager.store).hasSize(1); }