### Question:
PolicyFileHiveFactory implements HiveFactory { private String resolveAliases(String raw) { Matcher m = aliasPattern.matcher(raw); StringBuffer buff = new StringBuffer(raw.length() + 30); int index = 0; while (m.find()) { if (m.start() > index) { buff.append(raw.substring(index, m.start())); replaceAlias(raw, m, buff); } else if (m.start() == index) { replaceAlias(raw, m, buff); } else throw new IllegalStateException("These aliases are not supported: " + raw); index = m.end(); } if (index < raw.length()) buff.append(raw.substring(index, raw.length())); String temp = buff.toString(); if (temp.indexOf("${") >= 0) throw new IllegalStateException("Nesting aliases is not supported: " + raw); return temp; } PolicyFileHiveFactory(ActionFactory actionFactory); final boolean addPolicyFile(URL file); final boolean addStream(InputStream stream); final boolean addReader(Reader input); final String getAlias(String key); final String setAlias(String key, String value); final Hive createHive(); final boolean isUsingHiveCache(); final void useHiveCache(boolean useCache); final boolean isCloseInputStreams(); final void setCloseInputStreams(boolean closeInputStreams);  }### Answer:
@Test public void testResolveAliases() { try { Method method = PolicyFileHiveFactory.class.getDeclaredMethod("resolveAliases", new Class[] { String.class }); method.setAccessible(true); PolicyFileHiveFactory factory = new PolicyFileHiveFactory(Actions.getActionFactory(KEY)); factory.setAlias("foo", "foo"); factory.setAlias("foobar", "foobar"); String result = (String)method.invoke(factory, new Object[] { "${${foo}bar}" }); fail("Unable to detect nested aliases: " + result); } catch (IllegalArgumentException e) { fail(e.getMessage()); } catch (SecurityException e) { fail(e.getMessage()); } catch (IllegalAccessException e) { fail(e.getMessage()); } catch (NoSuchMethodException e) { fail(e.getMessage()); } catch (InvocationTargetException e) { if (e.getCause() instanceof IllegalStateException) { assertTrue(e.getCause().getMessage().toLowerCase().indexOf("nesting") >= 0); } else fail(e.getMessage()); } }