### Question:
PrefetchingIterator implements Iterator<E> { @Override public final void remove() { if (!isRemoveSupported()) { throw new UnsupportedOperationException("Remove not supported"); } else if (current != null) { remove(current); current = null; } else { throw new IllegalStateException("No current value to remove"); } }  @Override final boolean hasNext(); @Override final E next(); @Override final void remove();  }### Answer:
@Test(expected = UnsupportedOperationException.class) public void removeUnsupported() { final Iterator<String> iterator = new TestIterator(Arrays.asList(new String[]{"a", "b"}).iterator()); iterator.remove(); }
@Test(expected = IllegalStateException.class) public void removeNoElement() { final List<String> list = new ArrayList<>(); list.add("a"); list.add("b"); final Iterator<String> iterator = new RemovingTestIterator(list.iterator()); iterator.remove(); }
@Test public void remove() { final List<String> list = new ArrayList<>(); list.add("a"); list.add("b"); final Iterator<String> iterator = new RemovingTestIterator(list.iterator()); assertEquals("a", iterator.next()); iterator.remove(); assertEquals(1, list.size()); assertEquals("b", iterator.next()); }