### Question:
RoleMapper { public Set<GrantedAuthority> mapRolesToGrantedAuthority(final Collection<String> roles) { final Function<String, GrantedAuthority> privilegeConverter; if (springRoles) { privilegeConverter = p -> new SimpleGrantedAuthority(SPRING_ROLE_PREFIX + p); } else { privilegeConverter = SimpleGrantedAuthority::new; } return mapRolesToPrivileges(roles, privilegeConverter); } RoleMapper(final Supplier<Map<String, Set<String>>> mappingSupplier); Set<GrantedAuthority> mapRolesToGrantedAuthority(final Collection<String> roles); Set<T> mapRolesToPrivileges(final Collection<String> roles,
			final Function<String, ? extends T> converter); boolean isSpringRoles(); void setSpringRoles(final boolean springRoles);  }### Answer:
@Test(expected = NullPointerException.class) public void testMissingUser() { roleMapper.mapRolesToGrantedAuthority(null); fail(); }
@Test public void testLoadUserWithPrivileges() { final Set<GrantedAuthority> authorities = roleMapper.mapRolesToGrantedAuthority(asList("USER_WITH_PRIVILEGES_ROLE")); assertThat(authorities, hasItem(new SimpleGrantedAuthority("ROLE_PRIVILEGE"))); }
@Test public void testLoadUserWithoutPrivileges() { final Set<GrantedAuthority> authorities = roleMapper .mapRolesToGrantedAuthority(asList("USER_WITHOUT_PRIVILEGES_ROLE")); assertThat(authorities.isEmpty(), is(true)); }
@Test public void testLoadUserWithoutMapping() { final Set<GrantedAuthority> authorities = roleMapper.mapRolesToGrantedAuthority(asList("USER_WITHOUT_MAPPING")); assertThat(authorities.isEmpty(), is(true)); }
@Test public void testLoadUserWithMultipleRoles() { final Set<GrantedAuthority> authorities = roleMapper.mapRolesToGrantedAuthority(asList("ROLE1", "ROLE2")); assertThat(authorities.size(), is(3)); assertThat(authorities, hasItem(new SimpleGrantedAuthority("ROLE_PRIVILEGE1"))); assertThat(authorities, hasItem(new SimpleGrantedAuthority("ROLE_PRIVILEGE2"))); assertThat(authorities, hasItem(new SimpleGrantedAuthority("ROLE_PRIVILEGE3"))); }