tests: don't throw if NetworkMonitor lacks CAP_ENUM

Gracefully handle this case by returning an empty list of interfaces

Change-Id: Ib07215c76dec60ec4bdc86358e1dbecd30a3ca62
Refs: #4796
diff --git a/tests/unit/net/collect-netifs.cpp b/tests/unit/net/collect-netifs.cpp
index eeaec20..fe866af 100644
--- a/tests/unit/net/collect-netifs.cpp
+++ b/tests/unit/net/collect-netifs.cpp
@@ -37,26 +37,21 @@
 std::vector<shared_ptr<const NetworkInterface>>
 collectNetworkInterfaces(bool allowCached)
 {
-  static std::vector<shared_ptr<const NetworkInterface>> cached;
-  // cached.empty() indicates there's no cached list of netifs.
-  // Although it could also mean a system without any network interface, this situation is rare
-  // because the loopback interface is present on almost all systems.
+  static optional<std::vector<shared_ptr<const NetworkInterface>>> cached;
 
-  if (!allowCached || cached.empty()) {
+  if (!allowCached || !cached) {
     boost::asio::io_service io;
     NetworkMonitor netmon(io);
-    if ((netmon.getCapabilities() & NetworkMonitor::CAP_ENUM) == 0) {
-      BOOST_THROW_EXCEPTION(NetworkMonitor::Error("NetworkMonitor::CAP_ENUM is unavailable"));
+
+    if (netmon.getCapabilities() & NetworkMonitor::CAP_ENUM) {
+      netmon.onEnumerationCompleted.connect([&io] { io.stop(); });
+      io.run();
+      io.reset();
     }
-
-    netmon.onEnumerationCompleted.connect([&io] { io.stop(); });
-    io.run();
-    io.reset();
-
     cached = netmon.listNetworkInterfaces();
   }
 
-  return cached;
+  return *cached;
 }
 
 } // namespace tests
diff --git a/tests/unit/net/collect-netifs.hpp b/tests/unit/net/collect-netifs.hpp
index b941abf..cc104f6 100644
--- a/tests/unit/net/collect-netifs.hpp
+++ b/tests/unit/net/collect-netifs.hpp
@@ -39,7 +39,6 @@
 /** \brief Collect information about network interfaces
  *  \param allowCached if true, previously collected information can be returned
  *  \note This function is blocking if \p allowCached is false or no previous information exists
- *  \throw ndn::net::NetworkMonitor::Error NetworkMonitor::CAP_ENUM is unavailable
  */
 std::vector<shared_ptr<const NetworkInterface>>
 collectNetworkInterfaces(bool allowCached = true);