@Override
  protected void setupPrincipalExists(KerberosOperationHandler handler, boolean service) throws Exception {
    SearchResult result = createMock(SearchResult.class);
    expect(result.getNameInNamespace()).andReturn("user/service dn").anyTimes();

    NamingEnumeration<SearchResult> results = createMock(NamingEnumeration.class);
    results.close();
    expectLastCall().anyTimes();
    expect(results.hasMore()).andReturn(true).once();
    expect(results.next()).andReturn(result).once();
    expect(results.hasMore()).andReturn(false).anyTimes();

    expect(ldapContext.search(anyObject(Name.class), anyString(), anyObject(SearchControls.class)))
        .andReturn(results)
        .anyTimes();
    ldapContext.close();
    expectLastCall().once();
  }
Implementation to illustrate the use of operations on this class

@throws Throwable
ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/ADKerberosOperationHandlerTest.java