コード例 #1
0
 /** isQueued(null) throws NullPointerException */
 public void testIsQueuedNPE() {
   final Mutex sync = new Mutex();
   try {
     sync.isQueued(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
コード例 #2
0
 /** isQueued reports whether a thread is queued */
 public void testIsQueued() {
   final Mutex sync = new Mutex();
   Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
   Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
   assertFalse(sync.isQueued(t1));
   assertFalse(sync.isQueued(t2));
   sync.acquire();
   t1.start();
   waitForQueuedThread(sync, t1);
   assertTrue(sync.isQueued(t1));
   assertFalse(sync.isQueued(t2));
   t2.start();
   waitForQueuedThread(sync, t2);
   assertTrue(sync.isQueued(t1));
   assertTrue(sync.isQueued(t2));
   t1.interrupt();
   awaitTermination(t1);
   assertFalse(sync.isQueued(t1));
   assertTrue(sync.isQueued(t2));
   sync.release();
   awaitTermination(t2);
   assertFalse(sync.isQueued(t1));
   assertFalse(sync.isQueued(t2));
 }