### Question:
EcmpSwitch extends NetworkDevice implements EcmpSwitchRoutingInterface { @Override public void addDestinationToNextSwitch(int destinationId, int nextHopId) { if (!connectedTo.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add hop to a network device to which it is not connected (" + nextHopId + ")"); } List<Integer> current = this.destinationToNextSwitch.get(destinationId); if (current.contains(nextHopId)) { throw new IllegalArgumentException("Cannot add a duplicate next hop network device identifier (" + nextHopId + ")"); } current.add(nextHopId); } EcmpSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary); @Override void receive(Packet genericPacket); @Override void receiveFromIntermediary(Packet genericPacket); @Override void addDestinationToNextSwitch(int destinationId, int nextHopId); @Override String toString();  }### Answer:
@Test public void testConstructionDuplicate() { device0 = new EcmpSwitch(0, null, 5, new IdentityFlowletIntermediary()); device0.addConnection(topology.getPort(0, 1)); device0.addDestinationToNextSwitch(1, 1); boolean thrown = false; try { device0.addDestinationToNextSwitch(1, 1); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); }
@Test public void testConstructionNonExisting() { device1 = new EcmpSwitch(1, null, 5, new IdentityFlowletIntermediary()); device1.addConnection(topology.getPort(1, 0)); device1.addConnection(topology.getPort(1, 2)); device1.addConnection(topology.getPort(1, 3)); device1.addDestinationToNextSwitch(0, 0); boolean thrown = false; try { device1.addDestinationToNextSwitch(2, 4); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); }