### Question:
SocialAuthenticationProvider implements AuthenticationProvider { protected String toUserId(Connection<?> connection) { List<String> userIds = usersConnectionRepository.findUserIdsWithConnection(connection); return (userIds.size() == 1) ? userIds.iterator().next() : null; } SocialAuthenticationProvider(UsersConnectionRepository usersConnectionRepository, SocialUserDetailsService userDetailsService); boolean supports(Class<? extends Object> authentication); Authentication authenticate(Authentication authentication);  }### Answer:
@Test public void toUserId() { UsersConnectionRepository repo = mock(UsersConnectionRepository.class); SocialAuthenticationProvider provider = new SocialAuthenticationProvider(repo, null); Connection<Object> dummyConnection1 = dummyConnection("providerUser1"); Connection<Object> dummyConnection2 = dummyConnection("providerUser2"); Mockito.when(repo.findUserIdsWithConnection(dummyConnection1)).thenReturn(list("user1")); Mockito.when(repo.findUserIdsWithConnection(dummyConnection2)).thenReturn(list("user1", "user2")); assertEquals("user1", provider.toUserId(dummyConnection1)); assertNull(provider.toUserId(dummyConnection2)); }