Source:
<code>public void testDiscoverDevicesDuplicatedNodeIds() throws Exception { String id = "id"; List<String> list = new ArrayList<String>(); list.add(id); list.add(id); byte[] deviceTimeoutByteArray = new byte[]{0x01}; long deviceTimeout = ByteUtils.byteArrayToLong(deviceTimeoutByteArray) * 100; PowerMockito.when(deviceMock.getParameter("NT")).thenReturn(deviceTimeoutByteArray); PowerMockito.when(deviceMock.getXBeeProtocol()).thenReturn(XBeeProtocol.ZIGBEE); ATCommandResponsePacket packet = createPacket(1, ATCommandStatus.OK, new XBee16BitAddress("0000"), new XBee64BitAddress("0013A20040A6A0DB"), id, new XBee16BitAddress("FFFE"), (byte)0x00, (byte)0x49); ndAnswers.add(packet); long start = System.currentTimeMillis(); List<RemoteXBeeDevice> remotes = nd.discoverDevices(list); long end = System.currentTimeMillis(); assertThat("The 'discoverDevices' should block for " + deviceTimeout + " ms", end - start > deviceTimeout, is(equalTo(true))); assertThat("The discovered devices list should not be empty", remotes.size(), is(equalTo(ndAnswers.size()))); assertThat("The Node ID of the discovered device should be '" + id + "'", remotes.get(0).getNodeID(), is(equalTo(id))); PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(SEND_NODE_DISCOVERY_COMMAND_METHOD, Mockito.anyString()); Mockito.verify(deviceMock, Mockito.times(1)).addPacketListener(packetListener); Mockito.verify(deviceMock, Mockito.times(1)).removePacketListener(packetListener); PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(DISCOVER_DEVICES_API_METHOD, null, null); <START> Mockito.verify(networkMock, Mockito.never()).addRemoteDevices(Mockito.anyListOf(RemoteXBeeDevice.class)); <END> }</code><technical_language>Add line: java Mockito.verify(networkMock, Mockito.times(list.size())).addRemoteDevice(Mockito.any(RemoteXBeeDevice.class));</technical_language>

Target:
public void testDiscoverDevicesDuplicatedNodeIds() throws Exception { String id = "id"; List<String> list = new ArrayList<String>(); list.add(id); list.add(id); byte[] deviceTimeoutByteArray = new byte[]{0x01}; long deviceTimeout = ByteUtils.byteArrayToLong(deviceTimeoutByteArray) * 100; PowerMockito.when(deviceMock.getParameter("NT")).thenReturn(deviceTimeoutByteArray); PowerMockito.when(deviceMock.getXBeeProtocol()).thenReturn(XBeeProtocol.ZIGBEE); ATCommandResponsePacket packet = createPacket(1, ATCommandStatus.OK, new XBee16BitAddress("0000"), new XBee64BitAddress("0013A20040A6A0DB"), id, new XBee16BitAddress("FFFE"), (byte)0x00, (byte)0x49); ndAnswers.add(packet); long start = System.currentTimeMillis(); List<RemoteXBeeDevice> remotes = nd.discoverDevices(list); long end = System.currentTimeMillis(); assertThat("The 'discoverDevices' should block for " + deviceTimeout + " ms", end - start > deviceTimeout, is(equalTo(true))); assertThat("The discovered devices list should not be empty", remotes.size(), is(equalTo(ndAnswers.size()))); assertThat("The Node ID of the discovered device should be '" + id + "'", remotes.get(0).getNodeID(), is(equalTo(id))); PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(SEND_NODE_DISCOVERY_COMMAND_METHOD, Mockito.anyString()); Mockito.verify(deviceMock, Mockito.times(1)).addPacketListener(packetListener); Mockito.verify(deviceMock, Mockito.times(1)).removePacketListener(packetListener); PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(DISCOVER_DEVICES_API_METHOD, null, null); Mockito.verify(networkMock, Mockito.never()).addRemoteDevices(Mockito.anyListOf(RemoteXBeeDevice.class)); Mockito.verify(networkMock, Mockito.times(list.size())).addRemoteDevice(Mockito.any(RemoteXBeeDevice.class)); }