UserDetailsContextMapperImpl implements UserDetailsContextMapper { @Override public UserDetails mapUserFromContext(DirContextOperations dirContextOperations, String username, Collection<? extends GrantedAuthority> authorities) { logger.debug("Mapping user from context"); User user = getOrCreateUser(dirContextOperations, username); return new UserDetailsImpl(user); }  @Override UserDetails mapUserFromContext(DirContextOperations dirContextOperations, String username, Collection<? extends GrantedAuthority> authorities); @Override void mapUserToContext(UserDetails userDetails, DirContextAdapter dirContextAdapter);  }
@Test public void testMapUserFromContextWhenUserNameIsNotFound() throws Exception { doReturn(mock(User.class)).when(userService).getOrCreateOrUpdateBasicUser("testUsername", "givename", "sn", "cn"); DirContextOperations dirContextOperations = mock(DirContextOperations.class); when(dirContextOperations.getStringAttribute("givenname")).thenReturn("givename"); when(dirContextOperations.getStringAttribute("sn")).thenReturn("sn"); when(dirContextOperations.getStringAttribute("cn")).thenReturn("cn"); UserDetails userDetails = userDetailsContextMapper.mapUserFromContext(dirContextOperations, "testUsername", null); Assert.notNull(userDetails); verify(dirContextOperations, times(3)).getStringAttribute(anyString()); }