### Question:
Rank { public boolean hasPermission(String permission) { return operator || permissions.contains(permission) || child != null && child.hasPermission(permission); }  boolean hasPermission(String permission);  }### Answer:
@Test public void whenHierarchyHasPermission() { Rank a = createRank("a"); Rank b = createRank("b"); Rank c = createRank("c"); Rank d = createRank("d"); d.setChild(c); c.setChild(b); b.setChild(a); assertTrue(d.hasPermission("perm.a.a")); assertTrue(c.hasPermission("perm.a.b")); assertTrue(d.hasPermission("perm.d.a")); assertTrue(b.hasPermission("perm.a.a")); assertTrue(b.hasPermission("perm.a.b")); assertFalse(b.hasPermission("perm.c.a.a")); assertFalse(b.hasPermission("perm.c.a.b")); }
@Test public void whenOpHasPermission() { Rank op = new Rank(true, "name", "pref", Collections.emptySet()); assertTrue(op.hasPermission("ANY")); }