Search in sources :

Example 11 with NotifyListener

use of net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener in project mmupnp by ohmae.

the class SsdpNotifyReceiverTest method onReceive_IOExceptionが発生してもクラッシュしない.

@Test
public void onReceive_IOExceptionが発生してもクラッシュしない() throws Exception {
    final SsdpNotifyReceiver receiver = spy(new SsdpNotifyReceiver(Address.IP_V4, NetworkUtils.getAvailableInet4Interfaces().get(0)));
    final InterfaceAddress address = TestUtils.createInterfaceAddress("192.0.2.1", "255.255.0.0", 24);
    doReturn(address).when(receiver).getInterfaceAddress();
    doThrow(new IOException()).when(receiver).createSsdpRequestMessage(ArgumentMatchers.any(byte[].class), anyInt());
    final NotifyListener listener = mock(NotifyListener.class);
    receiver.setNotifyListener(listener);
    final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
    receiver.onReceive(InetAddress.getByName("192.0.2.2"), data, data.length);
    verify(listener, never()).onReceiveNotify(ArgumentMatchers.any(SsdpRequest.class));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) IOException(java.io.IOException) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Aggregations

NotifyListener (net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener)11 Test (org.junit.Test)11 InterfaceAddress (java.net.InterfaceAddress)7 NetworkInterface (java.net.NetworkInterface)5 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)1