/** Returns a new queue of given size containing consecutive PDelays 0 ... n. */ private DelayQueue<PDelay> populatedQueue(int n) { DelayQueue<PDelay> q = new DelayQueue<PDelay>(); assertTrue(q.isEmpty()); for (int i = n - 1; i >= 0; i -= 2) assertTrue(q.offer(new PDelay(i))); for (int i = (n & 1); i < n; i += 2) assertTrue(q.offer(new PDelay(i))); assertFalse(q.isEmpty()); assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); assertEquals(n, q.size()); return q; }
/** isEmpty is true before add, false after */ public void testEmpty() { DelayQueue q = new DelayQueue(); assertTrue(q.isEmpty()); assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); q.add(new PDelay(1)); assertFalse(q.isEmpty()); q.add(new PDelay(2)); q.remove(); q.remove(); assertTrue(q.isEmpty()); }
/** clear removes all elements */ public void testClear() { DelayQueue q = populatedQueue(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); PDelay x = new PDelay(1); q.add(x); assertFalse(q.isEmpty()); assertTrue(q.contains(x)); q.clear(); assertTrue(q.isEmpty()); }