GraphLock { public void checkHoldWriteLock() { if (!readWriteLock.isWriteLockedByCurrentThread()) { throw new IllegalMonitorStateException( "Impossible to perform a write operation without lock. Wrap your code with a write lock to solve this."); } } GraphLock(); void readLock(); void readUnlock(); void readUnlockAll(); void writeLock(); void writeUnlock(); void checkHoldWriteLock();  }
@Test public void testCheckHoldWriteLock() { GraphLock lock = new GraphLock(); lock.writeLock(); lock.checkHoldWriteLock(); }
@Test(expectedExceptions = IllegalMonitorStateException.class) public void testCheckHoldWriteLockFail() { GraphLock lock = new GraphLock(); lock.checkHoldWriteLock(); }