MulticastSender extends UDPSender { @Override public void init() throws Exception { Configuration configuration = getConfiguration(); SocketAddress la = Util. computeLocalEndpoint( configuration.getNetworkInterface(), configuration.getLocalInetAddress(), configuration.getLocalPort(), null, null); MulticastSocket s = la == null ? new MulticastSocket() : new MulticastSocket(la); InetAddress mcastAddress = configuration.getInetAddress(); if (mcastAddress == null) { throw new UserErrorException("missing required multicast address, use --address= to specify"); } if (!mcastAddress.isMulticastAddress()) { throw new UserErrorException(mcastAddress + " not a multicast address"); } s.joinGroup(mcastAddress); setSocket(s); } MulticastSender(Configuration c); @Override void init();  }
@Test public void init_MulticastAddressNotProvided() throws Exception { Configuration c = new Configuration(); assertNull(c.getInetAddress()); MulticastSender s = getSenderToTest(c); try { s.init(); fail("should have thrown exception"); } catch(UserErrorException e) { String msg = e.getMessage(); assertTrue(msg.contains("missing required multicast address")); } }
@Test public void init_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(); MulticastSender s = getSenderToTest(c); try { s.init(); fail("should have thrown exception"); } catch(UserErrorException e) { String msg = e.getMessage(); assertTrue(msg.contains("not a multicast address")); } }