AuthenticatedURL { public static void injectToken(HttpURLConnection conn, Token token) { HttpCookie authCookie = token.cookieHandler.getAuthCookie(); if (authCookie != null) { conn.addRequestProperty("Cookie", authCookie.toString()); } } AuthenticatedURL();  AuthenticatedURL(Authenticator authenticator);  AuthenticatedURL(Authenticator authenticator,
                          ConnectionConfigurator connConfigurator); static void setDefaultAuthenticator(Class<? extends Authenticator> authenticator); static Class<? extends Authenticator> getDefaultAuthenticator(); HttpURLConnection openConnection(URL url, Token token); static void injectToken(HttpURLConnection conn, Token token); static void extractToken(HttpURLConnection conn, Token token); static final String AUTH_COOKIE; }
@Test public void testInjectToken() throws Exception { HttpURLConnection conn = Mockito.mock(HttpURLConnection.class); AuthenticatedURL.Token token = new AuthenticatedURL.Token(); token.set("foo"); AuthenticatedURL.injectToken(conn, token); Mockito.verify(conn).addRequestProperty(Mockito.eq("Cookie"), Mockito.anyString()); }