LockManager { void unlock(ILock lock) { Assert.notNull(lock); Assert.isInstanceOf(Lock.class, lock); Lock l = (Lock) lock; if (l.getLockingThread() != Thread.currentThread()) { throw new IllegalStateException("current thread is not lock owner"); } synchronized (locks) { boolean isRegular = locks.values().contains(l); boolean isAll = l == allLock; if (!isRegular && !isAll) { throw new IllegalStateException("unknown lock"); } int newUseCount = l.decreaseUseCount(); if (newUseCount == 0) { if (isRegular) { locks.values().remove(l); } else { allLock = null; } } locks.notifyAll(); } }    }
@Test public void unlockWithUnknownLock() { Lock lock = new Lock(Thread.currentThread()); expectedException.expect(IllegalStateException.class); lockManager.unlock(lock); }