@Test
public void testValidateObject() throws Exception {

    when(dirContextValidatorMock
            .validateDirContext(DirContextType.READ_ONLY, dirContextMock))
            .thenReturn(true);
    final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
    objectFactory.setDirContextValidator(dirContextValidatorMock);
    final boolean valid = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock);
    assertThat(valid).isTrue();
    //Check exception in validator
    DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class);
    when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock))
            .thenThrow(new RuntimeException("Failed to validate"));
    objectFactory.setDirContextValidator(secondDirContextValidatorMock);
    final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock);
    assertThat(valid2).isFalse();
}