@@ -103,11 +103,11 @@ public void testExecuteWithSeparateArgument() throws Exception {
103
103
*/
104
104
@ Test
105
105
void testExecute () throws Exception {
106
- String command = getJavaCommand () + " --version" ;
106
+ String [] command = new String [] { getJavaCommand (), " --version" } ;
107
107
tasklet .setCommand (command );
108
108
tasklet .afterPropertiesSet ();
109
109
110
- log .info ("Executing command: " + command );
110
+ log .info ("Executing command: " + String . join ( " " , command ) );
111
111
RepeatStatus exitStatus = tasklet .execute (stepExecution .createStepContribution (), null );
112
112
113
113
assertEquals (RepeatStatus .FINISHED , exitStatus );
@@ -118,21 +118,21 @@ void testExecute() throws Exception {
118
118
*/
119
119
@ Test
120
120
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" } ;
122
122
tasklet .setCommand (command );
123
123
tasklet .setTimeout (200L );
124
124
tasklet .afterPropertiesSet ();
125
125
126
- log .info ("Executing command: " + command );
126
+ log .info ("Executing command: " + String . join ( " " , command ) );
127
127
try {
128
128
StepContribution contribution = stepExecution .createStepContribution ();
129
129
RepeatStatus exitStatus = tasklet .execute (contribution , null );
130
130
assertEquals (RepeatStatus .FINISHED , exitStatus );
131
131
assertEquals (ExitStatus .FAILED , contribution .getExitStatus ());
132
132
}
133
- catch (RuntimeException e ) {
133
+ catch (Exception e ) {
134
134
// 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" ));
136
136
}
137
137
}
138
138
@@ -141,7 +141,7 @@ void testExecuteFailure() throws Exception {
141
141
*/
142
142
@ Test
143
143
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" } ;
145
145
tasklet .setCommand (command );
146
146
tasklet .afterPropertiesSet ();
147
147
@@ -153,12 +153,12 @@ void testExecuteException() throws Exception {
153
153
*/
154
154
@ Test
155
155
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" } ;
157
157
tasklet .setCommand (command );
158
158
tasklet .setTimeout (10 );
159
159
tasklet .afterPropertiesSet ();
160
160
161
- log .info ("Executing command: " + command );
161
+ log .info ("Executing command: " + String . join ( " " , command ) );
162
162
Exception exception = assertThrows (SystemCommandException .class , () -> tasklet .execute (null , null ));
163
163
assertTrue (exception .getMessage ().contains ("did not finish within the timeout" ));
164
164
}
@@ -168,7 +168,7 @@ void testExecuteTimeout() throws Exception {
168
168
*/
169
169
@ Test
170
170
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" } ;
172
172
tasklet .setCommand (command );
173
173
tasklet .setTerminationCheckInterval (10 );
174
174
tasklet .afterPropertiesSet ();
@@ -178,7 +178,7 @@ void testInterruption() throws Exception {
178
178
String message = exception .getMessage ();
179
179
System .out .println (message );
180
180
assertTrue (message .contains ("Job interrupted while executing system command" ));
181
- assertTrue (message .contains (command ));
181
+ assertTrue (message .contains (command [ 0 ] ));
182
182
}
183
183
184
184
/*
@@ -255,7 +255,8 @@ void testStopped() throws Exception {
255
255
when (jobExplorer .getJobExecution (1L )).thenReturn (stepExecution .getJobExecution (),
256
256
stepExecution .getJobExecution (), stoppedJobExecution );
257
257
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" };
259
260
tasklet .setCommand (command );
260
261
tasklet .setTerminationCheckInterval (10 );
261
262
tasklet .afterPropertiesSet ();
@@ -294,7 +295,7 @@ public void testExecuteWithSuccessfulCommandRunnerMockExecution() throws Excepti
294
295
StepContribution stepContribution = stepExecution .createStepContribution ();
295
296
CommandRunner commandRunner = mock (CommandRunner .class );
296
297
Process process = mock (Process .class );
297
- String command = "invalid command" ;
298
+ String [] command = new String [] { "invalid command" } ;
298
299
299
300
when (commandRunner .exec (eq (command ), any (), any ())).thenReturn (process );
300
301
when (process .waitFor ()).thenReturn (0 );
@@ -314,7 +315,7 @@ public void testExecuteWithFailedCommandRunnerMockExecution() throws Exception {
314
315
StepContribution stepContribution = stepExecution .createStepContribution ();
315
316
CommandRunner commandRunner = mock (CommandRunner .class );
316
317
Process process = mock (Process .class );
317
- String command = "invalid command" ;
318
+ String [] command = new String [] { "invalid command" } ;
318
319
319
320
when (commandRunner .exec (eq (command ), any (), any ())).thenReturn (process );
320
321
when (process .waitFor ()).thenReturn (1 );
0 commit comments