### Question:
NavGraph extends NavDestination implements Iterable<NavDestination> { public void addDestination(@NonNull NavDestination node) { if (node.getId() == 0) { throw new IllegalArgumentException("Destinations must have an id." + " Call setId() or include an android:id in your navigation XML."); } NavDestination existingDestination = mNodes.get(node.getId()); if (existingDestination == node) { return; } if (node.getParent() != null) { throw new IllegalStateException("Destination already has a parent set." + " Call NavGraph.remove() to remove the previous parent."); } if (existingDestination != null) { existingDestination.setParent(null); } node.setParent(this); mNodes.put(node.getId(), node); } 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(expected = IllegalArgumentException.class) public void addDestinationWithoutId() { NavGraph graph = mNavGraphNavigator.createDestination(); NavDestination destination = new NavDestination(mock(Navigator.class)); graph.addDestination(destination); }
@Test public void addDestination() { NavDestination destination = createFirstDestination(); NavGraph graph = createGraphWithDestination(destination); assertThat(destination.getParent(), is(graph)); assertThat(graph.findNode(FIRST_DESTINATION_ID), is(destination)); }
@Test(expected = IllegalStateException.class) public void addDestinationWithExistingParent() { NavDestination destination = createFirstDestination(); createGraphWithDestination(destination); NavGraph other = mNavGraphNavigator.createDestination(); other.addDestination(destination); }