Skip to content

Commit 7a0d61e

Browse files
CSTACKEX-18_2: fix junit issues
1 parent 9b79f46 commit 7a0d61e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/vmsnapshot/OntapVMSnapshotStrategyTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.mockito.Mockito.doNothing;
2828
import static org.mockito.Mockito.doReturn;
2929
import static org.mockito.Mockito.doThrow;
30+
import static org.mockito.Mockito.lenient;
3031
import static org.mockito.Mockito.mock;
3132
import static org.mockito.Mockito.never;
3233
import static org.mockito.Mockito.times;
@@ -54,6 +55,8 @@
5455
import org.mockito.Mock;
5556
import org.mockito.Spy;
5657
import org.mockito.junit.jupiter.MockitoExtension;
58+
import org.mockito.junit.jupiter.MockitoSettings;
59+
import org.mockito.quality.Strictness;
5760

5861
import com.cloud.agent.AgentManager;
5962
import com.cloud.agent.api.FreezeThawVMAnswer;
@@ -90,6 +93,7 @@
9093
* </ul>
9194
*/
9295
@ExtendWith(MockitoExtension.class)
96+
@MockitoSettings(strictness = Strictness.LENIENT)
9397
class OntapVMSnapshotStrategyTest {
9498

9599
private static final long VM_ID = 100L;
@@ -182,7 +186,7 @@ private VMSnapshotVO createMockVmSnapshot(VMSnapshot.State state, VMSnapshot.Typ
182186
when(vmSnapshot.getId()).thenReturn(SNAPSHOT_ID);
183187
when(vmSnapshot.getVmId()).thenReturn(VM_ID);
184188
when(vmSnapshot.getState()).thenReturn(state);
185-
when(vmSnapshot.getType()).thenReturn(type);
189+
lenient().when(vmSnapshot.getType()).thenReturn(type);
186190
return vmSnapshot;
187191
}
188192

@@ -570,7 +574,7 @@ void testTakeVMSnapshot_FreezeFailure_ThrowsException() throws Exception {
570574

571575
// Cleanup mocks for finally block
572576
when(vmSnapshotDetailsDao.listDetails(SNAPSHOT_ID)).thenReturn(Collections.emptyList());
573-
doNothing().when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
577+
doReturn(true).when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
574578

575579
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class,
576580
() -> strategy.takeVMSnapshot(vmSnapshot));
@@ -591,7 +595,7 @@ void testTakeVMSnapshot_FreezeReturnsNull_ThrowsException() throws Exception {
591595
when(agentMgr.send(eq(HOST_ID), any(FreezeThawVMCommand.class))).thenReturn(null);
592596

593597
when(vmSnapshotDetailsDao.listDetails(SNAPSHOT_ID)).thenReturn(Collections.emptyList());
594-
doNothing().when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
598+
doReturn(true).when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
595599

596600
assertThrows(CloudRuntimeException.class, () -> strategy.takeVMSnapshot(vmSnapshot));
597601
}
@@ -616,7 +620,7 @@ void testTakeVMSnapshot_DiskSnapshotFails_RollbackAndThaw() throws Exception {
616620

617621
// Cleanup mocks
618622
when(vmSnapshotDetailsDao.listDetails(SNAPSHOT_ID)).thenReturn(Collections.emptyList());
619-
doNothing().when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
623+
doReturn(true).when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
620624

621625
assertThrows(CloudRuntimeException.class, () -> strategy.takeVMSnapshot(vmSnapshot));
622626

@@ -634,7 +638,7 @@ void testTakeVMSnapshot_AgentUnavailable_ThrowsCloudRuntimeException() throws Ex
634638
.thenThrow(new AgentUnavailableException(HOST_ID));
635639

636640
when(vmSnapshotDetailsDao.listDetails(SNAPSHOT_ID)).thenReturn(Collections.emptyList());
637-
doNothing().when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
641+
doReturn(true).when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
638642

639643
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class,
640644
() -> strategy.takeVMSnapshot(vmSnapshot));
@@ -651,7 +655,7 @@ void testTakeVMSnapshot_OperationTimeout_ThrowsCloudRuntimeException() throws Ex
651655
.thenThrow(new OperationTimedoutException(null, 0, 0, 0, false));
652656

653657
when(vmSnapshotDetailsDao.listDetails(SNAPSHOT_ID)).thenReturn(Collections.emptyList());
654-
doNothing().when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
658+
doReturn(true).when(vmSnapshotHelper).vmSnapshotStateTransitTo(any(), eq(VMSnapshot.Event.OperationFailed));
655659

656660
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class,
657661
() -> strategy.takeVMSnapshot(vmSnapshot));
@@ -663,8 +667,6 @@ void testTakeVMSnapshot_StateTransitionFails_ThrowsCloudRuntimeException() throw
663667
VMSnapshotVO vmSnapshot = createTakeSnapshotVmSnapshot();
664668
when(vmSnapshotHelper.pickRunningHost(VM_ID)).thenReturn(HOST_ID);
665669
UserVmVO userVm = mock(UserVmVO.class);
666-
when(userVm.getGuestOSId()).thenReturn(GUEST_OS_ID);
667-
when(userVm.getId()).thenReturn(VM_ID);
668670
when(userVmDao.findById(VM_ID)).thenReturn(userVm);
669671

670672
// State transition fails
@@ -786,10 +788,10 @@ private VMSnapshotVO createTakeSnapshotVmSnapshot() {
786788
VMSnapshotVO vmSnapshot = mock(VMSnapshotVO.class);
787789
when(vmSnapshot.getId()).thenReturn(SNAPSHOT_ID);
788790
when(vmSnapshot.getVmId()).thenReturn(VM_ID);
789-
when(vmSnapshot.getName()).thenReturn("vm-snap-1");
790-
when(vmSnapshot.getType()).thenReturn(VMSnapshot.Type.Disk);
791-
when(vmSnapshot.getDescription()).thenReturn("Test ONTAP VM Snapshot");
792-
when(vmSnapshot.getOptions()).thenReturn(new VMSnapshotOptions(true));
791+
lenient().when(vmSnapshot.getName()).thenReturn("vm-snap-1");
792+
lenient().when(vmSnapshot.getType()).thenReturn(VMSnapshot.Type.Disk);
793+
lenient().when(vmSnapshot.getDescription()).thenReturn("Test ONTAP VM Snapshot");
794+
lenient().when(vmSnapshot.getOptions()).thenReturn(new VMSnapshotOptions(true));
793795
return vmSnapshot;
794796
}
795797

@@ -809,7 +811,7 @@ private UserVmVO setupTakeSnapshotCommon(VMSnapshotVO vmSnapshot) throws Excepti
809811

810812
when(vmSnapshotDao.findCurrentSnapshotByVmId(VM_ID)).thenReturn(null);
811813

812-
doNothing().when(vmSnapshotHelper).vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.CreateRequested);
814+
doReturn(true).when(vmSnapshotHelper).vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.CreateRequested);
813815

814816
return userVm;
815817
}

0 commit comments

Comments
 (0)