@Test public void shouldAcquireSchemaReadLockBeforeRetrievingIndexRule() throws Exception { // given SchemaReadOperations delegate = mock(SchemaReadOperations.class); @SuppressWarnings("unchecked") Iterator<IndexDescriptor> rules = mock(Iterator.class); when(delegate.indexesGetAll(state)).thenReturn(rules); LockingStatementOperations context = new LockingStatementOperations(null, delegate, null, null); // when Iterator<IndexDescriptor> result = context.indexesGetAll(state); // then assertSame(rules, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaReadLock(); order.verify(delegate).indexesGetAll(state); verifyNoMoreInteractions(lockHolder, delegate); }