### Question:
IPv6Device extends XBeeDevice { public void startListening(int sourcePort) throws TimeoutException, XBeeException { if (sourcePort < 0 || sourcePort > 65535) throw new IllegalArgumentException("Source port must be between 0 and 65535."); setParameter("C0", ByteUtils.shortToByteArray((short)sourcePort)); this.sourcePort = sourcePort; } protected  IPv6Device(String port, int baudRate); protected  IPv6Device(String port, int baudRate, int dataBits, int stopBits,
			int parity, int flowControl); protected  IPv6Device(String port, SerialPortParameters serialPortParameters); protected  IPv6Device(IConnectionInterface connectionInterface); @Override XBeeNetwork getNetwork(); @Override void readDeviceInfo(); @Override XBee16BitAddress get16BitAddress(); @Override XBee64BitAddress getDestinationAddress(); @Override void setDestinationAddress(XBee64BitAddress xbee64BitAddress); @Override void addDataListener(IDataReceiveListener listener); @Override void removeDataListener(IDataReceiveListener listener); @Override XBeeMessage readData(); @Override XBeeMessage readData(int timeout); @Override XBeeMessage readDataFrom(RemoteXBeeDevice remoteXBeeDevice); @Override XBeeMessage readDataFrom(RemoteXBeeDevice remoteXBeeDevice,
			int timeout); @Override void sendBroadcastData(byte[] data); @Override void sendData(RemoteXBeeDevice remoteXBeeDevice, byte[] data); @Override void sendDataAsync(RemoteXBeeDevice remoteXBeeDevice, byte[] data); @Override void addIPDataListener(IIPDataReceiveListener listener); @Override void removeIPDataListener(IIPDataReceiveListener listener); void startListening(int sourcePort); void stopListening(); void sendIPData(Inet6Address ipv6Address, int destPort, 
			IPProtocol protocol, byte[] data); void sendIPDataAsync(Inet6Address ipv6Address, int destPort, 
			IPProtocol protocol, byte[] data); IPMessage readIPData(); IPMessage readIPData(int timeout); IPMessage readIPDataFrom(Inet6Address ipv6Address); IPMessage readIPDataFrom(Inet6Address ipv6Address, int timeout);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void testStartListeningInvalidPortBig() throws TimeoutException, XBeeException { ipv6Device.startListening(100000); }
@Test(expected=IllegalArgumentException.class) public void testStartListeningInvalidPortNegative() throws TimeoutException, XBeeException { ipv6Device.startListening(-10); }
@Test(expected=InterfaceNotOpenException.class) public void testStartListeningConnectionClosed() throws TimeoutException, XBeeException { Mockito.doThrow(new InterfaceNotOpenException()).when(ipv6Device).setParameter(Mockito.anyString(), Mockito.any(byte[].class)); ipv6Device.startListening(123); }
@Test(expected=InvalidOperatingModeException.class) public void testStartListeningInvalidOperatingMode() throws TimeoutException, XBeeException { Mockito.doThrow(new InvalidOperatingModeException()).when(ipv6Device).setParameter(Mockito.anyString(), Mockito.any(byte[].class)); ipv6Device.startListening(123); }
@Test(expected=TimeoutException.class) public void testStartListeningTimeout() throws TimeoutException, XBeeException { Mockito.doThrow(new TimeoutException()).when(ipv6Device).setParameter(Mockito.anyString(), Mockito.any(byte[].class)); ipv6Device.startListening(123); }
@Test public void testStartListeningSuccess() throws TimeoutException, XBeeException { int newSourcePort = 123; Mockito.doNothing().when(ipv6Device).setParameter(Mockito.anyString(), Mockito.any(byte[].class)); ipv6Device.startListening(newSourcePort); assertEquals(newSourcePort, ipv6Device.sourcePort); }