@Test
public void testGetGroupsWithHierarchy() throws NamingException {

  // The search functionality of the mock context is reused, so we will
  // return the user NamingEnumeration first, and then the group
  // The parent search is run once for each level, and is a different search
  // The parent group is returned once for each group, yet the final list
  // should be unique
  when(getContext().search(anyString(), anyString(), any(Object[].class),
      any(SearchControls.class)))
      .thenReturn(getUserNames(), getGroupNames());
  when(getContext().search(anyString(), anyString(),
      any(SearchControls.class)))
      .thenReturn(getParentGroupNames());
  doTestGetGroupsWithParent(Arrays.asList(getTestParentGroups()), 2, 1);
}