@@ -391,16 +391,22 @@ public void testExecuteWithRsyncFailure() throws Exception {
391391
392392 try (MockedStatic <Script > scriptMock = mockStatic (Script .class )) {
393393 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString (), anyInt (), any (Boolean .class )))
394- .thenReturn (0 ); // Mount success
394+ .thenAnswer (invocation -> {
395+ String command = invocation .getArgument (0 );
396+ if (command .contains ("mount" )) {
397+ return 0 ; // File exists
398+ } else if (command .contains ("rsync" )) {
399+ return 1 ; // Rsync failure
400+ }
401+ return 0 ; // Other commands success
402+ });
395403 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString ()))
396404 .thenAnswer (invocation -> {
397405 String command = invocation .getArgument (0 );
398406 if (command .contains ("ls " )) {
399407 return 0 ; // File exists
400408 } else if (command .contains ("qemu-img check" )) {
401409 return 0 ; // File is valid
402- } else if (command .contains ("rsync" )) {
403- return 1 ; // Rsync failure
404410 }
405411 return 0 ; // Other commands success
406412 });
@@ -444,16 +450,22 @@ public void testExecuteWithAttachVolumeFailure() throws Exception {
444450
445451 try (MockedStatic <Script > scriptMock = mockStatic (Script .class )) {
446452 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString (), anyInt (), any (Boolean .class )))
447- .thenReturn (0 ); // Mount success
453+ .thenAnswer (invocation -> {
454+ String command = invocation .getArgument (0 );
455+ if (command .contains ("mount" )) {
456+ return 0 ; // File exists
457+ } else if (command .contains ("rsync" )) {
458+ return 0 ; // Rsync success
459+ }
460+ return 0 ; // Other commands success
461+ });
448462 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString ()))
449463 .thenAnswer (invocation -> {
450464 String command = invocation .getArgument (0 );
451465 if (command .contains ("ls " )) {
452466 return 0 ; // File exists
453467 } else if (command .contains ("qemu-img check" )) {
454468 return 0 ; // File is valid
455- } else if (command .contains ("rsync" )) {
456- return 0 ; // Rsync success
457469 } else if (command .contains ("virsh attach-disk" )) {
458470 return 1 ; // Attach failure
459471 }
@@ -540,9 +552,7 @@ public void testExecuteWithMultipleVolumes() throws Exception {
540552
541553 try (MockedStatic <Script > scriptMock = mockStatic (Script .class )) {
542554 scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString (), anyInt (), any (Boolean .class )))
543- .thenReturn (0 ); // Mount success
544- scriptMock .when (() -> Script .runSimpleBashScriptForExitValue (anyString ()))
545- .thenReturn (0 ); // All other commands success
555+ .thenReturn (0 ); // All commands success
546556
547557 filesMock .when (() -> Files .deleteIfExists (any (Path .class ))).thenReturn (true );
548558
0 commit comments