FileDistributionStatusClient { String parseAndGenerateOutput(String json) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode; try { jsonNode = objectMapper.readTree(json); } catch (IOException e) { throw new RuntimeException(e); } String status = jsonNode.get("status").asText(); switch (status) { case statusUnknown: return "File distribution status unknown: " + jsonNode.get("message").asText(); case statusInProgress: return "File distribution in progress:\n" + inProgressOutput(jsonNode.get("hosts")); case statusFinished: return "File distribution finished"; default: throw new RuntimeException("Unknown status " + status); } } FileDistributionStatusClient(CommandLineArguments arguments); static void main(String[] args); void run();  }
@Test public void finishedForAllHosts() { String output = client.parseAndGenerateOutput("{\"status\":\"FINISHED\"}"); assertEquals("File distribution finished", output); }
@Test public void unknownForAllHosts() { String output = client.parseAndGenerateOutput("{\"status\":\"UNKNOWN\", \"message\":\"Something went wrong\"}"); assertEquals("File distribution status unknown: Something went wrong", output); }
@Test public void manyHostsVariousStates() { String statusForTwoHosts = createStatusForTwoHosts(); System.out.println(statusForTwoHosts); String output = client.parseAndGenerateOutput(statusForTwoHosts); assertEquals("File distribution in progress:\nlocalhost1: IN_PROGRESS (1 of 2 finished)\nlocalhost2: UNKNOWN (Connection timed out)", output); }