Roles { public static Role toRole(String value) { String[] parts = value.split("\\."); if (parts.length == 1 && parts[0].equals("hostedOperator")) return Role.hostedOperator(); if (parts.length == 1 && parts[0].equals("hostedSupporter")) return Role.hostedSupporter(); if (parts.length == 1 && parts[0].equals("hostedAccountant")) return Role.hostedAccountant(); if (parts.length == 2) return toRole(TenantName.from(parts[0]), parts[1]); if (parts.length == 3) return toRole(TenantName.from(parts[0]), ApplicationName.from(parts[1]), parts[2]); throw new IllegalArgumentException("Malformed or illegal role value '" + value + "'."); } private  Roles(); static List<TenantRole> tenantRoles(TenantName tenant); static List<ApplicationRole> applicationRoles(TenantName tenant, ApplicationName application); static Role toRole(String value); static Role toRole(TenantName tenant, String roleName); static Role toRole(TenantName tenant, ApplicationName application, String roleName); static String valueOf(Role role);  }
@Test(expected = IllegalArgumentException.class) public void illegalRoleValue() { Roles.toRole("my-tenant.awesomePerson"); }
@Test(expected = IllegalArgumentException.class) public void illegalCombination() { Roles.toRole("my-tenant.my-application.tenantOwner"); }
@Test(expected = IllegalArgumentException.class) public void illegalValue() { Roles.toRole("everyone"); }