### Question:
CommandRunner { List<String> execute(String jobName, String command) throws IOException, InterruptedException { try { if (logger != null && logger.isLoggable(Level.FINER)) { logger.entering(CommandRunner.class.getName(), "execute"); } if (command == null) { return Collections.emptyList(); } if (command.isEmpty()) { return Collections.emptyList(); } if (logger != null && logger.isLoggable(Level.INFO)) { logger.info( MessageFormat.format("executing job ''{0}'' with command ''{1}''", jobName, command)); } final Process process = Runtime.getRuntime().exec(command); if (process.waitFor() != 0) { throw new RuntimeException( MessageFormat.format("Failed to execute job ''{0}''. Exit value is {1}.", jobName, process.exitValue())); } final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); final List<String> response = new LinkedList<>(); while (true) { final String line = reader.readLine(); if (line == null) { break; } response.add(line); } if (logger != null && logger.isLoggable(Level.INFO)) { logger.info(MessageFormat.format("job ''{0}'' is executed successfully", jobName)); } return response; } finally { if (logger != null && logger.isLoggable(Level.FINER)) { logger.exiting(CommandRunner.class.getName(), "execute"); } } } CommandRunner();   CommandRunner(Logger logger);   }### Answer:
@Test public void testResponse_NoLineExpected() throws Exception { final File executable = new File("/bin/sleep"); if (executable.canExecute()) { final CommandRunner runner = new CommandRunner(); final String jobName = "test"; final String command = "/bin/sleep 1"; final List<String> lines = runner.execute(jobName, command); assertNotNull(lines); assertTrue(lines.isEmpty()); } }
@Test public void testResponse_SingleLineExpected() throws Exception { final File executable = new File("/bin/echo"); if (executable.canExecute()) { final CommandRunner runner = new CommandRunner(); final String jobName = "test"; final String command = "/bin/echo Job <1711> is submitted successfully"; final List<String> lines = runner.execute(jobName, command); assertNotNull(lines); assertEquals(1, lines.size()); assertEquals("Job <1711> is submitted successfully", lines.get(0)); } }