### Question:
AuthorizationHelper { public static String resolveLoginAliasToUserName(String loginAlias) { ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); if (attr != null && attr.getAttribute(loginAlias, RequestAttributes.SCOPE_SESSION) != null) { return (String)attr.getAttribute(loginAlias, RequestAttributes.SCOPE_SESSION); } return loginAlias; }  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 testResolveLoginAliasToUserName() throws Exception { reset(servletRequestAttributes); RequestContextHolder.setRequestAttributes(servletRequestAttributes); expect(servletRequestAttributes.getAttribute(eq("loginAlias1"), eq(RequestAttributes.SCOPE_SESSION))) .andReturn("user1").atLeastOnce(); replay(servletRequestAttributes); String user = AuthorizationHelper.resolveLoginAliasToUserName("loginAlias1"); verify(servletRequestAttributes); assertEquals("user1", user); }
@Test public void testResolveNoLoginAliasToUserName() throws Exception { reset(servletRequestAttributes); RequestContextHolder.setRequestAttributes(null); assertEquals("user", AuthorizationHelper.resolveLoginAliasToUserName("user")); RequestContextHolder.setRequestAttributes(servletRequestAttributes); expect(servletRequestAttributes.getAttribute(eq("nosuchalias"), eq(RequestAttributes.SCOPE_SESSION))) .andReturn(null).atLeastOnce(); replay(servletRequestAttributes); String user = AuthorizationHelper.resolveLoginAliasToUserName("nosuchalias"); verify(servletRequestAttributes); assertEquals("nosuchalias", user); }