### Question:
LogSearchLdapAuthorityMapper implements GrantedAuthoritiesMapper { @Override public Collection<? extends GrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthority> authorities) { if (!groupRoleMap.isEmpty() && !authorities.isEmpty()) { List<SimpleGrantedAuthority> newAuthorities = new ArrayList<>(); for (GrantedAuthority authority : authorities) { String withoutRoleStringLowercase = StringUtils.removeStart(authority.toString(), ROLE_PREFIX).toLowerCase(); String withoutRoleStringUppercase = StringUtils.removeStart(authority.toString(), ROLE_PREFIX).toUpperCase(); String simpleRoleLowercaseString = authority.toString().toLowerCase(); String simpleRoleUppercaseString = authority.toString().toUpperCase(); if (addAuthoritiy(newAuthorities, withoutRoleStringLowercase)) continue; if (addAuthoritiy(newAuthorities, withoutRoleStringUppercase)) continue; if (addAuthoritiy(newAuthorities, simpleRoleLowercaseString)) continue; addAuthoritiy(newAuthorities, simpleRoleUppercaseString); } return newAuthorities; } return authorities; } LogSearchLdapAuthorityMapper(Map<String, String> groupRoleMap); @Override Collection<? extends GrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthority> authorities);  }### Answer:
@Test public void testSimpleMapping() { Map<String, String> roleGroupMapping = new HashMap<>(); roleGroupMapping.put("apache1", "ROLE_USER"); LogSearchLdapAuthorityMapper underTest = new LogSearchLdapAuthorityMapper(roleGroupMapping); List<GrantedAuthority> result = new ArrayList<>(underTest.mapAuthorities(generateAuthorities())); assertEquals("ROLE_USER", result.get(0).toString()); }
@Test public void testSimpleMappingWithoutRolePrefix() { Map<String, String> roleGroupMapping = new HashMap<>(); roleGroupMapping.put("apache1", "USER"); LogSearchLdapAuthorityMapper underTest = new LogSearchLdapAuthorityMapper(roleGroupMapping); List<GrantedAuthority> result = new ArrayList<>(underTest.mapAuthorities(generateAuthorities())); assertEquals("ROLE_USER", result.get(0).toString()); }
@Test public void testMultipleToTheSameMapping() { Map<String, String> roleGroupMapping = new HashMap<>(); roleGroupMapping.put("apache1", "ROLE_USER"); roleGroupMapping.put("APACHE2", "ROLE_USER"); roleGroupMapping.put("role_apache3", "ROLE_USER"); roleGroupMapping.put("ROLE_APACHE4", "ROLE_USER"); LogSearchLdapAuthorityMapper underTest = new LogSearchLdapAuthorityMapper(roleGroupMapping); List<GrantedAuthority> result = new ArrayList<>(underTest.mapAuthorities(generateAuthorities())); assertEquals("ROLE_USER", result.get(0).toString()); assertEquals(1, result.size()); }
@Test public void testMultipleRoles() { Map<String, String> roleGroupMapping = new HashMap<>(); roleGroupMapping.put("apache1", "ROLE_USER"); roleGroupMapping.put("APACHE2", "ROLE_ADMIN"); LogSearchLdapAuthorityMapper underTest = new LogSearchLdapAuthorityMapper(roleGroupMapping); List<GrantedAuthority> result = new ArrayList<>(underTest.mapAuthorities(generateAuthorities())); assertEquals(2, result.size()); }