DelegatingLdapContext extends DelegatingDirContext implements LdapContext { public void close() throws NamingException { if (this.delegateLdapContext == null) { return; } super.close(); this.delegateLdapContext = null; } DelegatingLdapContext(KeyedObjectPool<Object,Object> keyedObjectPool,
                                 LdapContext delegateLdapContext, DirContextType dirContextType); LdapContext getDelegateLdapContext(); DirContext getDelegateDirContext(); LdapContext getInnermostDelegateLdapContext(); boolean equals(Object obj); int hashCode(); String toString(); ExtendedResponse extendedOperation(ExtendedRequest request); Control[] getConnectControls(); Control[] getRequestControls(); Control[] getResponseControls(); LdapContext newInstance(Control[] requestControls); void reconnect(Control[] connCtls); void setRequestControls(Control[] requestControls); void close();  }
@Test public void testDoubleClose() throws Exception { final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext( keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY); delegatingLdapContext.close(); delegatingLdapContext.close(); verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, ldapContextMock); }