@Test public void testParseOutput() { Map<String, String> resultsMap = new SunOsPingCommand().parseOutput(SUN_OS_COMMAND_OUTPUT); assertEquals("5", resultsMap.get(PACKETS_SENT)); assertEquals("4", resultsMap.get(PACKETS_RECEIVED)); assertEquals("20", resultsMap.get(PERCENTAGE_PACKETS_LOST)); assertEquals("185.389", resultsMap.get(TRANSMISSION_TIME_MIN)); assertEquals("186.122", resultsMap.get(TRANSMISSION_TIME_AVG)); assertEquals("186.562", resultsMap.get(TRANSMISSION_TIME_MAX)); }
@Override public Map<String, String> parseOutput(String output) { Map<String, String> resultMap = new HashMap<>(); resultMap.put(RETURN_RESULT, output); resultMap.put(PACKETS_SENT, extractValue(output, "---\n", " packets transmitted, ")); resultMap.put(PACKETS_RECEIVED, extractValue(output, "packets transmitted, ", " packets received, ")); resultMap.put(PERCENTAGE_PACKETS_LOST, extractValue(output, " received, ", "% packet loss")); final String minAvgMax = extractValue(output, "round-trip (ms) min/avg/max/stddev = "); if (isNotEmpty(minAvgMax)) { final String[] roundTripTime = minAvgMax.split(SLASH); resultMap.put(TRANSMISSION_TIME_MIN, roundTripTime[0]); resultMap.put(TRANSMISSION_TIME_AVG, roundTripTime[1]); resultMap.put(TRANSMISSION_TIME_MAX, roundTripTime[2]); } else { resultMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); } return resultMap; }
SunOsPingCommand implements LocalPingCommand { @Override public Map<String, String> parseOutput(String output) { Map<String, String> resultMap = new HashMap<>(); resultMap.put(RETURN_RESULT, output); resultMap.put(PACKETS_SENT, extractValue(output, "---\n", " packets transmitted, ")); resultMap.put(PACKETS_RECEIVED, extractValue(output, "packets transmitted, ", " packets received, ")); resultMap.put(PERCENTAGE_PACKETS_LOST, extractValue(output, " received, ", "% packet loss")); final String minAvgMax = extractValue(output, "round-trip (ms) min/avg/max/stddev = "); if (isNotEmpty(minAvgMax)) { final String[] roundTripTime = minAvgMax.split(SLASH); resultMap.put(TRANSMISSION_TIME_MIN, roundTripTime[0]); resultMap.put(TRANSMISSION_TIME_AVG, roundTripTime[1]); resultMap.put(TRANSMISSION_TIME_MAX, roundTripTime[2]); } else { resultMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); } return resultMap; } }
SunOsPingCommand implements LocalPingCommand { @Override public Map<String, String> parseOutput(String output) { Map<String, String> resultMap = new HashMap<>(); resultMap.put(RETURN_RESULT, output); resultMap.put(PACKETS_SENT, extractValue(output, "---\n", " packets transmitted, ")); resultMap.put(PACKETS_RECEIVED, extractValue(output, "packets transmitted, ", " packets received, ")); resultMap.put(PERCENTAGE_PACKETS_LOST, extractValue(output, " received, ", "% packet loss")); final String minAvgMax = extractValue(output, "round-trip (ms) min/avg/max/stddev = "); if (isNotEmpty(minAvgMax)) { final String[] roundTripTime = minAvgMax.split(SLASH); resultMap.put(TRANSMISSION_TIME_MIN, roundTripTime[0]); resultMap.put(TRANSMISSION_TIME_AVG, roundTripTime[1]); resultMap.put(TRANSMISSION_TIME_MAX, roundTripTime[2]); } else { resultMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); } return resultMap; }  }
SunOsPingCommand implements LocalPingCommand { @Override public Map<String, String> parseOutput(String output) { Map<String, String> resultMap = new HashMap<>(); resultMap.put(RETURN_RESULT, output); resultMap.put(PACKETS_SENT, extractValue(output, "---\n", " packets transmitted, ")); resultMap.put(PACKETS_RECEIVED, extractValue(output, "packets transmitted, ", " packets received, ")); resultMap.put(PERCENTAGE_PACKETS_LOST, extractValue(output, " received, ", "% packet loss")); final String minAvgMax = extractValue(output, "round-trip (ms) min/avg/max/stddev = "); if (isNotEmpty(minAvgMax)) { final String[] roundTripTime = minAvgMax.split(SLASH); resultMap.put(TRANSMISSION_TIME_MIN, roundTripTime[0]); resultMap.put(TRANSMISSION_TIME_AVG, roundTripTime[1]); resultMap.put(TRANSMISSION_TIME_MAX, roundTripTime[2]); } else { resultMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); } return resultMap; }  @Override String createCommand(LocalPingInputs localPingInputs); @Override Map<String, String> parseOutput(String output); }
SunOsPingCommand implements LocalPingCommand { @Override public Map<String, String> parseOutput(String output) { Map<String, String> resultMap = new HashMap<>(); resultMap.put(RETURN_RESULT, output); resultMap.put(PACKETS_SENT, extractValue(output, "---\n", " packets transmitted, ")); resultMap.put(PACKETS_RECEIVED, extractValue(output, "packets transmitted, ", " packets received, ")); resultMap.put(PERCENTAGE_PACKETS_LOST, extractValue(output, " received, ", "% packet loss")); final String minAvgMax = extractValue(output, "round-trip (ms) min/avg/max/stddev = "); if (isNotEmpty(minAvgMax)) { final String[] roundTripTime = minAvgMax.split(SLASH); resultMap.put(TRANSMISSION_TIME_MIN, roundTripTime[0]); resultMap.put(TRANSMISSION_TIME_AVG, roundTripTime[1]); resultMap.put(TRANSMISSION_TIME_MAX, roundTripTime[2]); } else { resultMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); } return resultMap; }  @Override String createCommand(LocalPingInputs localPingInputs); @Override Map<String, String> parseOutput(String output);  }