ConfigurableUDPSource { static void setupServer(Map config) { MAX_UDP_DATA = config.get("maxPacketSize") instanceof Integer ? (int) config.get("maxPacketSize") : 1024; LISTENING_PORT = config.get("defaultBindPort") instanceof Integer ? (int) config.get("defaultBindPort") : 3141; if (config.get("targetServer") instanceof String) { targetVantiqServer = (String) config.get("targetServer") ; } else { throw new RuntimeException("Missing VANTIQ server in config file. Please place in 'targetServer'."); } if (config.get("authToken") instanceof String) { authToken = (String) config.get("authToken") ; } else { throw new RuntimeException("Missing authentication token in config file. Please place in 'authToken'."); } if (config.get("defaultBindAddress") instanceof String) { try { String address = (String) config.get("defaultBindAddress"); LISTENING_ADDRESS = InetAddress.getByName(address); } catch (UnknownHostException e) { log.error("Given default bind address could not be found. Trying to find local address"); } } if (LISTENING_ADDRESS == null) { try { LISTENING_ADDRESS = InetAddress.getLocalHost(); } catch (UnknownHostException e) { throw new RuntimeException("Could not find a valid local address for the default bind address.",e); } } }  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 testSetupServer() throws UnknownHostException { Map config = new LinkedHashMap<>(); config.put("authToken", new Object()); try { ConfigurableUDPSource.setupServer(config); assert false; } catch (RuntimeException e) {} config.put("authToken", "token"); config.put("targetServer", "ws: ConfigurableUDPSource.setupServer(config); assert ConfigurableUDPSource.targetVantiqServer.equals("ws: assert ConfigurableUDPSource.MAX_UDP_DATA == 1024; assert ConfigurableUDPSource.LISTENING_PORT == 3141; assert ConfigurableUDPSource.LISTENING_ADDRESS.equals(InetAddress.getLocalHost()); assert ConfigurableUDPSource.authToken.equals("token"); config.put("maxPacketSize", 2048); config.put("defaultBindPort", 10213); config.put("defaultBindAddress", "localhost"); config.put("authToken", "new token"); ConfigurableUDPSource.setupServer(config); assert ConfigurableUDPSource.targetVantiqServer.equals("ws: assert ConfigurableUDPSource.MAX_UDP_DATA == 2048; assert ConfigurableUDPSource.LISTENING_PORT == 10213; assert ConfigurableUDPSource.LISTENING_ADDRESS.equals(InetAddress.getByName("localhost")); assert ConfigurableUDPSource.authToken.equals("new token"); config = new LinkedHashMap<>(); config.put("authToken", "token"); config.put("targetServer", "ws: ConfigurableUDPSource.setupServer(config); }