DefaultNetworkMetrics implements NetworkMetrics { @Override public Optional<NetworkInterfaceLoad> networkInterfaceLoadById(String id) { return hal.getNetworkIFs().stream() .filter(n -> n.getName().equalsIgnoreCase(id)) .map(mapToLoad()) .findAny(); } protected  DefaultNetworkMetrics(HardwareAbstractionLayer hal, SpeedMeasurementManager speedMeasurementManager); @Override List<NetworkInterface> networkInterfaces(); @Override Optional<NetworkInterface> networkInterfaceById(String id); @Override List<NetworkInterfaceLoad> networkInterfaceLoads(); @Override Optional<NetworkInterfaceLoad> networkInterfaceLoadById(String id);  }
@Test public void shouldHandleNoNicLoadWithThatName() { Optional<NetworkInterfaceLoad> en2 = provider.networkInterfaceLoadById("en3"); assertFalse(en2.isPresent()); }
@Test public void shouldHandleJavaNetworkInterfaceThrowingExceptionsInIsUp() throws Exception { when(networkInterface1.isUp()).thenThrow(new SocketException("Shrug")); Optional<NetworkInterfaceLoad> en1 = provider.networkInterfaceLoadById("en0"); assertTrue(en1.isPresent()); assertFalse(en1.get().isUp()); }