SocialAuthenticationService<Object> authService = mock(SocialAuthenticationService.class);
ConnectionRepository connectionRepository = mock(ConnectionRepository.class);
ConnectionFactory<Object> connectionFactory = mock(MockConnectionFactory.class);
MockHttpServletRequest request = new MockHttpServletRequest();
ConnectionData data = new ConnectionData("dummyprovider", "1234", null, null, null, null, null, null, null);
String userId = "joe";
DummyConnection<Object> connection = DummyConnection.dummy(data.getProviderId(), userId);
when(usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), set(data.getProviderUserId()))).thenReturn(empty(String.class));
when(usersConnectionRepository.createConnectionRepository(userId)).thenReturn(connectionRepository);
when(authService.getConnectionCardinality()).thenReturn(ConnectionCardinality.ONE_TO_ONE);
when(authService.getConnectionFactory()).thenReturn(connectionFactory);
when(authService.getConnectionAddedRedirectUrl(request, connection)).thenReturn("/redirect");