You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by nv...@apache.org on 2023/11/08 17:21:37 UTC

(cloudstack) branch main updated: Remove powermock form VM Manager test (#8199)

This is an automated email from the ASF dual-hosted git repository.

nvazquez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new d3917ef8f68 Remove powermock form VM Manager test (#8199)
d3917ef8f68 is described below

commit d3917ef8f6818e08c0d38c82b60cc49cdbf5d710
Author: Vishesh <vi...@gmail.com>
AuthorDate: Wed Nov 8 22:51:32 2023 +0530

    Remove powermock form VM Manager test (#8199)
---
 .../cloud/vm/VirtualMachineManagerImplTest.java    | 48 +++++++++++-----------
 .../org.mockito.plugins.MockMaker                  |  1 +
 2 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java
index 20af10ed338..cf194462719 100644
--- a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java
+++ b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java
@@ -66,8 +66,10 @@ import org.junit.runner.RunWith;
 import org.mockito.InOrder;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.MockedStatic;
 import org.mockito.Mockito;
 import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
 
 import com.cloud.agent.AgentManager;
@@ -107,15 +109,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.VMInstanceDao;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 import org.springframework.test.util.ReflectionTestUtils;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(CallContext.class)
-@PowerMockIgnore({"javax.xml.*", "org.w3c.dom.*", "org.apache.xerces.*", "org.xml.*"})
+@RunWith(MockitoJUnitRunner.class)
 public class VirtualMachineManagerImplTest {
 
     @Spy
@@ -1014,15 +1010,16 @@ public class VirtualMachineManagerImplTest {
         doReturn(false).when(virtualMachineManagerImpl).areAllVolumesAllocated(Mockito.anyLong());
 
         CallContext callContext = mock(CallContext.class);
-        Mockito.when(callContext.getCallingAccount()).thenReturn(account);
-        Mockito.when(callContext.getCallingUser()).thenReturn(user);
-        PowerMockito.mockStatic(CallContext.class);
-        PowerMockito.when(CallContext.current()).thenReturn(callContext);
-
-        try {
-            virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner);
-        } catch (CloudRuntimeException e) {
-            assertEquals(e.getMessage(), "Error while transitioning");
+        when(callContext.getCallingAccount()).thenReturn(account);
+        when(callContext.getCallingUser()).thenReturn(user);
+        try (MockedStatic<CallContext> ignored = Mockito.mockStatic(CallContext.class)) {
+            when(CallContext.current()).thenReturn(callContext);
+
+            try {
+                virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner);
+            } catch (CloudRuntimeException e) {
+                assertEquals(e.getMessage(), "Error while transitioning");
+            }
         }
 
         assertEquals(vmInstance.getPodIdToDeployIn(), (Long) destPod.getId());
@@ -1106,15 +1103,16 @@ public class VirtualMachineManagerImplTest {
         doReturn(true).when(virtualMachineManagerImpl).areAllVolumesAllocated(Mockito.anyLong());
 
         CallContext callContext = mock(CallContext.class);
-        Mockito.when(callContext.getCallingAccount()).thenReturn(account);
-        Mockito.when(callContext.getCallingUser()).thenReturn(user);
-        PowerMockito.mockStatic(CallContext.class);
-        PowerMockito.when(CallContext.current()).thenReturn(callContext);
-
-        try {
-            virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner);
-        } catch (CloudRuntimeException e) {
-            assertEquals(e.getMessage(), "Error while transitioning");
+        when(callContext.getCallingAccount()).thenReturn(account);
+        when(callContext.getCallingUser()).thenReturn(user);
+        try (MockedStatic<CallContext> ignored = Mockito.mockStatic(CallContext.class)) {
+            when(CallContext.current()).thenReturn(callContext);
+
+            try {
+                virtualMachineManagerImpl.orchestrateStart("vm-uuid", params, plan, planner);
+            } catch (CloudRuntimeException e) {
+                assertEquals(e.getMessage(), "Error while transitioning");
+            }
         }
 
         assertNull(vmInstance.getPodIdToDeployIn());
diff --git a/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 00000000000..1f0955d450f
--- /dev/null
+++ b/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline