### Question:
ActiveMQWildcardPermission extends WildcardPermission { @Override public boolean implies(Permission p) { if (!(p instanceof WildcardPermission)) { return false; } WildcardPermission wp = (WildcardPermission) p; List<Set<String>> otherParts = getParts(wp); int i = 0; for (Set<String> otherPart : otherParts) { if (getParts().size() - 1 < i) { return true; } else { Set<String> thisPart = getParts().get(i); for (String token : thisPart) { if (token.equals(WILDCARD_TOKEN)) { continue; } for (String otherToken : otherPart) { if (!caseSensitive) { otherToken = otherToken.toLowerCase(); } if (!matches(token, otherToken)) { return false; } } } i++; } } for (; i < getParts().size(); i++) { Set<String> part = getParts().get(i); if (!part.contains(WILDCARD_TOKEN)) { return false; } } return true; } ActiveMQWildcardPermission(String wildcardString);  ActiveMQWildcardPermission(String wildcardString, boolean caseSensitive); @Override boolean implies(Permission p); @Override String toString();  }### Answer:
@Test public void testNotWildcardPermission() { ActiveMQWildcardPermission perm = new ActiveMQWildcardPermission("topic:TEST:*"); Permission dummy = new Permission() { @Override public boolean implies(Permission p) { return false; } }; assertFalse(perm.implies(dummy)); }
@Test public void testIntrapartWildcard() { ActiveMQWildcardPermission superset = new ActiveMQWildcardPermission("topic:ActiveMQ.Advisory.*:read"); ActiveMQWildcardPermission subset = new ActiveMQWildcardPermission("topic:ActiveMQ.Advisory.Topic:read"); assertTrue(superset.implies(subset)); assertFalse(subset.implies(superset)); }
@Test(expected=IllegalStateException.class) public void testGetPartsByReflectionThrowingException() { ActiveMQWildcardPermission perm = new ActiveMQWildcardPermission("foo:bar") { @Override protected List<Set<String>> doGetPartsByReflection(WildcardPermission wp) throws Exception { throw new RuntimeException("Testing failure"); } }; WildcardPermission otherPerm = new WildcardPermission("foo:bar:baz"); perm.implies(otherPerm); }
@Test public void testImpliesWithExtraParts() { ActiveMQWildcardPermission perm1 = new ActiveMQWildcardPermission("foo:bar:baz"); ActiveMQWildcardPermission perm2 = new ActiveMQWildcardPermission("foo:bar"); assertFalse(perm1.implies(perm2)); }