### Question:
AuthorizationUtils { public static void throwAuthorizationFailure(Set<String> challenges) { throwAuthorizationFailure(challenges, null); } private  AuthorizationUtils(); static String[] getBasicAuthUserInfo(MessageContext mc); static String[] getBasicAuthParts(String basicAuthData); static String[] getAuthorizationParts(MessageContext mc); static String[] getAuthorizationParts(MessageContext mc,
                                                 Set<String> challenges); static String[] getAuthorizationParts(MessageContext mc,
                                                 Set<String> challenges,
                                                 String realm); static void throwAuthorizationFailure(Set<String> challenges); static void throwAuthorizationFailure(Set<String> challenges, String realm); static void throwAuthorizationFailure(Set<String> challenges, String realm, Throwable cause);  }### Answer:
@Test public void testThrowAuthorizationFailureSingleChallenge() { try { AuthorizationUtils.throwAuthorizationFailure(Collections.singleton("Basic")); fail("WebApplicationException expected"); } catch (WebApplicationException ex) { Response r = ex.getResponse(); assertEquals(401, r.getStatus()); Object value = r.getMetadata().getFirst(HttpHeaders.WWW_AUTHENTICATE); assertNotNull(value); assertEquals("Basic", value.toString()); } }
@Test public void testThrowAuthorizationFailureManyChallenges() { Set<String> challenges = new LinkedHashSet<>(Arrays.asList("Basic", "Bearer", "*")); try { AuthorizationUtils.throwAuthorizationFailure(challenges); fail("WebApplicationException expected"); } catch (WebApplicationException ex) { Response r = ex.getResponse(); assertEquals(401, r.getStatus()); String value = r.getHeaderString(HttpHeaders.WWW_AUTHENTICATE); assertNotNull(value); assertEquals("Basic,Bearer", value); } }
@Test public void testThrowAuthorizationFailureNoChallenge() { try { AuthorizationUtils.throwAuthorizationFailure(Collections.emptySet()); fail("WebApplicationException expected"); } catch (WebApplicationException ex) { Response r = ex.getResponse(); assertEquals(401, r.getStatus()); Object value = r.getMetadata().getFirst(HttpHeaders.WWW_AUTHENTICATE); assertNull(value); } }
@Test public void testThrowAuthorizationFailureWithCause() { try { AuthorizationUtils.throwAuthorizationFailure(Collections.singleton("Basic"), null, new RuntimeException("expired token")); fail("WebApplicationException expected"); } catch (WebApplicationException ex) { Response r = ex.getResponse(); assertEquals("expired token", r.getEntity()); assertEquals(401, r.getStatus()); Object value = r.getMetadata().getFirst(HttpHeaders.WWW_AUTHENTICATE); assertNotNull(value); assertEquals("Basic", value.toString()); } }