@Test public void shouldAcquireSchemaWriteLockBeforeAddingIndexRule() throws Exception { // given SchemaWriteOperations delegate = mock(SchemaWriteOperations.class); IndexDescriptor rule = mock(IndexDescriptor.class); when(delegate.indexCreate(state, 123, 456)).thenReturn(rule); LockingStatementOperations context = new LockingStatementOperations(null, null, delegate, null); // when IndexDescriptor result = context.indexCreate(state, 123, 456); // then assertSame(rule, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaWriteLock(); order.verify(delegate).indexCreate(state, 123, 456); verifyNoMoreInteractions(lockHolder, delegate); }