DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=36707>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=36707 Summary: [Exec] allow easy mocking of Process creation Product: Commons Version: unspecified Platform: Other OS/Version: other Status: NEW Severity: normal Priority: P2 Component: Sandbox AssignedTo: commons-dev@jakarta.apache.org ReportedBy: [EMAIL PROTECTED] In order to do proper unit testing, it is practical to use mocked Process instances. Unfortunately the Execute class doesn't make it easy to plug these classes. It calls the public static launch() method (which cannot be overriden) and that method uses the vmlauncher which cannot be replaced. I see 3 options: - mock the Process creation. Create a protected launchCommand() method that does call the public static launch() method. That protected method can be overriden by sub-classes. public static Process launch(final CommandLine command, final Environment env, final File dir) throws IOException { CommandLauncher launcher = vmLauncher; if (dir != null && !dir.exists()) { throw new IOException(dir + " doesn't exist."); } return launcher.exec(command, env, dir); } // hook for mock protected Process launchCommand(final CommandLine command, final Environment env, final File dir) throws IOException { return launch(command, env, dir); } - mock the Launcher creation which will itself be mocked. public static Process launch(final CommandLine command, final Environment env, final File dir) throws IOException { return launch(command, env, dir, vmLauncher); } private static Process launch(final CommandLine command, final Environment env, final File dir, CommandLauncher launcher) throws IOException { if (dir != null && !dir.exists()) { throw new IOException(dir + " doesn't exist."); } return launcher.exec(command, env, dir); } private Process launchCommand(final CommandLine command, final Environment env, final File dir) throws IOException { return launch(command, env, dir, getLauncher()); } // hook for mock protected CommandLauncher getLauncher() { return vmlauncher; } - a combination of both I attach a patch that solves it using solution #1. -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]