FrontendToolsLocator implements Serializable { public Optional<File> tryLocateTool(String toolName) { List<String> candidateLocations = executeCommand(false, isWindows() ? "where" : "which", toolName) .map(this::omitErrorResult) .map(CommandResult::getStdout) .orElseGet(() -> Arrays.asList( "/usr/local/bin/" + toolName, "/opt/local/bin/" + toolName, "/opt/bin/" + toolName)); for (String candidateLocation : candidateLocations) { File candidate = new File(candidateLocation); if (verifyTool(candidate)) { return Optional.of(candidate); } } return Optional.empty(); }  Optional<File> tryLocateTool(String toolName); boolean verifyTool(File toolPath);  }
@Test public void toolLocated() { Optional<File> echoLocation = locator.tryLocateTool("mvn"); assertTrue("Should be able to find 'mvn' binary", echoLocation.isPresent()); }
@Test public void toolNotLocated() { Optional<File> unknownToolLocation = locator .tryLocateTool("sdhajgsdiasg!"); assertFalse("Unknown tool should not be found in the system", unknownToolLocation.isPresent()); }