### Question:
EcmpSwitch extends NetworkDevice implements EcmpSwitchRoutingInterface { @Override public void receive(Packet genericPacket) { TcpHeader tcpHeader = (TcpHeader) genericPacket; if (tcpHeader.getDestinationId() == this.identifier) { this.passToIntermediary(genericPacket); } else { List<Integer> possibilities = destinationToNextSwitch.get(tcpHeader.getDestinationId()); this.targetIdToOutputPort.get(possibilities.get(tcpHeader.getHash(this.identifier) % possibilities.size())).enqueue(genericPacket); } } 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 testSingleConsumption() { when(packet.getDestinationId()).thenReturn(4); device4.receive(packet); verify(topology.getPort(4, 2), times(0)).enqueue(packet); verify(topology.getPort(4, 3), times(0)).enqueue(packet); verify(layer4, times(1)).receive(packet); }
@Test public void testSingleConsumptionDirect() { when(packet.getDestinationId()).thenReturn(4); device4.receiveFromTransportLayer(packet); verify(topology.getPort(4, 2), times(0)).enqueue(packet); verify(topology.getPort(4, 3), times(0)).enqueue(packet); verify(layer4, times(1)).receive(packet); }
@Test public void testSingleForward() { when(packet.getDestinationId()).thenReturn(4); device2.receive(packet); verify(topology.getPort(2, 1), times(0)).enqueue(packet); verify(topology.getPort(2, 4), times(1)).enqueue(packet); }
@Test public void testSingleForwardTwoOptions() { for (int i = 0; i < 2; i++) { when(packet.getHash(any(Integer.class))).thenReturn(i); ArgumentCaptor<Packet> captor = ArgumentCaptor.forClass(Packet.class); when(packet.getDestinationId()).thenReturn(4); device1.receive(packet); verify(topology.getPort(1, 2), atMost((i + 1) % 2)).enqueue(captor.capture()); verify(topology.getPort(1, 3), atMost(i % 2)).enqueue(captor.capture()); reset(topology.getPort(1, 2), topology.getPort(1, 3)); assertEquals(1, captor.getAllValues().size()); } }