@Test public void shouldAcquireSchemaReadLockBeforeRetrievingConstraintsByLabel() throws Exception { // given SchemaReadOperations delegate = mock(SchemaReadOperations.class); @SuppressWarnings("unchecked") Iterator<UniquenessConstraint> constraints = mock(Iterator.class); when(delegate.constraintsGetForLabel(state, 123)).thenReturn(constraints); LockingStatementOperations context = new LockingStatementOperations(null, delegate, null, null); // when Iterator<UniquenessConstraint> result = context.constraintsGetForLabel(state, 123); // then assertEquals(constraints, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaReadLock(); order.verify(delegate).constraintsGetForLabel(state, 123); verifyNoMoreInteractions(lockHolder, delegate); }