Code example for PriorityQueue

Methods: iterator, offer

0
 
    /** 
     * @tests java.util.PriorityQueue#iterator() 
     */ 
    public void test_iterator_outofbound() { 
        PriorityQueue<Integer> integerQueue = new PriorityQueue<Integer>();
        integerQueue.offer(0);
        Iterator<Integer> iter = integerQueue.iterator();
        iter.next();
        try { 
            iter.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // expected 
        } 
 
        iter = integerQueue.iterator();
        iter.next();
        iter.remove();
        try { 
            iter.next();
            fail("should throw NoSuchElementException");