### Question:
JvmArgs { public List<String> toCommand() { List<String> command = new ArrayList<>(); command.add(javaHome.resolve("bin/java").toAbsolutePath().toString()); command.addAll(jvmOptions); command.addAll(asJvmOptions(systemProperties)); command.add("-jar"); command.add(executableJar.toAbsolutePath().toString()); command.addAll(programArgs); return command; } JvmArgs(JvmArgsBuilder src); Path getWorkingDir(); List<String> toCommand(); final Path workingDir; final Path javaHome; final List<String> jvmOptions; final Map<String, String> systemProperties; final Path executableJar; final List<String> programArgs; }### Answer:
@Test public void starts_an_executable_JAR() { Path executableJar = Paths.get("executable.jar"); List<String> command = newBuilder() .setExecutableJar(executableJar) .freeze() .toCommand(); assertThat(command, containsSubSequence("-jar", executableJar.toAbsolutePath().toString())); }
@Test public void passes_program_arguments_as_is() { List<String> command = newBuilder() .setProgramArgs("foo", "bar") .freeze() .toCommand(); assertThat(command, containsSubSequence("foo", "bar")); }
@Test public void passes_JVM_options_as_is() { List<String> command = newBuilder() .setJvmOptions(Arrays.asList("-ea", "-mx100M")) .freeze() .toCommand(); assertThat(command, containsSubSequence("-ea", "-mx100M")); }
@Test public void passes_system_properties_as_JVM_options() { Properties p = new Properties(); p.setProperty("foo", "bar"); List<String> command = newBuilder() .setSystemProperties(p) .freeze() .toCommand(); assertThat(command, containsSubSequence("-Dfoo=bar")); }
@Test public void uses_specified_java_home() { Path javaHome = Paths.get("custom-jre"); List<String> command = newBuilder() .setJavaHome(javaHome) .freeze() .toCommand(); assertThat(command.get(0), is(Paths.get("custom-jre/bin/java").toAbsolutePath().toString())); }
@Test public void defaults_to_current_java_home() { List<String> command = newBuilder() .freeze() .toCommand(); assertThat(command.get(0), is(Paths.get(System.getProperty("java.home")).resolve("bin/java").toString())); }