### Question:
ConnectController implements InitializingBean { @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="code") public RedirectView oauth2Callback(@PathVariable String providerId, NativeWebRequest request) { try { OAuth2ConnectionFactory<?> connectionFactory = (OAuth2ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId); Connection<?> connection = connectSupport.completeConnection(connectionFactory, request); addConnection(connection, connectionFactory, request); } catch (Exception e) { sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e); logger.warn("Exception while handling OAuth2 callback (" + e.getMessage() + "). Redirecting to " + providerId +" connection status page."); } return connectionStatusRedirect(providerId, request); } @Inject  ConnectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository); @Deprecated void setInterceptors(List<ConnectInterceptor<?>> interceptors); void setConnectInterceptors(List<ConnectInterceptor<?>> interceptors); void setDisconnectInterceptors(List<DisconnectInterceptor<?>> interceptors); void setApplicationUrl(String applicationUrl); void setViewPath(String viewPath); void setConnectionStatusUrlPath(String connectionStatusUrlPath); void setSessionStrategy(SessionStrategy sessionStrategy); void addInterceptor(ConnectInterceptor<?> interceptor); void addDisconnectInterceptor(DisconnectInterceptor<?> interceptor); @RequestMapping(method=RequestMethod.GET) String connectionStatus(NativeWebRequest request, Model model); @RequestMapping(value="/{providerId}", method=RequestMethod.GET) String connectionStatus(@PathVariable String providerId, NativeWebRequest request, Model model); @RequestMapping(value="/{providerId}", method=RequestMethod.POST) RedirectView connect(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="code") RedirectView oauth2Callback(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="error") RedirectView oauth2ErrorCallback(@PathVariable String providerId, 
			@RequestParam("error") String error, 
			@RequestParam(value="error_description", required=false) String errorDescription,
			@RequestParam(value="error_uri", required=false) String errorUri,
			NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.DELETE) RedirectView removeConnections(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}/{providerUserId}", method=RequestMethod.DELETE) RedirectView removeConnection(@PathVariable String providerId, @PathVariable String providerUserId, NativeWebRequest request); void afterPropertiesSet();  }### Answer:
@Test public void oauth2Callback() throws Exception { ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry(); ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret"); connectionFactoryLocator.addConnectionFactory(connectionFactory); StubConnectionRepository connectionRepository = new StubConnectionRepository(); ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository); List<ConnectInterceptor<?>> interceptors = getConnectInterceptor(); connectController.setConnectInterceptors(interceptors); connectController.afterPropertiesSet(); MockMvc mockMvc = standaloneSetup(connectController) .build(); assertEquals(0, connectionRepository.findConnections("oauth2Provider").size()); mockMvc.perform(get("/connect/oauth2Provider").param("code", "oauth2Code").param("state", "STATE").sessionAttr("oauth2State", "STATE")) .andExpect(redirectedUrl("/connect/oauth2Provider")); List<Connection<?>> connections = connectionRepository.findConnections("oauth2Provider"); assertEquals(1, connections.size()); assertEquals("oauth2Provider", connections.get(0).getKey().getProviderId()); assertFalse(((TestConnectInterceptor<?>)(interceptors.get(0))).postConnectInvoked); TestConnectInterceptor<?> testInterceptor2 = (TestConnectInterceptor<?>)(interceptors.get(1)); assertTrue(testInterceptor2.postConnectInvoked); }