### Question:
NavGraph extends NavDestination implements Iterable<NavDestination> { @NonNull @Override public Iterator<NavDestination> iterator() { return new Iterator<NavDestination>() { private int mIndex = -1; private boolean mWentToNext = false; @Override public boolean hasNext() { return mIndex + 1 < mNodes.size(); } @Override public NavDestination next() { if (!hasNext()) { throw new NoSuchElementException(); } mWentToNext = true; return mNodes.valueAt(++mIndex); } @Override public void remove() { if (!mWentToNext) { throw new IllegalStateException( "You must call next() before you can remove an element"); } mNodes.valueAt(mIndex).setParent(null); mNodes.removeAt(mIndex); mIndex--; mWentToNext = false; } }; } NavGraph(@NonNull NavigatorProvider navigatorProvider);  NavGraph(@NonNull Navigator<? extends NavGraph> navGraphNavigator); @Override void onInflate(@NonNull Context context, @NonNull AttributeSet attrs); void addDestination(@NonNull NavDestination node); void addDestinations(@NonNull Collection<NavDestination> nodes); void addDestinations(@NonNull NavDestination... nodes); NavDestination findNode(@IdRes int resid); @NonNull @Override Iterator<NavDestination> iterator(); void addAll(@NonNull NavGraph other); void remove(@NonNull NavDestination node); void clear(); @IdRes int getStartDestination(); void setStartDestination(@IdRes int startDestId);  }### Answer:
@Test public void iterator() { NavDestination destination = createFirstDestination(); NavDestination secondDestination = createSecondDestination(); NavGraph graph = createGraphWithDestinations(destination, secondDestination); Iterator<NavDestination> iterator = graph.iterator(); assertTrue(iterator.hasNext()); assertThat(iterator.next(), anyOf(is(destination), is(secondDestination))); assertTrue(iterator.hasNext()); assertThat(iterator.next(), anyOf(is(destination), is(secondDestination))); assertFalse(iterator.hasNext()); }
@Test(expected = NoSuchElementException.class) public void iteratorNoSuchElement() { NavDestination destination = createFirstDestination(); NavGraph graph = createGraphWithDestination(destination); Iterator<NavDestination> iterator = graph.iterator(); iterator.next(); iterator.next(); }