@Test
public void testDestroyObject() throws Exception {

    final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
    objectFactory.destroyObject(DirContextType.READ_ONLY, dirContextMock);
    DirContext throwingDirContextMock = Mockito.mock(DirContext.class);
    doThrow(new RuntimeException("Failed to close"))
            .when(throwingDirContextMock).close();
    objectFactory.destroyObject(DirContextType.READ_ONLY, throwingDirContextMock);
    verify(dirContextMock).close();
}