### Question:
RecipientIdentityResolver { public RecipientIdentity toIdentity(String uri) throws IllegalParameterValueException { RecipientIdentity identity; if (uri == null) { throw new IllegalParameterValueException(identifierLabel, "null"); } String[] protocolLevel = uri.split(":"); if (protocolLevel.length != 2) { throw new IllegalParameterValueException(identifierLabel, uri); } String[] segments = protocolLevel[1].split("/"); Class<?> clazz = getClassForProtocol(protocolLevel[0]); if (segments.length == 0 && Tenant.class.isAssignableFrom(clazz)) { return new RecipientIdentity(clazz, TenantService.ORGANIZATIONS); } if (!segments[0].equals("")) { throw new IllegalParameterValueException(identifierLabel, uri); } if (segments.length == 2) { identity = new RecipientIdentity(clazz, segments[1]); } else if (segments.length == 3) { identity = new RecipientIdentity(clazz, makeIdentityId(uri, segments[1], segments[2])); } else { throw new IllegalParameterValueException(identifierLabel, uri); } return identity; }  Class<?> getClassForProtocol(String protocol); String getProtocolForClass(Class<?> clazz); RecipientIdentity toIdentity(String uri); RecipientIdentity toIdentity(Object recipient); String toRecipientUri(Object recipient); String toRecipientUri(RecipientIdentity recipientIdentity); Object resolveRecipientObject(RecipientIdentity recipientIdentity); Object resolveRecipientObject(String uri); void setMap(Map<String, Class<?>> map); void setIdentifierLabel(String identifierLabel); void setRequiredProtocols(Set<String> requiredProtocols);  }### Answer:
@Test public void toIdentity_forExistentUser_success() throws Exception { RecipientIdentity userIdentity = attributesResolver.toIdentity(anonymousUser); assertNotNull(userIdentity); assertEquals(anonymousUser.getUsername(), userIdentity.getId()); assertEquals(User.class, userIdentity.getRecipientClass()); userIdentity = permissionsResolver.toIdentity(anonymousUser); assertNotNull(userIdentity); assertEquals(anonymousUser.getUsername(), userIdentity.getId()); assertEquals(User.class, userIdentity.getRecipientClass()); }
@Test public void toIdentity_forExistentTenant_success() throws Exception { RecipientIdentity tenantIdentity = attributesResolver.toIdentity(tenantRoot); assertNotNull(tenantIdentity); assertEquals(tenantRoot.getId(), tenantIdentity.getId()); assertEquals(Tenant.class, tenantIdentity.getRecipientClass()); }
@Test public void toIdentity_forExistentRole_success() throws Exception { RecipientIdentity roleIdentity = permissionsResolver.toIdentity(roleAdmin); assertNotNull(roleIdentity); assertEquals(roleAdmin.getRoleName(), roleIdentity.getId()); assertEquals(Role.class, roleIdentity.getRecipientClass()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void toIdentity_forFolder_exception() { Folder folder = new FolderImpl(); folder.setName("some_folder"); permissionsResolver.toIdentity(folder); }
@Test(expectedExceptions = IllegalParameterValueException.class) public void toIdentity_forWrongUri1_exception() { permissionsResolver.toIdentity("/users/joeuser"); }
@Test(expectedExceptions = IllegalParameterValueException.class) public void toIdentity_forWrongUri2_exception() { permissionsResolver.toIdentity("users:/joeuser"); }