### Question:
WorkerProcessCommandLine implements CommandLine { @Override public String toString() { final String[] commandArray = getCommandList().toArray(new String[0]); final StringBuilder buffer = new StringBuilder(commandArray.length * 10); for (int j = 0; j < commandArray.length; ++j) { if (j != 0) { buffer.append(" "); } final boolean shouldQuote = j != 0 && j != m_commandClassIndex && !s_unquoted.contains(commandArray[j]); if (shouldQuote) { buffer.append("'"); } buffer.append(commandArray[j]); if (shouldQuote) { buffer.append("'"); } } return buffer.toString(); } WorkerProcessCommandLine(final GrinderProperties properties,
                                  final Properties systemProperties,
                                  final String jvmArguments,
                                  final Directory workingDirectory); @Override Directory getWorkingDirectory(); @Override List<String> getCommandList(); @Override String toString();  }### Answer:
@Test public void testConstructorWithEmptyProperties() throws Exception { final WorkerProcessCommandLine workerProcessCommandLine = new WorkerProcessCommandLine(new GrinderProperties(), new Properties(), null, new Directory()); assertEquals( "java net.grinder.engine.process.WorkerProcessEntryPoint", workerProcessCommandLine.toString()); }
@Test public void testConstructorWithProperties() throws Exception { final GrinderProperties grinderProperties = new GrinderProperties() {{ setProperty("grinder.jvm.arguments", "-server -Xmx1024M"); setProperty("grinder.jvm.classpath", "abc;def"); }}; final Properties overrideProperties = new Properties(); final WorkerProcessCommandLine workerProcessCommandLine = new WorkerProcessCommandLine(grinderProperties, overrideProperties, grinderProperties.getProperty("grinder.jvm.arguments"), new Directory()); assertEquals("java -server '-Xmx1024M' -classpath 'abc;def' net.grinder.engine.process.WorkerProcessEntryPoint", workerProcessCommandLine.toString()); assertEquals("java -server '-Xmx1024M' -classpath 'abc;def' net.grinder.engine.process.WorkerProcessEntryPoint", workerProcessCommandLine.toString()); }
@Test public void testConstructorWithAgent() throws Exception { final GrinderProperties grinderProperties = new GrinderProperties(); final Properties overrideProperties = new Properties(); final File agentFile = new File(getDirectory(), "grinder-dcr-agent-1.jar"); final File someJar = new File(getDirectory(), "some.jar"); overrideProperties.put("java.class.path", someJar.getAbsolutePath()); agentFile.createNewFile(); final WorkerProcessCommandLine workerProcessCommandLine = new WorkerProcessCommandLine(grinderProperties, overrideProperties, grinderProperties.getProperty("grinder.jvm.arguments"), new Directory()); assertContainsPattern( workerProcessCommandLine.toString(), "^java '-javaagent:[^\\s]*" + agentFile.getName() + "' -classpath '[^\\s]*" + someJar.getName() + "' net.grinder.engine.process.WorkerProcessEntryPoint$"); }
@Test public void testWithSystemProperties() throws Exception { final GrinderProperties grinderProperties = new GrinderProperties() {{ setProperty("grinder.jvm.arguments", "-Xmx1024M"); setProperty("grinder.jvm.classpath", "abc;def"); }}; final Properties systemProperties = new Properties() {{ setProperty("grinder.processes", "99"); setProperty("java.class.path", "jvd;vg;nc"); }}; final WorkerProcessCommandLine workerProcessCommandLine = new WorkerProcessCommandLine(grinderProperties, systemProperties, grinderProperties.getProperty("grinder.jvm.arguments"), new Directory()); String commandLine = workerProcessCommandLine.toString(); final String expectedPrefix = "java '-Xmx1024M' "; assertTrue(commandLine, commandLine.startsWith(expectedPrefix)); commandLine = commandLine.substring(expectedPrefix.length()); final String expectedSuffix = "-classpath 'abc;def" + File.pathSeparatorChar + "jvd;vg;nc' " + "net.grinder.engine.process.WorkerProcessEntryPoint"; assertEquals(expectedSuffix, commandLine); }