commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siegfried Goeschl (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (SANDBOX-62) [Exec] allow easy mocking of Process creation
Date Wed, 02 Jan 2008 18:20:34 GMT

     [ https://issues.apache.org/jira/browse/SANDBOX-62?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Siegfried Goeschl resolved SANDBOX-62.
--------------------------------------

    Resolution: Fixed

Made DefaultExecutor.launch() protected to enable mocking

> [Exec] allow easy mocking of Process creation
> ---------------------------------------------
>
>                 Key: SANDBOX-62
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-62
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: Exec
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Jerome Lacoste
>            Assignee: Siegfried Goeschl
>         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.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message