@@ -370,16 +370,22 @@ public void testExecuteWithRsyncFailure() throws Exception {
370370
371371 try (MockedStatic <Script > scriptMock = mockStatic (Script .class )) {
372372 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString (), anyInt (), any (Boolean .class )))
373- .thenReturn (0 ); // Mount success
373+ .thenAnswer (invocation -> {
374+ String command = invocation .getArgument (0 );
375+ if (command .contains ("mount" )) {
376+ return 0 ; // File exists
377+ } else if (command .contains ("rsync" )) {
378+ return 1 ; // Rsync failure
379+ }
380+ return 0 ; // Other commands success
381+ });
374382 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString ()))
375383 .thenAnswer (invocation -> {
376384 String command = invocation .getArgument (0 );
377385 if (command .contains ("ls " )) {
378386 return 0 ; // File exists
379387 } else if (command .contains ("qemu-img check" )) {
380388 return 0 ; // File is valid
381- } else if (command .contains ("rsync" )) {
382- return 1 ; // Rsync failure
383389 }
384390 return 0 ; // Other commands success
385391 });
@@ -420,16 +426,22 @@ public void testExecuteWithAttachVolumeFailure() throws Exception {
420426
421427 try (MockedStatic <Script > scriptMock = mockStatic (Script .class )) {
422428 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString (), anyInt (), any (Boolean .class )))
423- .thenReturn (0 ); // Mount success
429+ .thenAnswer (invocation -> {
430+ String command = invocation .getArgument (0 );
431+ if (command .contains ("mount" )) {
432+ return 0 ; // File exists
433+ } else if (command .contains ("rsync" )) {
434+ return 0 ; // Rsync success
435+ }
436+ return 0 ; // Other commands success
437+ });
424438 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString ()))
425439 .thenAnswer (invocation -> {
426440 String command = invocation .getArgument (0 );
427441 if (command .contains ("ls " )) {
428442 return 0 ; // File exists
429443 } else if (command .contains ("qemu-img check" )) {
430444 return 0 ; // File is valid
431- } else if (command .contains ("rsync" )) {
432- return 0 ; // Rsync success
433445 } else if (command .contains ("virsh attach-disk" )) {
434446 return 1 ; // Attach failure
435447 }
@@ -511,9 +523,7 @@ public void testExecuteWithMultipleVolumes() throws Exception {
511523
512524 try (MockedStatic <Script > scriptMock = mockStatic (Script .class )) {
513525 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString (), anyInt (), any (Boolean .class )))
514- .thenReturn (0 ); // Mount success
515- scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString ()))
516- .thenReturn (0 ); // All other commands success
526+ .thenReturn (0 ); // All commands success
517527
518528 filesMock .when (() -> Files .deleteIfExists (any (Path .class ))).thenReturn (true );
519529
0 commit comments