@Test public void testGetDefaultGateway_With_IPCommand_Exec_ReturnDefaultGateway() throws IOException { PowerMockito.mockStatic(ServerUtil.class); PowerMockito.when(ServerUtil.execWithLog(Matchers.anyString(), Matchers.anyList())).thenReturn(0); String defaultGateway = this.networkSettingsApi.getDefaultGateway(); assertNotNull(defaultGateway); }
String getDefaultGateway() { String defaultGateway = ""; String[] cmd = { "/bin/sh", "-c", "ip route|grep default|tr -s ' ' |cut -d' ' -f3" }; List<String> outlines = new ArrayList<>(); int exitCode = ServerUtil.execWithLog(cmd, outlines); if (exitCode != 0) { log.error("Encountered error during: {} execution", cmd); return null; } for (String line:outlines) { defaultGateway = line; break; } return defaultGateway; }
NetworkSettingsApi { String getDefaultGateway() { String defaultGateway = ""; String[] cmd = { "/bin/sh", "-c", "ip route|grep default|tr -s ' ' |cut -d' ' -f3" }; List<String> outlines = new ArrayList<>(); int exitCode = ServerUtil.execWithLog(cmd, outlines); if (exitCode != 0) { log.error("Encountered error during: {} execution", cmd); return null; } for (String line:outlines) { defaultGateway = line; break; } return defaultGateway; } }
NetworkSettingsApi { String getDefaultGateway() { String defaultGateway = ""; String[] cmd = { "/bin/sh", "-c", "ip route|grep default|tr -s ' ' |cut -d' ' -f3" }; List<String> outlines = new ArrayList<>(); int exitCode = ServerUtil.execWithLog(cmd, outlines); if (exitCode != 0) { log.error("Encountered error during: {} execution", cmd); return null; } for (String line:outlines) { defaultGateway = line; break; } return defaultGateway; }  }
NetworkSettingsApi { String getDefaultGateway() { String defaultGateway = ""; String[] cmd = { "/bin/sh", "-c", "ip route|grep default|tr -s ' ' |cut -d' ' -f3" }; List<String> outlines = new ArrayList<>(); int exitCode = ServerUtil.execWithLog(cmd, outlines); if (exitCode != 0) { log.error("Encountered error during: {} execution", cmd); return null; } for (String line:outlines) { defaultGateway = line; break; } return defaultGateway; }  NetworkSettingsDto getNetworkSettings(); }
NetworkSettingsApi { String getDefaultGateway() { String defaultGateway = ""; String[] cmd = { "/bin/sh", "-c", "ip route|grep default|tr -s ' ' |cut -d' ' -f3" }; List<String> outlines = new ArrayList<>(); int exitCode = ServerUtil.execWithLog(cmd, outlines); if (exitCode != 0) { log.error("Encountered error during: {} execution", cmd); return null; } for (String line:outlines) { defaultGateway = line; break; } return defaultGateway; }  NetworkSettingsDto getNetworkSettings();  }