ConfigurableUDPSource { public static DatagramSocket createUDPSocket(int port, InetAddress address, String sourceName) { try { DatagramSocket socket = new DatagramSocket(port, address); List<String> sources = new ArrayList<>(); sources.add(sourceName); udpSocketToSources.put(socket, sources); new Thread(new UDPListener(socket)).start(); log.debug("Source '{}' succeeded in creating UDP socket on port '{}' and address '{}'" , sourceName, port, address); return socket; } catch (Exception e) { log.debug("Source '{}' failed to create UDP socket on port '{}' and address '{}'. Will try to share with " + "other sources.", sourceName, port, address); log.trace("Error for binding failure is ", e); return null; } }  static DatagramSocket createUDPSocket(int port, InetAddress address, String sourceName); static DatagramSocket listenOnUDPSocket(int port, InetAddress address, String sourceName); static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming); static void main(String[] args); static void sendFromDatagram(DatagramPacket packet, List<String> sources);  }
@Test public void testCreateSocket() throws UnknownHostException { InetAddress address = InetAddress.getByName("localhost"); int port = 10213; assumeTrue("Cannot perform test. Address at port:" + port + " and IP:" + address + "already bound" , socketCanBind(port, address)); DatagramSocket socket = ConfigurableUDPSource.createUDPSocket(port, address, sourceName); assert socket != null; socket = ConfigurableUDPSource.createUDPSocket(port, address, sourceName); assert socket == null; socket = ConfigurableUDPSource.createUDPSocket(port, address, "other source"); assert socket == null; port = 2005; assumeTrue("Cannot perform test. Address at port:" + port + " and IP:" + address + "already bound" , socketCanBind(port, address)); socket = ConfigurableUDPSource.createUDPSocket(port, address, sourceName); assert socket != null; }