@Test
public void testConnectionConfigurator() throws Exception {

  HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
  Mockito.when(conn.getResponseCode()).
      thenReturn(HttpURLConnection.HTTP_UNAUTHORIZED);
  ConnectionConfigurator connConf =
      Mockito.mock(ConnectionConfigurator.class);
  Mockito.when(connConf.configure(Mockito.<HttpURLConnection>any())).
      thenReturn(conn);
  Authenticator authenticator = Mockito.mock(Authenticator.class);
  AuthenticatedURL aURL = new AuthenticatedURL(authenticator, connConf);
  aURL.openConnection(new URL("http://foo"), new AuthenticatedURL.Token());
  Mockito.verify(connConf).configure(Mockito.<HttpURLConnection>any());
}