commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dennis Lundberg (JIRA)" <j...@apache.org>
Subject [jira] Moved: (EXEC-21) [Exec] allow easy mocking of Process creation
Date Sat, 28 Jun 2008 05:41:46 GMT

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

Dennis Lundberg moved SANDBOX-62 to EXEC-21:
--------------------------------------------

    Component/s:     (was: Exec)
            Key: EXEC-21  (was: SANDBOX-62)
        Project: Commons Exec  (was: Commons Sandbox)

> [Exec] allow easy mocking of Process creation
> ---------------------------------------------
>
>                 Key: EXEC-21
>                 URL: https://issues.apache.org/jira/browse/EXEC-21
>             Project: Commons Exec
>          Issue Type: Bug
>         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