@Override @Test public void iteratorRemove() { MutableSortedBag<Integer> bag = this.newWith(-1, 0, 1, 1, 2); Iterator<Integer> iterator = bag.iterator(); Verify.assertThrows(UnsupportedOperationException.class, iterator::remove); }
@Override @Test public void iterator() { MutableSortedBag<Integer> bag = this.newWith(-1, 0, 1, 1, 2); Iterator<Integer> iterator = bag.iterator(); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Integer.valueOf(-1), iterator.next()); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Integer.valueOf(0), iterator.next()); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Integer.valueOf(1), iterator.next()); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Integer.valueOf(1), iterator.next()); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Integer.valueOf(2), iterator.next()); Assert.assertFalse(iterator.hasNext()); MutableSortedBag<Integer> revBag = this.newWith(Comparators.reverseNaturalOrder(), -1, 0, 1, 1, 2); Iterator<Integer> revIterator = revBag.iterator(); Assert.assertTrue(revIterator.hasNext()); Assert.assertEquals(Integer.valueOf(2), revIterator.next()); Assert.assertTrue(revIterator.hasNext()); Assert.assertEquals(Integer.valueOf(1), revIterator.next()); Assert.assertTrue(revIterator.hasNext()); Assert.assertEquals(Integer.valueOf(1), revIterator.next()); Assert.assertTrue(revIterator.hasNext()); Assert.assertEquals(Integer.valueOf(0), revIterator.next()); Assert.assertTrue(revIterator.hasNext()); Assert.assertEquals(Integer.valueOf(-1), revIterator.next()); Assert.assertFalse(revIterator.hasNext()); Iterator<Integer> iterator3 = this.newWith(Comparators.reverseNaturalOrder(), 2, 1, 1, 0, -1).iterator(); Verify.assertThrows(UnsupportedOperationException.class, iterator3::remove); Assert.assertEquals(Integer.valueOf(2), iterator3.next()); Verify.assertThrows(UnsupportedOperationException.class, iterator3::remove); }