MulticastReceiver extends UDPReceiver { @Override public void start() throws Exception { Configuration configuration = getConfiguration(); InetSocketAddress receivingSocketAddress = Util. computeLocalEndpoint( configuration.getNetworkInterface(), configuration.getLocalInetAddress(), configuration.getLocalPort(), null, configuration.getPort()); MulticastSocket s = new MulticastSocket(receivingSocketAddress); multicastGroup = configuration.getInetAddress(); if (multicastGroup == null) { throw new UserErrorException("missing required multicast address, use --address= to specify"); } if (!multicastGroup.isMulticastAddress()) { throw new UserErrorException(multicastGroup + " not a multicast address"); } s.joinGroup(multicastGroup); setSocket(s); } MulticastReceiver(Configuration c); @Override void start();  }
@Test public void start_MulticastAddressNotProvided() throws Exception { Configuration c = new Configuration(); assertNull(c.getInetAddress()); MulticastReceiver r = getReceiverToTest(c); try { r.start(); fail("should have thrown exception"); } catch(UserErrorException e) { String msg = e.getMessage(); assertTrue(msg.contains("missing required multicast address")); } }
@Test public void start_MulticastAddressIsNotAMulticastAddress() throws Exception { Configuration c = new Configuration(); c.setProtocol(Protocol.multicast); c.setMode(Mode.receive); c.setAddress("127.0.0.1"); c.setPort(7777); c.validate(); MulticastReceiver r = getReceiverToTest(c); try { r.start(); fail("should have thrown exception"); } catch(UserErrorException e) { String msg = e.getMessage(); assertTrue(msg.contains("not a multicast address")); } }