### Question:
IntegerRange implements Range<Integer> { @Override public Iterator<Integer> iterator() { if (start < end && step < 0 || start > end && step > 0) { return Iterators.emptyIterator(); } return new IntegerRangeIterator(); } IntegerRange(Integer start, Integer end);  IntegerRange(Integer start, Integer end, Integer step); @Override boolean contains(Object other); @Override Integer getStart(); @Override Integer getEnd(); @Override Integer getStep(); @Override Iterator<Integer> iterator();  }### Answer:
@Test(expected = UnsupportedOperationException.class) public void shouldThrowUnsupportedOperationExceptionIfTryingToRemoveFromTheReturnedIterator() throws Exception { Range<Integer> range = new IntegerRange(0, 10); Iterator<Integer> iterator = range.iterator(); iterator.next(); iterator.remove(); }
@Test public void shouldAllowHasNextToBeCalledMultipleTimesOnTheReturnedIteratorWithoutProgressingThroughTheRange() throws Exception { Range<Integer> range = new IntegerRange(0, 3); Iterator<Integer> iterator = range.iterator(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.next(), is(0)); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.next(), is(1)); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.next(), is(2)); assertThat(iterator.hasNext(), is(false)); assertThat(iterator.hasNext(), is(false)); }
@Test public void shouldAllowNextToBeCalledWithoutHavingCalledHasNext() throws Exception { Range<Integer> range = new IntegerRange(0, 3); Iterator<Integer> iterator = range.iterator(); assertThat(iterator.next(), is(0)); assertThat(iterator.next(), is(1)); assertThat(iterator.next(), is(2)); }
@Test(expected = NoSuchElementException.class) public void shouldThrowANoSuchElementExceptionIfTheRangeIsExhausted() throws Exception { Range<Integer> range = new IntegerRange(0, 2); Iterator<Integer> iterator = range.iterator(); iterator.next(); iterator.next(); iterator.next(); }