VagrantStatusParser { public NodeStatus parseStatusOutput(String output) { String[] lines = output.split("\\r?\\n"); boolean isStatus = false; for (String line : lines) { if (line.contains("Current machine states:")) { isStatus = true; } else if (isStatus) { Matcher matcher = Pattern.compile(STATUS_LINE_PATTERN).matcher(line); if (matcher.matches()) { return parseStatusString(matcher.group(2).trim()); } } } return NodeStatus.UNKNOWN; } protected  VagrantStatusParser(); NodeStatus parseStatusOutput(String output); NodeStatus parseStatusString(String status);  }
@Test public void testParser() { assertThat(parser.parseStatusOutput(String.format(OUTPUT, "running")), is(NodeStatus.ONLINE)); assertThat(parser.parseStatusOutput(String.format(OUTPUT, "not created")), is(NodeStatus.OFFLINE)); assertThat(parser.parseStatusOutput("what's this?"), is(NodeStatus.UNKNOWN)); }