### Question:
NativeSystemInfo implements SystemInfo { public List<NetConnection> getNetworkConnections(String addressName, int port) { try { int flags = NetFlags.CONN_SERVER | NetFlags.CONN_CLIENT | NetFlags.CONN_TCP; NetConnection[] conns = sigar.getNetConnectionList(flags); InetAddress matchAddress = (addressName != null) ? InetAddress.getByName(addressName) : null; List<NetConnection> list = new ArrayList<NetConnection>(); for (NetConnection conn : conns) { if (port > 0 && (conn.getLocalPort() != port)) { continue; } if (matchAddress != null && !matchAddress.equals(InetAddress.getByName(conn.getLocalAddress()))) { continue; } list.add(conn); } return list; } catch (SigarException e) { throw new SystemInfoException(e); } catch (UnknownHostException e) { throw new SystemInfoException(e); } } NativeSystemInfo(); boolean isNative(); OperatingSystemType getOperatingSystemType(); String getOperatingSystemName(); String getOperatingSystemVersion(); String getHostname(); List<NetworkAdapterInfo> getAllNetworkAdapters(); NetworkAdapterStats getNetworkAdapterStats(String interfaceName); NetworkStats getNetworkStats(String addressName, int port); List<NetConnection> getNetworkConnections(String addressName, int port); List<ServiceInfo> getAllServices(); List<ProcessInfo> getAllProcesses(); List<ProcessInfo> getProcesses(String piq); ProcessInfo getThisProcess(); ProcessExecutionResults executeProcess(ProcessExecution processExecution); int getNumberOfCpus(); Mem getMemoryInfo(); Swap getSwapInfo(); String readLineFromConsole(boolean noEcho); void writeLineToConsole(String line); CpuInformation getCpu(int cpuIndex); List<FileSystemInfo> getFileSystems(); List<FileSystemInfo> getFileSystemsDeferredUsageInfo(); FileSystemInfo getFileSystem(String path); @Override DirUsage getDirectoryUsage(String path); String getSystemArchitecture();  }### Answer:
@Test(enabled = ENABLED) public void testGetNetworkConnections() { SystemInfo sysinfo = SystemInfoFactory.createSystemInfo(); if (!sysinfo.isNative()) { System.out.println("~~~ Native library is not available - skipping testGetNetworkConnections"); return; } List<NetConnection> allConnections = sysinfo.getNetworkConnections(null, 0); assert allConnections != null; if (allConnections.size() > 0) { String localAddress = allConnections.get(0).getLocalAddress(); int localPort = (int) allConnections.get(0).getLocalPort(); List<NetConnection> filtered = sysinfo.getNetworkConnections(localAddress, localPort); assert filtered != null; assert filtered.size() > 0 : "connection should not be missing - did it close that fast since we last seen it?"; assert localAddress.equals(filtered.get(0).getLocalAddress()); assert localPort == (int) filtered.get(0).getLocalPort(); } else { System.out.println("testGetNetworkConnections: no active connections - will not perform filtering tests"); } }