### Question:
AuthUtil { public static String getUser(Id id) { AuthenticationProvider provider = ProviderRegistry.getProvider(id.getScheme()); return provider == null ? null : provider.getUserName(id.getId()); } private  AuthUtil(); static String getUser(Id id);  }### Answer:
@Test public void testGetUserFromAllAuthenticationScheme() { String user = "zkUser"; Id id = new Id("digest", user + ":password"); String result = AuthUtil.getUser(id); assertEquals(user, result); String principal = "zkCli/hadoop.hadoop.com"; id = new Id("sasl", principal); assertEquals(principal, AuthUtil.getUser(id)); String ip = "192.168.1.2"; id = new Id("ip", ip); assertEquals(ip, AuthUtil.getUser(id)); String certificate = "CN=host-192.168.1.2,OU=OrganizationUnit,O=Organization,L=Location,ST=State,C=IN"; id = new Id("x509", certificate); assertEquals(certificate, AuthUtil.getUser(id)); }
@Test public void testGetUserShouldReturnNullIfAuthenticationNotConfigured() { Id id = new Id("invalid Authentication Scheme", "user"); String result = AuthUtil.getUser(id); assertNull(result); }