@Test
public void testDoWithSingleContext() {

    when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock);
    verifyNoMoreInteractions(contextSourceMock);
    SingleContextSource.doWithSingleContext(contextSourceMock, new LdapOperationsCallback<Object>() {
        @Override
        public Object doWithLdapOperations(LdapOperations operations) {
            operations.executeReadOnly(new ContextExecutor<Object>() {
                @Override
                public Object executeWithContext(DirContext ctx) throws NamingException {
                    Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target");
                    assertThat(targetContex).isSameAs(dirContextMock);
                    return false;
                }
            });
            // Second operation will have retrieved new DirContext from the SingleContextSource.
            // It should be the same instance.
            operations.executeReadOnly(new ContextExecutor<Object>() {
                @Override
                public Object executeWithContext(DirContext ctx) throws NamingException {
                    Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target");
                    assertThat(targetContex).isSameAs(dirContextMock);
                    return false;
                }
            });
            return null;
        }
    });
}