DelegatingDirContext extends DelegatingContext implements DirContext, DirContextProxy { public void close() throws NamingException { if (this.delegateDirContext == null) { return; } super.close(); this.delegateDirContext = null; } DelegatingDirContext(KeyedObjectPool keyedObjectPool, DirContext delegateDirContext, DirContextType dirContextType); DirContext getDelegateDirContext(); Context getDelegateContext(); DirContext getInnermostDelegateDirContext(); boolean equals(Object obj); int hashCode(); String toString(); DirContext getTargetContext(); void bind(Name name, Object obj, Attributes attrs); void bind(String name, Object obj, Attributes attrs); DirContext createSubcontext(Name name, Attributes attrs); DirContext createSubcontext(String name, Attributes attrs); Attributes getAttributes(Name name, String[] attrIds); Attributes getAttributes(Name name); Attributes getAttributes(String name, String[] attrIds); Attributes getAttributes(String name); DirContext getSchema(Name name); DirContext getSchema(String name); DirContext getSchemaClassDefinition(Name name); DirContext getSchemaClassDefinition(String name); void modifyAttributes(Name name, int modOp, Attributes attrs); void modifyAttributes(Name name, ModificationItem[] mods); void modifyAttributes(String name, int modOp, Attributes attrs); void modifyAttributes(String name, ModificationItem[] mods); void rebind(Name name, Object obj, Attributes attrs); void rebind(String name, Object obj, Attributes attrs); NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn); NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes); NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons); NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons); NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes, String[] attributesToReturn); NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes); NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs, SearchControls cons); NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons); void close();  }
@Test public void testDoubleClose() throws Exception { final DelegatingDirContext delegatingDirContext = new DelegatingDirContext( keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY); delegatingDirContext.close(); delegatingDirContext.close(); verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, dirContextMock); }