### Question:
AuthorizationsUtil { public static Set<Authorizations> mergeAuthorizations(String requestedAuths, Collection<? extends Collection<String>> userAuths) { HashSet<String> requested = null; if (!StringUtils.isEmpty(requestedAuths)) { requested = new HashSet<>(splitAuths(requestedAuths)); } if (null == userAuths) return Collections.singleton(new Authorizations()); HashSet<Authorizations> mergedAuths = new HashSet<>(); HashSet<String> missingAuths = (requested == null) ? new HashSet<>() : new HashSet<>(requested); for (Collection<String> auths : userAuths) { if (null != requested) { missingAuths.removeAll(auths); auths = new HashSet<>(auths); auths.retainAll(requested); } mergedAuths.add(new Authorizations(auths.toArray(new String[auths.size()]))); } if (!missingAuths.isEmpty()) { throw new IllegalArgumentException("User requested authorizations that they don't have. Missing: " + missingAuths + ", Requested: " + requested + ", User: " + userAuths); } return mergedAuths; }  static Authorizations union(Iterable<byte[]> authorizations1, Iterable<byte[]> authorizations2); static Set<Authorizations> mergeAuthorizations(String requestedAuths, Collection<? extends Collection<String>> userAuths); static Set<Authorizations> getDowngradedAuthorizations(String requestedAuths, Principal principal); static LinkedHashSet<Authorizations> getDowngradedAuthorizations(String requestedAuths, DatawavePrincipal principal); static String downgradeUserAuths(Principal principal, String requested); static List<String> splitAuths(String requestedAuths); static Set<Authorizations> buildAuthorizations(Collection<? extends Collection<String>> userAuths); static String buildAuthorizationString(Collection<? extends Collection<String>> userAuths); static String buildUserAuthorizationString(Principal principal); static Collection<Authorizations> minimize(Collection<Authorizations> authorizations); static Collection<? extends Collection<String>> prepareAuthsForMerge(Authorizations authorizations);  }### Answer:
@Test public void testMergeAuthorizations() { HashSet<Authorizations> expected = Sets.newHashSet(new Authorizations("A", "C"), new Authorizations("A")); assertEquals(expected, AuthorizationsUtil.mergeAuthorizations(methodAuths, userAuths)); }
@Test(expected = IllegalArgumentException.class) public void testUserRequestsAuthTheyDontHave() { methodAuths = "A,C,F"; AuthorizationsUtil.mergeAuthorizations(methodAuths, userAuths); fail("Exception not thrown!"); }
@Test public void testMethodAuthsIsNull() { HashSet<Authorizations> expected = new HashSet<>(); for (Set<String> auths : userAuths) { expected.add(new Authorizations(auths.toArray(new String[auths.size()]))); } assertEquals(expected, AuthorizationsUtil.mergeAuthorizations(null, userAuths)); }
@Test public void testUserAuthsIsNull() { assertEquals(Collections.singleton(new Authorizations()), AuthorizationsUtil.mergeAuthorizations(methodAuths, null)); }
@Test public void testBothMethodAndUserAuthsNull() { assertEquals(Collections.singleton(new Authorizations()), AuthorizationsUtil.mergeAuthorizations(null, null)); }