### Question:
AuthorizationHelper { public Collection<GrantedAuthority> convertPrivilegesToAuthorities(Collection<PrivilegeEntity> privilegeEntities) { Set<GrantedAuthority> authorities = new HashSet<>(privilegeEntities.size()); for (PrivilegeEntity privilegeEntity : privilegeEntities) { authorities.add(new AmbariGrantedAuthority(privilegeEntity)); } return authorities; }  static String getProxyUserName(Authentication authentication); static String getProxyUserName(); Collection<GrantedAuthority> convertPrivilegesToAuthorities(Collection<PrivilegeEntity> privilegeEntities); static String getAuthenticatedName(); static String getAuthenticatedName(String defaultUsername); static int getAuthenticatedId(); static boolean isAuthorized(ResourceType resourceType, Long resourceId,
                                     RoleAuthorization requiredAuthorization); static boolean isAuthorized(ResourceType resourceType, Long resourceId,
                                     Set<RoleAuthorization> requiredAuthorizations); static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, RoleAuthorization requiredAuthorization); static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, Set<RoleAuthorization> requiredAuthorizations); static void verifyAuthorization(ResourceType resourceType,
                                         Long resourceId,
                                         Set<RoleAuthorization> requiredAuthorizations); static void verifyAuthorization(Authentication authentication,
                                         ResourceType resourceType,
                                         Long resourceId,
                                         Set<RoleAuthorization> requiredAuthorizations); static Authentication getAuthentication(); static void addLoginNameAlias(String ambariUserName, String loginAlias); static String resolveLoginAliasToUserName(String loginAlias); static List<String> getAuthorizationNames(Authentication authentication);  }### Answer:
@Test public void testConvertPrivilegesToAuthorities() throws Exception { Collection<PrivilegeEntity> privilegeEntities = new ArrayList<>(); ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity(); resourceTypeEntity.setId(1); resourceTypeEntity.setName("CLUSTER"); ResourceEntity resourceEntity = new ResourceEntity(); resourceEntity.setId(1L); resourceEntity.setResourceType(resourceTypeEntity); PrincipalTypeEntity principalTypeEntity = new PrincipalTypeEntity(); principalTypeEntity.setId(1); principalTypeEntity.setName("USER"); PrincipalEntity principalEntity = new PrincipalEntity(); principalEntity.setPrincipalType(principalTypeEntity); principalEntity.setId(1L); PermissionEntity permissionEntity1 = new PermissionEntity(); permissionEntity1.setPermissionName("Permission1"); permissionEntity1.setResourceType(resourceTypeEntity); permissionEntity1.setId(2); permissionEntity1.setPermissionName("CLUSTER.USER"); PermissionEntity permissionEntity2 = new PermissionEntity(); permissionEntity2.setPermissionName("Permission1"); permissionEntity2.setResourceType(resourceTypeEntity); permissionEntity2.setId(3); permissionEntity2.setPermissionName("CLUSTER.ADMINISTRATOR"); PrivilegeEntity privilegeEntity1 = new PrivilegeEntity(); privilegeEntity1.setId(1); privilegeEntity1.setPermission(permissionEntity1); privilegeEntity1.setPrincipal(principalEntity); privilegeEntity1.setResource(resourceEntity); PrivilegeEntity privilegeEntity2 = new PrivilegeEntity(); privilegeEntity2.setId(1); privilegeEntity2.setPermission(permissionEntity2); privilegeEntity2.setPrincipal(principalEntity); privilegeEntity2.setResource(resourceEntity); privilegeEntities.add(privilegeEntity1); privilegeEntities.add(privilegeEntity2); Collection<GrantedAuthority> authorities = new AuthorizationHelper().convertPrivilegesToAuthorities(privilegeEntities); assertEquals("Wrong number of authorities", 2, authorities.size()); Set<String> authorityNames = new HashSet<>(); for (GrantedAuthority authority : authorities) { authorityNames.add(authority.getAuthority()); } Assert.assertTrue(authorityNames.contains("CLUSTER.USER@1")); Assert.assertTrue(authorityNames.contains("CLUSTER.ADMINISTRATOR@1")); }