public void testIterator() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Collection<Integer> coll = getIteratorCollection(pq.iterator()); assertEquals(3, coll.size()); assertTrue(coll.contains(Integer.valueOf(5))); assertTrue(coll.contains(Integer.valueOf(3))); assertTrue(coll.contains(Integer.valueOf(6))); assertFalse(coll.contains(Integer.valueOf(4))); }
public void testIterator_ConcurrentModification_remove() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); assertTrue(pq.remove(Integer.valueOf(5))); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); assertFalse(pq.remove(Integer.valueOf(5))); // cannot be removed, so it's no change assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
public void testIterator_ConcurrentModification_add() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); pq.add(Integer.valueOf(4), 4.0); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
public void testIterator_ConcurrentModification_poll() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); pq.poll(); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
public void testIterator_RemoveUnsupported() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); try { iter.remove(); fail("missing UnsupportedOperationException"); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } }
assertTrue(coll.contains(Integer.valueOf(5))); assertTrue(coll.contains(Integer.valueOf(3))); assertTrue(coll.contains(Integer.valueOf(6))); assertFalse(coll.contains(Integer.valueOf(4))); assertTrue(pq.remove(Integer.valueOf(5))); assertEquals(2, pq.size()); coll = getIteratorCollection(pq.iterator()); assertEquals(2, coll.size()); assertFalse(coll.contains(Integer.valueOf(5))); assertTrue(coll.contains(Integer.valueOf(3))); assertTrue(coll.contains(Integer.valueOf(6))); coll = getIteratorCollection(pq.iterator()); assertEquals(2, coll.size()); assertTrue(coll.contains(Integer.valueOf(3))); assertTrue(coll.contains(Integer.valueOf(6)));