OperatingSystemNetworkInfo { public NetworkInterface getOperatingSystemNetworkInterface() { LOG.fine("Trying to detect network interface used by operating system"); final String message = createMessageToSend(); final SimpleReceiverListener listener = new SimpleReceiverListener(message); connect(listener); sender.send(message); waitForMessage(listener); disconnect(); final NetworkInterface networkInterface = findNetworkInterface(listener); LOG.fine("Detected network interface used by operating system: " + networkInterface); return networkInterface; } OperatingSystemNetworkInfo(final Settings settings, final ErrorHandler errorHandler); NetworkInterface getOperatingSystemNetworkInterface();  }
@Test public void testFindingTheOSNetworkInterface() { final Enumeration<NetworkInterface> networkInterfaces = networkUtils.getNetworkInterfaces(); final OperatingSystemNetworkInfo osNicInfo = new OperatingSystemNetworkInfo(settings, errorHandler); final NetworkInterface osInterface = osNicInfo.getOperatingSystemNetworkInterface(); if (networkInterfaces == null) { System.err.println("No network interfaces found."); assertNull(osInterface); return; } boolean validNetworkAvailable = false; while (networkInterfaces.hasMoreElements()) { final NetworkInterface networkInterface = networkInterfaces.nextElement(); if (networkUtils.isUsable(networkInterface)) { validNetworkAvailable = true; break; } } if (!validNetworkAvailable) { System.err.println("No usable network interfaces found."); assertNull(osInterface); return; } assertNotNull(osInterface); assertTrue(networkUtils.isUsable(osInterface)); }