@@ -74,36 +74,42 @@ private List<String> echoCommand(String... args) {
7474 : List .of ("echo" , String .join (" " , args ));
7575 }
7676
77- @ SuppressWarnings ("SameParameterValue" )
78- private List <String > envEchoCommand (String var ) {
77+ @ BeforeEach
78+ void setUp () {
79+ testLogHandler .clear ();
80+ }
81+
82+ @ SuppressWarnings ("PMD.AvoidUsingHardCodedIP" )
83+ private List <String > sleepCommand () {
7984 return SystemTools .isWindows ()
80- ? List .of ("cmd" , "/c" , "echo" , "%" + var + "%" )
81- : List .of ("sh " , "-c" , "echo $" + var );
85+ ? List .of ("cmd" , "/c" , "ping -n 12 127.0.0.1" ) // single arg
86+ : List .of ("sleep " , "5" );
8287 }
8388
84- @ SuppressWarnings ("SameParameterValue" )
85- private List <String > exitCommand (int code ) {
89+ private List <String > blockingCommand () {
8690 return SystemTools .isWindows ()
87- ? List .of ("cmd" , "/c" , "exit" , String . valueOf ( code ))
88- : List .of ("sh" , "-c" , "exit " + code );
91+ ? List .of ("cmd" , "/c" , "echo started & ping -n 12 127.0.0.1" ) // single arg
92+ : List .of ("sh" , "-c" , "echo started; sleep 10" );
8993 }
9094
9195 private List <String > multiLineEchoCommand () {
9296 return SystemTools .isWindows ()
93- ? List .of ("cmd" , "/c" , "echo line1& echo line2" )
97+ ? List .of ("cmd" , "/c" , "echo line1 & echo line2" ) // single arg
9498 : List .of ("sh" , "-c" , "echo line1; echo line2" );
9599 }
96100
97- @ BeforeEach
98- void setUp () {
99- testLogHandler .clear ();
101+ @ SuppressWarnings ("SameParameterValue" )
102+ private List <String > envEchoCommand (String var ) {
103+ return SystemTools .isWindows ()
104+ ? List .of ("cmd" , "/c" , "echo %" + var + "%" ) // single arg
105+ : List .of ("sh" , "-c" , "echo $" + var );
100106 }
101107
102- @ SuppressWarnings ("PMD.AvoidUsingHardCodedIP " )
103- private List <String > sleepCommand ( ) {
108+ @ SuppressWarnings ("SameParameterValue " )
109+ private List <String > exitCommand ( int code ) {
104110 return SystemTools .isWindows ()
105- ? List .of ("cmd" , "/c" , "ping" , "-n" , "12" , "127.0.0.1" ) // no > nul
106- : List .of ("sleep " , "5" );
111+ ? List .of ("cmd" , "/c" , "exit " + code ) // single arg
112+ : List .of ("sh " , "-c" , "exit " + code );
107113 }
108114
109115 @ Nested
@@ -473,13 +479,8 @@ void cleanupThreadInterruptedOnTimeout(@TempDir Path tmp) throws Exception {
473479 var interrupted = new AtomicBoolean (false );
474480 var started = new CountDownLatch (1 );
475481
476- // Windows: don't redirect, or the echo disappears
477- var blockingCmd = SystemTools .isWindows ()
478- ? List .of ("cmd" , "/c" , "echo started & ping -n 12 127.0.0.1" )
479- : List .of ("sh" , "-c" , "echo started; sleep 10" );
480-
481482 var result = createBasicExecutor (tmp .toFile ())
482- .command (blockingCmd )
483+ .command (blockingCommand () )
483484 .timeout (1 )
484485 .outputConsumer (line -> {
485486 if ("started" .equals (line )) {
@@ -501,7 +502,7 @@ void cleanupThreadInterruptedOnTimeout(@TempDir Path tmp) throws Exception {
501502
502503 @ Test
503504 @ DisplayName ("cleanupThread handles null thread" )
504- void cleanupThreadWithNullThread (@ TempDir Path tmp ) throws Exception {
505+ void cleanupThreadWithNullThread (@ TempDir Path tmp ) {
505506 // inheritIO=true means startOutputReader returns null
506507 assertDoesNotThrow (() -> createBasicExecutor (tmp .toFile ())
507508 .command (echoCommand (FOO ))
@@ -526,7 +527,7 @@ void cleanupThreadWithFinishedThread(@TempDir Path tmp) throws Exception {
526527
527528 @ Test
528529 @ DisplayName ("cleanupThread restores interrupt flag if interrupted during join" )
529- void cleanupThreadRestoresInterruptFlag () throws Exception {
530+ void cleanupThreadRestoresInterruptFlag () {
530531 class TestExecutor extends ProcessExecutor <TestExecutor > {
531532 void testCleanupThread () {
532533 var thread = new Thread (() -> {
0 commit comments