### Question:
CurrentUser { public static void proxyDoAsUser(final String doAsUser, final String proxyHost) { if (!isAuthenticated()) { throw new IllegalStateException("Authentication not done"); } String currentUser = CURRENT_USER.get().authenticatedUser; if (StringUtils.isNotEmpty(doAsUser) && !doAsUser.equalsIgnoreCase(currentUser)) { if (StringUtils.isEmpty(proxyHost)) { throw new IllegalArgumentException("proxy host cannot be null or empty"); } ProxyUserService proxyUserService = Services.get().getService(ProxyUserService.SERVICE_NAME); try { proxyUserService.validate(currentUser, proxyHost, doAsUser); } catch (IOException ex) { throw new RuntimeException(ex); } CurrentUser user = CURRENT_USER.get(); LOG.info("Authenticated user {} is proxying doAs user {} from host {}", user.authenticatedUser, doAsUser, proxyHost); AUDIT.info("Authenticated user {} is proxying doAs user {} from host {}", user.authenticatedUser, doAsUser, proxyHost); user.proxyUser = doAsUser; } } private  CurrentUser(String authenticatedUser); static void authenticate(final String user); static void proxyDoAsUser(final String doAsUser, final String proxyHost); static void proxy(final String aclOwner, final String aclGroup); static void clear(); static boolean isAuthenticated(); static String getAuthenticatedUser(); static UserGroupInformation getAuthenticatedUGI(); static String getUser(); static UserGroupInformation createProxyUGI(String proxyUser); static UserGroupInformation getProxyUGI(); static Set<String> getGroupNames(); static String getPrimaryGroupName();  }### Answer:
@Test(expectedExceptions = IllegalStateException.class) public void testProxyDoAsUserWithNoAuth() throws Exception { CurrentUser.proxyDoAsUser("falcon", "localhost"); }
@Test public void testProxyDoAsUser() throws Exception { CurrentUser.authenticate("foo"); CurrentUser.proxyDoAsUser(EntityBuilderTestUtil.USER, "localhost"); UserGroupInformation proxyUgi = CurrentUser.getProxyUGI(); Assert.assertNotNull(proxyUgi); Assert.assertEquals(proxyUgi.getUserName(), EntityBuilderTestUtil.USER); Assert.assertEquals(CurrentUser.getAuthenticatedUser(), "foo"); Assert.assertEquals(CurrentUser.getUser(), EntityBuilderTestUtil.USER); }