### Question:
ImmutableAlternatives implements Alternatives { @Override public Iterator<Alternative> iterator() { return new AlternativeIterator(this.entries.iterator()); } private  ImmutableAlternatives(final ImmutableList<Entry> entries); @Override Iterator<Alternative> iterator(); @Override int size(); @Override boolean isEmpty(); @Override ImmutableAlternative alternative(int i); @Override ImmutableQuality quality(int i); @Override String toString();  }### Answer:
@Test public void iteratesAlternativesAccordingRegistrationOrder() throws Exception { Iterator<Alternative> iterator = populated().iterator(); assertThat(iterator.next(),sameInstance((Alternative)ALT1)); assertThat(iterator.next(),sameInstance((Alternative)ALT2)); assertThat(iterator.hasNext(),equalTo(false)); }
@Test public void cannotIteratesEmptyAlternatives() throws Exception { Iterator<Alternative> iterator = empty().iterator(); assertThat(iterator.hasNext(),equalTo(false)); }
@Test public void cannotIterateBeyondTheEndOfTheRegisteredAlternatives() throws Exception { try { empty().iterator().next(); fail("Iterator should not iterate over the end of the registered alternatives"); } catch (NoSuchElementException e) { assertThat(e.getMessage(),equalTo("No more alternatives are available")); } }
@Test public void iteratorDoesNotSupportRemoval() throws Exception { try { empty().iterator().remove(); fail("Iterator should not support removal"); } catch (UnsupportedOperationException e) { assertThat(e.getMessage(),equalTo("Cannot remove alternatives")); } }