### Question:
MappingTools { public static Map<String, Set<String>> asMap(final Collection<RoleMapping> mappings) { requireNonNull(mappings); return mappings.stream().collect(toConcurrentMap(RoleMapping::getRoleName, RoleMapping::getPrivilegeNames)); } private  MappingTools(); static Set<String> getPrivilegeNames(final Collection<RoleMapping> mappings); static Set<String> getRoleNames(final Collection<RoleMapping> mappings); static Map<String, Set<String>> asMap(final Collection<RoleMapping> mappings);  }### Answer:
@Test public void testAsMapEmpty() { final Map<String, Set<String>> result = asMap(Collections.emptySet()); assertThat(result.isEmpty(), is(true)); }
@Test(expected = NullPointerException.class) public void testAsMapNull() { asMap(null); fail(); }
@Test public void testAsMap() { final Map<String, Set<String>> result = asMap(mappings); final Set<String> privileges = result.get(role.getName()); assertThat(result.size(), is(1)); assertThat(privileges, is(not(nullValue()))); assertThat(privileges, hasItem(privilege1.getName())); assertThat(privileges, hasItem(privilege2.getName())); }