DefaultRoleToGroupMapper implements RoleToGroupMapper { @Override public List<String> groupsFromRoles(List<String> roles) { if (template == null || roles == null) { return roles; } else { List<String> renamedRoles = new ArrayList<>(); for (String role : roles) { String renamedRole = template.replace(ROLE_MAPPING_PLACEHOLDER, role); renamedRoles.add(renamedRole); LOG.debug("Mapped role {} to {}", role, renamedRole); } return renamedRoles; } }  @Override void cleanup(); @Override List<String> groupsFromRoles(List<String> roles); @Override void initialize(Properties properties); static final String PROPERTY_KEY_ROLE_MAPPING_TEMPLATE; static final String ROLE_MAPPING_PLACEHOLDER; static final String DEFAULT_MAPPING_TEMPLATE; }
@Test public void testSimpleMapping() { DefaultRoleToGroupMapper mapper = new DefaultRoleToGroupMapper(); List<String> result = mapper.groupsFromRoles(Arrays.asList("Role1", "Role2", "Role3")); assertNotNull(result); assertEquals(3, result.size()); assertEquals("Role1", result.get(0)); assertEquals("Role3", result.get(2)); }
@Test public void testNullMapping() { DefaultRoleToGroupMapper mapper = new DefaultRoleToGroupMapper(); List<String> result = mapper.groupsFromRoles(null); assertNull(result); }
@Test public void testEmptyMapping() { DefaultRoleToGroupMapper mapper = new DefaultRoleToGroupMapper(); List<String> result = mapper.groupsFromRoles(new ArrayList<String>()); assertNotNull(result); assertEquals(0, result.size()); }