when(factory.getProviderId()).thenReturn(connection.getKey().getProviderId());
when(factory.getOAuthOperations()).thenReturn(operations);
when(factory.createConnection(accessGrant)).thenReturn(connection);
when(
operations.buildAuthenticateUrl(oAuth2Parameters("http://example.com/auth/foo?param=param_value"))).thenReturn(
"http://facebook.com/auth");
when(operations.exchangeForAccess(code, "http://example.com/auth/foo", null)).thenReturn(accessGrant);
// first phase
MockHttpServletRequest request = new MockHttpServletRequest(context, "GET", "/auth/foo");