-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update Mockito to 5.16.1 #10686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Mockito to 5.16.1 #10686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -704,7 +704,7 @@ private void configureAndVerifyTestSearchDiskDefOnMigrateDiskInfoList(String ser | |||||||
|
|
||||||||
| @Test | ||||||||
| public void deleteOrDisconnectDisksOnSourcePoolTest() { | ||||||||
| LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = Mockito.spy(libvirtMigrateCmdWrapper); | ||||||||
| LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = libvirtMigrateCmdWrapper; | ||||||||
| Mockito.doNothing().when(spyLibvirtMigrateCmdWrapper).deleteLocalVolume("volPath"); | ||||||||
|
Comment on lines
+707
to
708
|
||||||||
| LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = libvirtMigrateCmdWrapper; | |
| Mockito.doNothing().when(spyLibvirtMigrateCmdWrapper).deleteLocalVolume("volPath"); | |
| Mockito.doNothing().when(libvirtMigrateCmdWrapper).deleteLocalVolume("volPath"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,8 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import com.cloud.agent.api.Command; | ||
| import com.cloud.agent.api.ScaleVmAnswer; | ||
| import com.cloud.hypervisor.vmware.mo.DatastoreMO; | ||
| import com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO; | ||
| import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper; | ||
|
|
@@ -52,7 +54,6 @@ | |
| import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer; | ||
| import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsCommand; | ||
| import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
@@ -62,17 +63,14 @@ | |
| import org.mockito.MockedConstruction; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.mockito.Spy; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import com.cloud.agent.api.Answer; | ||
| import com.cloud.agent.api.Command; | ||
| import com.cloud.agent.api.CheckGuestOsMappingAnswer; | ||
| import com.cloud.agent.api.CheckGuestOsMappingCommand; | ||
| import com.cloud.agent.api.GetHypervisorGuestOsNamesAnswer; | ||
| import com.cloud.agent.api.GetHypervisorGuestOsNamesCommand; | ||
| import com.cloud.agent.api.ScaleVmAnswer; | ||
| import com.cloud.agent.api.ScaleVmCommand; | ||
| import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer; | ||
| import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand; | ||
|
|
@@ -185,6 +183,8 @@ public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) { | |
| VimPortType vimService; | ||
| @Mock | ||
| HostCapability hostCapability; | ||
| @Mock | ||
| ManagedObjectReference _morHyperHost; | ||
JoaoJandre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CopyCommand storageCmd; | ||
| EnumMap<VmwareStorageProcessorConfigurableFields, Object> params = new EnumMap<VmwareStorageProcessorConfigurableFields,Object>(VmwareStorageProcessorConfigurableFields.class); | ||
|
|
@@ -201,11 +201,9 @@ public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) { | |
|
|
||
| private Map<String,String> specsArray = new HashMap<String,String>(); | ||
|
|
||
| AutoCloseable closeable; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| closeable = MockitoAnnotations.openMocks(this); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to remove it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class is annotated with I removed the line as it was unnecessary and could issues in some circumstances. |
||
| storageCmd = mock(CopyCommand.class); | ||
| doReturn(context).when(_resource).getServiceContext(null); | ||
| when(cmd.getVirtualMachine()).thenReturn(vmSpec); | ||
|
|
@@ -234,11 +232,6 @@ public void setup() throws Exception { | |
| when(hostCapability.isNestedHVSupported()).thenReturn(true); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| closeable.close(); | ||
| } | ||
|
|
||
| //Test successful scaling up the vm | ||
| @Test | ||
| public void testScaleVMF1() throws Exception { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,7 +154,7 @@ public void prepareForShutdownCmdOtherMsHostsInPreparingState() { | |
| ManagementServerHostVO msHost2 = mock(ManagementServerHostVO.class); | ||
| List<ManagementServerHostVO> msHostList = new ArrayList<>(); | ||
| msHostList.add(msHost2); | ||
| Mockito.when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.lenient().when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc mockito was throwing errors earlier when an unnecessary mocks was setup. Why is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be removed. I choose not to remove it because I did not want to significantly alter any logic of the tests as part of the Mockito version upgrade. It is unclear to me if the mock is not being used by accident and it should be used. I feel the discussion about the test intention should happen independently of the Mockito upgrade. |
||
| Mockito.when(msHostDao.findById(1L)).thenReturn(msHost1); | ||
| PrepareForShutdownCmd cmd = mock(PrepareForShutdownCmd.class); | ||
| Mockito.when(cmd.getManagementServerId()).thenReturn(1L); | ||
|
|
@@ -169,7 +169,7 @@ public void prepareForShutdownCmdNullResponseFromClusterManager() { | |
| ManagementServerHostVO msHost = mock(ManagementServerHostVO.class); | ||
| Mockito.when(msHost.getState()).thenReturn(ManagementServerHost.State.Up); | ||
| List<ManagementServerHostVO> msHostList = new ArrayList<>(); | ||
| Mockito.when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.lenient().when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.when(msHostDao.findById(1L)).thenReturn(msHost); | ||
| PrepareForShutdownCmd cmd = mock(PrepareForShutdownCmd.class); | ||
| Mockito.when(cmd.getManagementServerId()).thenReturn(1L); | ||
|
|
@@ -185,7 +185,7 @@ public void prepareForShutdownCmdFailedResponseFromClusterManager() { | |
| ManagementServerHostVO msHost = mock(ManagementServerHostVO.class); | ||
| Mockito.when(msHost.getState()).thenReturn(ManagementServerHost.State.Up); | ||
| List<ManagementServerHostVO> msHostList = new ArrayList<>(); | ||
| Mockito.when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.lenient().when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.when(msHostDao.findById(1L)).thenReturn(msHost); | ||
| PrepareForShutdownCmd cmd = mock(PrepareForShutdownCmd.class); | ||
| Mockito.when(cmd.getManagementServerId()).thenReturn(1L); | ||
|
|
@@ -200,7 +200,7 @@ public void prepareForShutdownCmdFailedResponseFromClusterManager() { | |
| public void prepareForShutdownCmdSuccessResponseFromClusterManager() { | ||
| ManagementServerHostVO msHost = mock(ManagementServerHostVO.class); | ||
| Mockito.when(msHost.getState()).thenReturn(ManagementServerHost.State.Up); | ||
| Mockito.when(msHostDao.listBy(any())).thenReturn(new ArrayList<>()); | ||
| Mockito.lenient().when(msHostDao.listBy(any())).thenReturn(new ArrayList<>()); | ||
| Mockito.when(msHostDao.findById(1L)).thenReturn(msHost); | ||
| Mockito.when(hostDao.listByMs(anyLong())).thenReturn(new ArrayList<>()); | ||
| PrepareForShutdownCmd cmd = mock(PrepareForShutdownCmd.class); | ||
|
|
@@ -279,7 +279,7 @@ public void triggerShutdownCmdMsInUpStateAndOtherMsHostsInPreparingState() { | |
| ManagementServerHostVO msHost2 = mock(ManagementServerHostVO.class); | ||
| List<ManagementServerHostVO> msHostList = new ArrayList<>(); | ||
| msHostList.add(msHost2); | ||
| Mockito.when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.lenient().when(msHostDao.listBy(any())).thenReturn(msHostList); | ||
| Mockito.when(msHostDao.findById(1L)).thenReturn(msHost1); | ||
| TriggerShutdownCmd cmd = mock(TriggerShutdownCmd.class); | ||
| Mockito.when(cmd.getManagementServerId()).thenReturn(1L); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.