@@ -103,11 +103,11 @@ public void testExecuteWithSeparateArgument() throws Exception {
103103 */
104104 @ Test
105105 void testExecute () throws Exception {
106- String command = getJavaCommand () + " --version" ;
106+ String [] command = new String [] { getJavaCommand (), " --version" } ;
107107 tasklet .setCommand (command );
108108 tasklet .afterPropertiesSet ();
109109
110- log .info ("Executing command: " + command );
110+ log .info ("Executing command: " + String . join ( " " , command ) );
111111 RepeatStatus exitStatus = tasklet .execute (stepExecution .createStepContribution (), null );
112112
113113 assertEquals (RepeatStatus .FINISHED , exitStatus );
@@ -118,21 +118,21 @@ void testExecute() throws Exception {
118118 */
119119 @ Test
120120 void testExecuteFailure () throws Exception {
121- String command = getJavaCommand () + " org.springframework.batch.sample.tasklet.UnknownClass" ;
121+ String [] command = new String [] { getJavaCommand () + " org.springframework.batch.sample.tasklet.UnknownClass" } ;
122122 tasklet .setCommand (command );
123123 tasklet .setTimeout (200L );
124124 tasklet .afterPropertiesSet ();
125125
126- log .info ("Executing command: " + command );
126+ log .info ("Executing command: " + String . join ( " " , command ) );
127127 try {
128128 StepContribution contribution = stepExecution .createStepContribution ();
129129 RepeatStatus exitStatus = tasklet .execute (contribution , null );
130130 assertEquals (RepeatStatus .FINISHED , exitStatus );
131131 assertEquals (ExitStatus .FAILED , contribution .getExitStatus ());
132132 }
133- catch (RuntimeException e ) {
133+ catch (Exception e ) {
134134 // on some platforms the system call does not return
135- assertEquals ( "Execution of system command did not finish within the timeout" , e .getMessage ());
135+ assertTrue ( e .getMessage (). contains ( "Cannot run program" ));
136136 }
137137 }
138138
@@ -141,7 +141,7 @@ void testExecuteFailure() throws Exception {
141141 */
142142 @ Test
143143 void testExecuteException () throws Exception {
144- String command = "non-sense-that-should-cause-exception-when-attempted-to-execute" ;
144+ String [] command = new String [] { "non-sense-that-should-cause-exception-when-attempted-to-execute" } ;
145145 tasklet .setCommand (command );
146146 tasklet .afterPropertiesSet ();
147147
@@ -153,12 +153,12 @@ void testExecuteException() throws Exception {
153153 */
154154 @ Test
155155 void testExecuteTimeout () throws Exception {
156- String command = isRunningOnWindows () ? "ping 127.0.0.1" : "sleep 3" ;
156+ String [] command = isRunningOnWindows () ? new String [] { "ping" , " 127.0.0.1" } : new String [] { "sleep" , "3" } ;
157157 tasklet .setCommand (command );
158158 tasklet .setTimeout (10 );
159159 tasklet .afterPropertiesSet ();
160160
161- log .info ("Executing command: " + command );
161+ log .info ("Executing command: " + String . join ( " " , command ) );
162162 Exception exception = assertThrows (SystemCommandException .class , () -> tasklet .execute (null , null ));
163163 assertTrue (exception .getMessage ().contains ("did not finish within the timeout" ));
164164 }
@@ -168,7 +168,7 @@ void testExecuteTimeout() throws Exception {
168168 */
169169 @ Test
170170 void testInterruption () throws Exception {
171- String command = isRunningOnWindows () ? "ping 127.0.0.1" : "sleep 5" ;
171+ String [] command = isRunningOnWindows () ? new String [] { "ping" , " 127.0.0.1" } : new String [] { "sleep" , "5" } ;
172172 tasklet .setCommand (command );
173173 tasklet .setTerminationCheckInterval (10 );
174174 tasklet .afterPropertiesSet ();
@@ -178,7 +178,7 @@ void testInterruption() throws Exception {
178178 String message = exception .getMessage ();
179179 System .out .println (message );
180180 assertTrue (message .contains ("Job interrupted while executing system command" ));
181- assertTrue (message .contains (command ));
181+ assertTrue (message .contains (command [ 0 ] ));
182182 }
183183
184184 /*
@@ -255,7 +255,8 @@ void testStopped() throws Exception {
255255 when (jobExplorer .getJobExecution (1L )).thenReturn (stepExecution .getJobExecution (),
256256 stepExecution .getJobExecution (), stoppedJobExecution );
257257
258- String command = isRunningOnWindows () ? "ping 127.0.0.1 -n 5" : "sleep 15" ;
258+ String [] command = isRunningOnWindows () ? new String [] { "ping" , "127.0.0.1" , "-n" , "5" }
259+ : new String [] { "sleep" , "15" };
259260 tasklet .setCommand (command );
260261 tasklet .setTerminationCheckInterval (10 );
261262 tasklet .afterPropertiesSet ();
@@ -294,7 +295,7 @@ public void testExecuteWithSuccessfulCommandRunnerMockExecution() throws Excepti
294295 StepContribution stepContribution = stepExecution .createStepContribution ();
295296 CommandRunner commandRunner = mock (CommandRunner .class );
296297 Process process = mock (Process .class );
297- String command = "invalid command" ;
298+ String [] command = new String [] { "invalid command" } ;
298299
299300 when (commandRunner .exec (eq (command ), any (), any ())).thenReturn (process );
300301 when (process .waitFor ()).thenReturn (0 );
@@ -314,7 +315,7 @@ public void testExecuteWithFailedCommandRunnerMockExecution() throws Exception {
314315 StepContribution stepContribution = stepExecution .createStepContribution ();
315316 CommandRunner commandRunner = mock (CommandRunner .class );
316317 Process process = mock (Process .class );
317- String command = "invalid command" ;
318+ String [] command = new String [] { "invalid command" } ;
318319
319320 when (commandRunner .exec (eq (command ), any (), any ())).thenReturn (process );
320321 when (process .waitFor ()).thenReturn (1 );
0 commit comments