### Question:
ConnectSupport { public Connection<?> completeConnection(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request) { String verifier = request.getParameter("oauth_verifier"); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(extractCachedRequestToken(request), verifier); OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null); return connectionFactory.createConnection(accessToken); } ConnectSupport();  ConnectSupport(SessionStrategy sessionStrategy); void setUseAuthenticateUrl(boolean useAuthenticateUrl); void setApplicationUrl(String applicationUrl); void setCallbackUrl(String callbackUrl); String buildOAuthUrl(ConnectionFactory<?> connectionFactory, NativeWebRequest request); String buildOAuthUrl(ConnectionFactory<?> connectionFactory, NativeWebRequest request, MultiValueMap<String, String> additionalParameters); Connection<?> completeConnection(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request); Connection<?> completeConnection(OAuth2ConnectionFactory<?> connectionFactory, NativeWebRequest request);  }### Answer:
@Test public void completeConnection_OAuth2() { ConnectSupport support = new ConnectSupport(); MockHttpServletRequest mockRequest = new PortAwareMockHttpServletRequest(); mockRequest.addParameter("code", "authorization-grant"); mockRequest.addParameter("state", "STATE"); mockRequest.setScheme("https"); mockRequest.setServerPort(443); mockRequest.setServerName("somesite.com"); mockRequest.setRequestURI("/connect/someprovider"); mockRequest.getSession().setAttribute("oauth2State", "STATE"); ServletWebRequest request = new ServletWebRequest(mockRequest); Connection<?> connection = support.completeConnection(new TestOAuth2ConnectionFactory(), request); assertEquals("TestUser", connection.getDisplayName()); assertEquals("https: assertEquals("https: }
@Test public void completeConnection_OAuth1() { ConnectSupport support = new ConnectSupport(); MockHttpServletRequest mockRequest = new PortAwareMockHttpServletRequest(); mockRequest.addParameter("oauth_verifier", "verifier"); mockRequest.getSession().setAttribute("oauthToken", new OAuthToken("requestToken", "requestTokenSecret")); mockRequest.setScheme("http"); mockRequest.setServerName("somesite.com"); mockRequest.setRequestURI("/connect/someprovider"); ServletWebRequest request = new ServletWebRequest(mockRequest); Connection<?> connection = support.completeConnection(new TestOAuth1ConnectionFactory(OAuth1Version.CORE_10_REVISION_A), request); assertEquals("TestUser", connection.getDisplayName()); assertEquals("https: assertEquals("https: }