@Test public void testClose() { ReentrantLock lock = new ReentrantLock(); assertFalse(lock.isHeldByCurrentThread()); AutoLock al = new AutoLock(lock); assertFalse(lock.isHeldByCurrentThread()); al.autoLock(); assertTrue(lock.isHeldByCurrentThread()); al.close(); assertFalse(lock.isHeldByCurrentThread()); }
@Test public void testDefault() throws Exception { AutoLock al = new AutoLock(); assertNotNull(al.autoLock()); assertNotNull(al.toString()); assertNotNull(al.newCondition()); al.lockInterruptibly(); al.unlock(); assertTrue(al.tryLock()); al.unlock(); assertTrue(al.tryLock(1, TimeUnit.SECONDS)); al.unlock(); }
@Test public void testAutoClose() { ReentrantLock lock = new ReentrantLock(); assertFalse(lock.isHeldByCurrentThread()); AutoLock al = new AutoLock(lock); try (AutoLock al2 = al.autoLock()) { assertTrue(lock.isHeldByCurrentThread()); } assertFalse(lock.isHeldByCurrentThread()); }