You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2006/07/05 05:59:39 UTC
[jira] Updated: (SANDBOX-62) [Exec] allow easy mocking of Process
creation
[ http://issues.apache.org/jira/browse/SANDBOX-62?page=all ]
Henri Yandell updated SANDBOX-62:
---------------------------------
Component: Exec
> [Exec] allow easy mocking of Process creation
> ---------------------------------------------
>
> Key: SANDBOX-62
> URL: http://issues.apache.org/jira/browse/SANDBOX-62
> Project: Commons Sandbox
> Type: Bug
> Components: Exec
> Environment: Operating System: other
> Platform: Other
> Reporter: Jerome Lacoste
> Attachments: 36707_allow_mocking_process_in_execute.diff
>
> 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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org