diff --git a/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java index 717b5c3262d..f69e8cea4f3 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java index f64df167e25..97737691ed6 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java @@ -39,7 +39,7 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.HashMap; import java.util.Map; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; @RunWith(MockitoJUnitRunner.class) public class AddObjectStoragePoolCmdTest { @@ -65,9 +65,11 @@ public class AddObjectStoragePoolCmdTest { Map details; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); details = new HashMap<>(); addObjectStoragePoolCmdSpy = Mockito.spy(new AddObjectStoragePoolCmd()); ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "name", name); @@ -81,14 +83,15 @@ public class AddObjectStoragePoolCmdTest { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test public void testAddObjectStore() throws DiscoveryException { Mockito.doReturn(objectStore).when(storageService).discoverObjectStore(Mockito.anyString(), - Mockito.anyString(), Mockito.anyString(), anyObject()); + Mockito.anyString(), Mockito.anyString(), any()); ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse(); - Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(anyObject()); + Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any()); addObjectStoragePoolCmdSpy.execute(); Mockito.verify(storageService, Mockito.times(1)) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java index 35be56d0c75..9fb133b1b48 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java @@ -37,9 +37,11 @@ public class DeleteObjectStoragePoolCmdTest { @Spy DeleteObjectStoragePoolCmd deleteObjectStoragePoolCmd; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); deleteObjectStoragePoolCmd = Mockito.spy(new DeleteObjectStoragePoolCmd()); deleteObjectStoragePoolCmd._storageService = storageService; } @@ -47,6 +49,7 @@ public class DeleteObjectStoragePoolCmdTest { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java index 5244ff1ef9a..fbf4d2c495d 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java @@ -23,7 +23,7 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class FindStoragePoolsForMigrationCmdTest { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java index ef66c2a1a64..756869ee228 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java @@ -33,7 +33,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.springframework.test.util.ReflectionTestUtils; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; public class UpdateObjectStoragePoolCmdTest { public static final Logger s_logger = Logger.getLogger(UpdateObjectStoragePoolCmdTest.class.getName()); @@ -56,9 +56,11 @@ public class UpdateObjectStoragePoolCmdTest { private String provider = "Simulator"; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); updateObjectStoragePoolCmd = Mockito.spy(new UpdateObjectStoragePoolCmd()); updateObjectStoragePoolCmd._storageService = storageService; updateObjectStoragePoolCmd._responseGenerator = responseGenerator; @@ -70,13 +72,14 @@ public class UpdateObjectStoragePoolCmdTest { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test public void testUpdateObjectStore() { Mockito.doReturn(objectStore).when(storageService).updateObjectStore(1L, updateObjectStoragePoolCmd); ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse(); - Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(anyObject()); + Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any()); updateObjectStoragePoolCmd.execute(); Mockito.verify(storageService, Mockito.times(1)) .updateObjectStore(1L, updateObjectStoragePoolCmd); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java index 1e4bb326f7e..2c43278a582 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.command.user.project.ActivateProjectCmd; @@ -57,7 +57,7 @@ public class ActivateProjectCmdTest extends TestCase { @Test public void testGetEntityOwnerIdForNullProject() { ProjectService projectService = Mockito.mock(ProjectService.class); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(null); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(null); activateProjectCmd._projectService = projectService; try { @@ -74,9 +74,9 @@ public class ActivateProjectCmdTest extends TestCase { ProjectService projectService = Mockito.mock(ProjectService.class); Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(project); - Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account); + Mockito.when(projectService.getProjectOwner(ArgumentMatchers.anyLong())).thenReturn(account); activateProjectCmd._projectService = projectService; Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java index 199ee00551d..f100822b8c7 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.command.user.account.AddAccountToProjectCmd; @@ -101,9 +101,9 @@ public class AddAccountToProjectCmdTest extends TestCase { Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(project); - Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account); + Mockito.when(projectService.getProjectOwner(ArgumentMatchers.anyLong())).thenReturn(account); addAccountToProjectCmd._projectService = projectService; Assert.assertEquals(2L, addAccountToProjectCmd.getEntityOwnerId()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java index d0cc8be716a..9ea3a6446e8 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java @@ -21,7 +21,7 @@ import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd; @@ -59,7 +59,7 @@ public class AddIpToVmNicTest extends TestCase { NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) + networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any())) .thenReturn(secIp); ipTonicCmd._networkService = networkService; @@ -79,7 +79,7 @@ public class AddIpToVmNicTest extends TestCase { AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) + networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any())) .thenReturn(null); ipTonicCmd._networkService = networkService; @@ -98,7 +98,7 @@ public class AddIpToVmNicTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); - Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(true); + Mockito.when(networkService.releaseSecondaryIpFromNic(ArgumentMatchers.anyInt())).thenReturn(true); removeIpFromNic._networkService = networkService; removeIpFromNic.execute(); @@ -109,7 +109,7 @@ public class AddIpToVmNicTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); - Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(false); + Mockito.when(networkService.releaseSecondaryIpFromNic(ArgumentMatchers.anyInt())).thenReturn(false); removeIpFromNic._networkService = networkService; successResponseGenerator = Mockito.mock(SuccessResponse.class); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java index 8760fc87556..a62c29e487a 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.ServerApiException; @@ -86,7 +86,7 @@ public class AddNetworkServiceProviderCmdTest extends TestCase { addNetworkServiceProviderCmd._networkService = networkService; PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class); - Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn( + Mockito.when(networkService.addProviderToPhysicalNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyList())).thenReturn( physicalNetworkServiceProvider); try { @@ -103,7 +103,7 @@ public class AddNetworkServiceProviderCmdTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); addNetworkServiceProviderCmd._networkService = networkService; - Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(null); + Mockito.when(networkService.addProviderToPhysicalNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyList())).thenReturn(null); try { addNetworkServiceProviderCmd.create(); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java index 46fd6905683..86a53787e08 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java @@ -18,7 +18,7 @@ package org.apache.cloudstack.api.command.test; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.isNull; @@ -86,7 +86,7 @@ public class AddSecondaryStorageCmdTest extends TestCase { StorageService resourceService = Mockito.mock(StorageService.class); addImageStoreCmd._storageService = resourceService; - Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)anyObject())) + Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)any())) .thenReturn(null); try { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java index c5288067e94..34baebe5257 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java @@ -17,10 +17,10 @@ package org.apache.cloudstack.api.command.test; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import java.util.HashMap; import java.util.List; @@ -126,7 +126,7 @@ public class CreateSnapshotCmdTest extends TestCase { try { Mockito.when(volumeApiService.takeSnapshot(nullable(Long.class), nullable(Long.class), nullable(Long.class), - nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), anyObject(), Mockito.anyList())).thenReturn(null); + nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), any(), Mockito.anyList())).thenReturn(null); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java index 55a41c61ce6..76836caef28 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java index ee3193123e0..dc1f2ca5189 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java index 8639e135599..29b6144fd07 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java index 269a7b8a9e6..fb55e86dc0c 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java index 1ba7963b2b9..1dc05888608 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java index 0c31e501519..a063f6c2d6b 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java index 2fdef2acaa9..c9eb672c9e9 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java @@ -23,6 +23,7 @@ import com.cloud.utils.db.EntityManager; import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -41,9 +42,16 @@ public class CreateVMScheduleCmdTest { @InjectMocks private CreateVMScheduleCmd createVMScheduleCmd = new CreateVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java index 6adfc2b905c..9b4decc83aa 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.vm.schedule.VMSchedule; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -44,9 +45,16 @@ public class DeleteVMScheduleCmdTest { @InjectMocks private DeleteVMScheduleCmd deleteVMScheduleCmd = new DeleteVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java index 18657b4c397..f9a1d945f03 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java @@ -21,6 +21,7 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -38,10 +39,16 @@ public class ListVMScheduleCmdTest { public VMScheduleManager vmScheduleManager; @InjectMocks private ListVMScheduleCmd listVMScheduleCmd = new ListVMScheduleCmd(); + private AutoCloseable closeable; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java index 044685b579c..5ce133382f3 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java @@ -24,6 +24,7 @@ import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMSchedule; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,9 +43,16 @@ public class UpdateVMScheduleCmdTest { @InjectMocks private UpdateVMScheduleCmd updateVMScheduleCmd = new UpdateVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java b/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java index eb1336f90e9..d3537d6f831 100644 --- a/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java +++ b/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.Account; import com.cloud.user.User; diff --git a/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java b/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java index 50c82a76455..1ce3cfb06b9 100644 --- a/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java +++ b/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java @@ -27,7 +27,7 @@ import java.util.Vector; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.SecurityGroupRulesCmd.IpPortAndProto; diff --git a/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java b/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java index 2c7245662a2..24ca268913c 100644 --- a/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java +++ b/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java @@ -27,6 +27,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicStatusLine; +import org.junit.After; import org.junit.Before; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -58,9 +59,11 @@ public class BaseDirectTemplateDownloaderTest { @InjectMocks protected HttpsDirectTemplateDownloader httpsDownloader = new HttpsDirectTemplateDownloader(httpUrl, 1000, 1000, 1000); + private AutoCloseable closeable; + @Before public void init() throws IOException { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Mockito.when(httpsClient.execute(Mockito.any(HttpGet.class))).thenReturn(response); Mockito.when(httpsClient.execute(Mockito.any(HttpHead.class))).thenReturn(response); StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); @@ -69,4 +72,9 @@ public class BaseDirectTemplateDownloaderTest { ByteArrayInputStream inputStream = new ByteArrayInputStream(httpMetalinkContent.getBytes(StandardCharsets.UTF_8)); Mockito.when(httpEntity.getContent()).thenReturn(inputStream); } + + @After + public void tearDown() throws Exception { + closeable.close(); + } } diff --git a/core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java b/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java index 2ee2b46b4c9..fe9b7fafa81 100644 --- a/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java +++ b/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java @@ -22,7 +22,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.resource.ServerResource; 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 cf194462719..97bd1f5f1b0 100644 --- a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -742,7 +742,7 @@ public class VirtualMachineManagerImplTest { List volumesNotMapped = new ArrayList<>(); Mockito.doReturn(volumeToPoolObjectMap).when(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), - Mockito.anyMapOf(Long.class, Long.class)); + Mockito.anyMap()); Mockito.doReturn(volumesNotMapped).when(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap); Mockito.doNothing().when(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(Mockito.eq(virtualMachineProfileMock), @@ -753,7 +753,7 @@ public class VirtualMachineManagerImplTest { assertEquals(mappingVolumeAndStoragePool, volumeToPoolObjectMap); InOrder inOrder = Mockito.inOrder(virtualMachineManagerImpl); - inOrder.verify(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), Mockito.anyMapOf(Long.class, Long.class)); + inOrder.verify(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), Mockito.anyMap()); inOrder.verify(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap); inOrder.verify(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(Mockito.eq(virtualMachineProfileMock), any(DataCenterDeployment.class), Mockito.eq(volumeToPoolObjectMap), Mockito.eq(volumesNotMapped)); diff --git a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java index 9e64eff1816..d3d8cab2989 100644 --- a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java +++ b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java @@ -38,7 +38,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import com.cloud.api.query.dao.DomainRouterJoinDao; @@ -137,7 +137,7 @@ public class NetworkOrchestratorTest extends TestCase { when(provider.getCapabilities()).thenReturn(services); capabilities.put(Network.Capability.DhcpAccrossMultipleSubnets, "true"); - when(testOrchastrator._ntwkSrvcDao.getProviderForServiceInNetwork(Matchers.anyLong(), Matchers.eq(Service.Dhcp))).thenReturn(dhcpProvider); + when(testOrchastrator._ntwkSrvcDao.getProviderForServiceInNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.eq(Service.Dhcp))).thenReturn(dhcpProvider); when(testOrchastrator._networkModel.getElementImplementingProvider(dhcpProvider)).thenReturn(provider); when(guru.getName()).thenReturn(guruName); diff --git a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java index c9e6424a345..c566ad87f38 100644 --- a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java +++ b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.engine.provisioning.test; import java.util.HashMap; -import java.util.UUID; import junit.framework.TestCase; @@ -30,11 +29,10 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State; @@ -51,7 +49,6 @@ import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.EngineHostDao; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.EngineHostPodDao; import org.apache.cloudstack.engine.service.api.ProvisioningService; -import com.cloud.dc.DataCenter.NetworkType; import static org.mockito.ArgumentMatchers.any; 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 deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java b/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java index 6c894de7fb2..64941d99bb6 100644 --- a/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java @@ -17,6 +17,7 @@ package com.cloud.offerings.dao; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -37,9 +38,16 @@ public class NetworkOfferingDaoImplTest { final long offeringId = 1L; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java b/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java index 9277bf915c1..85fe0e09542 100755 --- a/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java @@ -21,7 +21,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; @@ -72,7 +72,7 @@ public class StoragePoolTagsDaoImplTest extends TestCase { public void setup() { when(_configDao.getValue(batchSizeConfigurationKey)).thenReturn(batchSizeValue); doReturn(storagePoolTagList).when(_storagePoolTagsDaoImpl).searchIncludingRemoved( - Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); } @Test @@ -91,7 +91,7 @@ public class StoragePoolTagsDaoImplTest extends TestCase { List storagePoolTags = new ArrayList(); _storagePoolTagsDaoImpl.searchForStoragePoolIdsInternal(0, storageTagsIds.length, storageTagsIds, storagePoolTags); - verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); assertEquals(2, storagePoolTags.size()); } @@ -99,30 +99,30 @@ public class StoragePoolTagsDaoImplTest extends TestCase { public void testSearchForStoragePoolIdsInternalStorageTagsNullSearch() { List storagePoolTags = new ArrayList(); doReturn(null).when(_storagePoolTagsDaoImpl).searchIncludingRemoved( - Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); _storagePoolTagsDaoImpl.searchForStoragePoolIdsInternal(0, storageTagsIds.length, storageTagsIds, storagePoolTags); - verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); assertEquals(0, storagePoolTags.size()); } @Test public void testSearchByIdsStorageTagsIdsGreaterOrEqualThanBatchSize() { when(_configDao.getValue(batchSizeConfigurationKey)).thenReturn(batchSizeLow); - doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.anyInt(), Matchers.any(Long[].class), Matchers.anyList()); + doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); _storagePoolTagsDaoImpl.searchByIds(storageTagsIds); int batchSize = Integer.parseInt(batchSizeLow); int difference = storageTagsIds.length - 2 * batchSize; - verify(_storagePoolTagsDaoImpl, Mockito.times(2)).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.eq(batchSize), Matchers.any(Long[].class), Matchers.anyList()); - verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.eq(2 * batchSize), Matchers.eq(difference), Matchers.any(Long[].class), Matchers.anyList()); + verify(_storagePoolTagsDaoImpl, Mockito.times(2)).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.eq(batchSize), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); + verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.eq(2 * batchSize), ArgumentMatchers.eq(difference), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); } @Test public void testSearchByIdsStorageTagsIdsLowerThanBatchSize() { - doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.anyInt(), Matchers.any(Long[].class), Matchers.anyList()); + doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); _storagePoolTagsDaoImpl.searchByIds(storageTagsIds); - verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.eq(0), Matchers.eq(storageTagsIds.length), Matchers.any(Long[].class), Matchers.anyList()); + verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.eq(0), ArgumentMatchers.eq(storageTagsIds.length), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); } } diff --git a/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java b/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java index c3ad42a9130..05d9154b6a4 100644 --- a/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java @@ -17,7 +17,7 @@ package com.cloud.usage.dao; -import static org.mockito.Matchers.contains; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java index 767b41420b7..00eae3b78d4 100644 --- a/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java @@ -20,6 +20,7 @@ package com.cloud.vm.dao; import com.cloud.utils.Pair; import com.cloud.vm.VirtualMachine; import org.joda.time.DateTime; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.Assert; @@ -45,15 +46,22 @@ public class VMInstanceDaoImplTest { @Mock VMInstanceVO vm; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Long hostId = null; when(vm.getHostId()).thenReturn(hostId); when(vm.getUpdated()).thenReturn(5L); when(vm.getUpdateTime()).thenReturn(DateTime.now().toDate()); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testUpdateState() throws Exception { Long destHostId = null; diff --git a/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java index 6ef248fdd62..eff881065c2 100644 --- a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java +++ b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java @@ -131,7 +131,7 @@ public class ConfigDriveBuilderTest { configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(Mockito.any(File.class))).then(invocationOnMock -> null); - configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVmMetadata(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.any(File.class), anyMap())).then(invocationOnMock -> null); + configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVmMetadata(Mockito.anyList(), Mockito.anyString(), Mockito.any(File.class), anyMap())).then(invocationOnMock -> null); configDriveBuilderMocked.when(() -> ConfigDriveBuilder.linkUserData((Mockito.anyString()))).then(invocationOnMock -> null); @@ -145,7 +145,7 @@ public class ConfigDriveBuilderTest { configDriveBuilderMocked.verify(() -> { ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(Mockito.any(File.class)); - ConfigDriveBuilder.writeVmMetadata(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.any(File.class), anyMap()); + ConfigDriveBuilder.writeVmMetadata(Mockito.anyList(), Mockito.anyString(), Mockito.any(File.class), anyMap()); ConfigDriveBuilder.linkUserData(Mockito.anyString()); ConfigDriveBuilder.generateAndRetrieveIsoAsBase64Iso(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); }); @@ -194,7 +194,7 @@ public class ConfigDriveBuilderTest { @Test public void writeVmMetadataTest() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.anyMap())).thenReturn(new JsonObject()); + Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyList(), Mockito.anyString(), Mockito.anyMap())).thenReturn(new JsonObject()); List vmData = new ArrayList<>(); vmData.add(new String[]{"dataType", "fileName", "content"}); @@ -347,7 +347,7 @@ public class ConfigDriveBuilderTest { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.nullable(Map.class))).thenCallRealMethod(); + Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyList(), Mockito.anyString(), Mockito.nullable(Map.class))).thenCallRealMethod(); List vmData = new ArrayList<>(); vmData.add(new String[]{"dataType", "fileName", "content"}); diff --git a/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java index 8f1ada87458..87a2288cfdc 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java @@ -51,7 +51,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java index ea1a221c8c0..cea9de3f1b4 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java @@ -47,7 +47,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.verification.VerificationMode; import com.cloud.agent.api.MigrateCommand; diff --git a/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java index b33f57c685c..0a8bba821f8 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java @@ -33,7 +33,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.storage.Snapshot; import com.cloud.storage.Storage.ImageFormat; diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java index d438fef5638..6aab8d32384 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java @@ -47,7 +47,7 @@ import org.apache.cloudstack.test.utils.SpringUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -192,22 +192,22 @@ public class VMSnapshotStrategyKVMTest extends TestCase{ UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); @@ -270,22 +270,22 @@ public class VMSnapshotStrategyKVMTest extends TestCase{ UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class); diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java index 5fd6dee9083..7bcfd4dda58 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java @@ -33,7 +33,7 @@ import org.apache.cloudstack.test.utils.SpringUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -115,18 +115,18 @@ public class VMSnapshotStrategyTest extends TestCase { UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); Exception e = null; @@ -139,8 +139,8 @@ public class VMSnapshotStrategyTest extends TestCase { assertNotNull(e); CreateVMSnapshotAnswer answer = Mockito.mock(CreateVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(true); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); VMSnapshot snapshot = null; snapshot = vmSnapshotStrategy.takeVMSnapshot(vmSnapshot); assertNotNull(snapshot); @@ -159,23 +159,23 @@ public class VMSnapshotStrategyTest extends TestCase { UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); Exception e = null; @@ -189,7 +189,7 @@ public class VMSnapshotStrategyTest extends TestCase { RevertToVMSnapshotAnswer answer = Mockito.mock(RevertToVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(Boolean.TRUE); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); boolean result = vmSnapshotStrategy.revertVMSnapshot(vmSnapshot); assertTrue(result); } @@ -207,23 +207,23 @@ public class VMSnapshotStrategyTest extends TestCase { UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); @@ -238,7 +238,7 @@ public class VMSnapshotStrategyTest extends TestCase { DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(true); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot); assertTrue(result); diff --git a/engine/storage/snapshot/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/snapshot/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/storage/snapshot/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java b/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java index 493ea089ef4..ae25017db31 100644 --- a/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java +++ b/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java b/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java index 91d8b611a0f..25266106f43 100644 --- a/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java +++ b/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java @@ -23,7 +23,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.utils.component.ComponentLifecycle; diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java index 54e30ebed95..476e378cf57 100644 --- a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.framework.config.impl; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -28,6 +28,7 @@ import junit.framework.TestCase; import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDao; import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -74,13 +75,15 @@ public class ConfigDepotAdminTest extends TestCase { @Mock ScopedConfigStorage _scopedStorage; + private AutoCloseable closeable; + /** * @throws java.lang.Exception */ @Override @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); _depotAdmin = new ConfigDepotImpl(); _depotAdmin._configDao = _configDao; _depotAdmin._configGroupDao = _configGroupDao; @@ -91,6 +94,12 @@ public class ConfigDepotAdminTest extends TestCase { _depotAdmin._scopedStorages.add(_scopedStorage); } + @Override + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testAutoPopulation() { ConfigurationVO dynamicIntCV = new ConfigurationVO("UnitTestComponent", DynamicIntCK); diff --git a/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java b/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java index a2153fee506..7ae7368e173 100644 --- a/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java +++ b/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java @@ -36,10 +36,10 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.db.DbUtil; import com.cloud.utils.db.TransactionLegacy; @@ -150,13 +150,13 @@ public class DbUtilTest { @Test public void getGlobalLock() throws SQLException { Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(1); Assert.assertTrue(DbUtil.getGlobalLock("TEST", 600)); - Mockito.verify(connection).prepareStatement(Matchers.anyString()); + Mockito.verify(connection).prepareStatement(ArgumentMatchers.anyString()); Mockito.verify(preparedStatement).close(); Mockito.verify(resultSet).close(); } @@ -164,13 +164,13 @@ public class DbUtilTest { @Test public void getGlobalLockTimeout() throws SQLException { Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(0); Assert.assertFalse(DbUtil.getGlobalLock("TEST", 600)); - Mockito.verify(connection).prepareStatement(Matchers.anyString()); + Mockito.verify(connection).prepareStatement(ArgumentMatchers.anyString()); Mockito.verify(preparedStatement).close(); Mockito.verify(resultSet).close(); Mockito.verify(connection).close(); @@ -237,7 +237,7 @@ public class DbUtilTest { @Test public void releaseGlobalLock() throws SQLException { - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(1); diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java index ae2f2e9926e..a0dd4c22814 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java @@ -40,7 +40,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -177,7 +177,7 @@ public class QuotaAlertManagerImplTest extends TestCase { quotaAlertManager.sendQuotaAlert(email); assertTrue(email.getSendDate() != null); - Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(), Mockito.anyListOf(String.class), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(), Mockito.anyList(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(quotaAlertManager.mailSender, Mockito.times(1)).sendMail(Mockito.any(SMTPMailProperties.class)); } diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java index 1b28f66b2bb..baf749cd0c9 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java @@ -38,7 +38,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.AccountVO; import com.cloud.user.dao.AccountDao; diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java index fc9b4af0ed2..c1e59f99863 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java @@ -22,7 +22,7 @@ import org.apache.cloudstack.api.response.UsageTypeResponse; import org.apache.cloudstack.usage.UsageTypes; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; import java.util.Map; diff --git a/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java b/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java index 66f3a37ae1b..3813c81b88f 100644 --- a/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java +++ b/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java @@ -25,6 +25,7 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.VMInstanceDao; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,8 +44,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -99,9 +100,11 @@ public class HostAffinityProcessorTest { @Mock VirtualMachineProfile profile; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); when(groupVM1.getHostId()).thenReturn(HOST_ID); when(groupVM2.getHostId()).thenReturn(HOST_ID); @@ -124,6 +127,11 @@ public class HostAffinityProcessorTest { when(affinityGroupVMMapDao.findByVmIdType(eq(VM_ID), any())).thenReturn(new ArrayList<>(Arrays.asList(mapVO))); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testProcessAffinityGroupMultipleVMs() { processor.processAffinityGroup(mapVO, plan, vm); diff --git a/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java b/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java index f879f056372..d4ded302332 100644 --- a/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java +++ b/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java @@ -34,7 +34,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.certificate.CrlVO; import com.cloud.certificate.dao.CrlDao; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java index 1fdb2956f30..adabc694f25 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import junit.framework.TestCase; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java index c66ac6b89c1..1a73fcd7506 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java index a357a181c38..de0220edfa0 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java index 0492ae84b8d..d6f9f747fa8 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java index e57109c4761..f5ce92ae014 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.math.BigDecimal; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java index 0cb1799ec10..22d78d6794e 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.math.BigDecimal; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java index 310e9ced72f..0b9d34daa70 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.naming.ConfigurationException; import java.lang.reflect.Field; diff --git a/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java b/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java index cd1d5018529..b1f4a1b130a 100644 --- a/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java +++ b/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java @@ -18,7 +18,7 @@ package org.apache.cloudstack.dedicated.manager; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; import java.io.IOException; diff --git a/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java index f1645611272..e174824cfdd 100644 --- a/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java +++ b/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.everyItem; import static org.hamcrest.Matchers.equalTo; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java index 3e18638361c..2c3a3126f6d 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java @@ -24,7 +24,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -51,7 +51,7 @@ public class DpdkDriverTest { public void initMocks() { closeable = MockitoAnnotations.openMocks(this); scriptMockedStatic = Mockito.mockStatic(Script.class); - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())).thenReturn(null); + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())).thenReturn(null); extraConfig = new HashMap<>(); } @@ -68,14 +68,14 @@ public class DpdkDriverTest { @Test public void testGetDpdkLatestPortNumberUsedExistingDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber)); Assert.assertEquals(dpdkPortNumber, driver.getDpdkLatestPortNumberUsed()); } @Test public void testGetNextDpdkPortNoDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(null); String expectedPortName = DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(1); Assert.assertEquals(expectedPortName, driver.getNextDpdkPort()); @@ -83,7 +83,7 @@ public class DpdkDriverTest { @Test public void testGetNextDpdkPortExistingDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber)); String expectedPortName = DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber + 1); Assert.assertEquals(expectedPortName, driver.getNextDpdkPort()); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java index c278144b4e1..4f1eba1a772 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java @@ -39,11 +39,11 @@ import org.libvirt.DomainInfo; import org.libvirt.LibvirtException; import org.libvirt.TypedParameter; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; @@ -297,7 +297,7 @@ public class LibvirtMigrateVolumeCommandWrapperTest { Mockito.doReturn(domxml).when(dm).getXMLDesc(0); - Mockito.doNothing().when(dm).blockCopy(Matchers.anyString(), Matchers.anyString(), Matchers.any(TypedParameter[].class), Matchers.anyInt()); + Mockito.doNothing().when(dm).blockCopy(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(TypedParameter[].class), ArgumentMatchers.anyInt()); MigrateVolumeAnswer answer = new MigrateVolumeAnswer(command, true, null, destPath); Mockito.doReturn(answer).when(libvirtMigrateVolumeCommandWrapper).checkBlockJobStatus(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); @@ -342,7 +342,7 @@ public class LibvirtMigrateVolumeCommandWrapperTest { Mockito.doReturn(null).when(destVolumeObjectTO).getPassphrase(); Mockito.doReturn(domxml).when(dm).getXMLDesc(0); - Mockito.doThrow(LibvirtException.class).when(dm).blockCopy(Matchers.anyString(), Matchers.anyString(), Matchers.any(TypedParameter[].class), Matchers.anyInt()); + Mockito.doThrow(LibvirtException.class).when(dm).blockCopy(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(TypedParameter[].class), ArgumentMatchers.anyInt()); Answer migrateVolumeAnswer = libvirtMigrateVolumeCommandWrapper.migratePowerFlexVolume(command, libvirtComputingResource); diff --git a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java index 5a7c156272f..a94fb01475a 100644 --- a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java +++ b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java @@ -29,7 +29,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; diff --git a/plugins/hypervisors/kvm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/kvm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/hypervisors/kvm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/hypervisors/vmware/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/vmware/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/hypervisors/vmware/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java index f5169ae5dde..b7e39ab8927 100644 --- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java +++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.Command; import com.cloud.agent.api.to.DataObjectType; diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java index 26c2e6da625..32584309979 100644 --- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java +++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java @@ -25,7 +25,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.VMTemplateVO; diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java index 95fb5aeb5c7..9790222f027 100644 --- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java +++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java @@ -24,7 +24,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.MigrateCommand; import com.cloud.agent.api.to.VirtualMachineTO; diff --git a/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/integrations/kubernetes-service/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/integrations/kubernetes-service/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/integrations/kubernetes-service/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java b/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java index ec4add4141d..b37be68b3e4 100644 --- a/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java +++ b/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java @@ -128,7 +128,7 @@ public class MetricsServiceImplTest { Mockito.verify(scMock).setParameters(stringCaptor1.capture(), objectArrayCaptor.capture()); Assert.assertEquals("idIN", stringCaptor1.getValue()); - Assert.assertEquals(Arrays.asList(fakeVmId1), objectArrayCaptor.getAllValues()); + Assert.assertEquals(fakeVmId1, objectArrayCaptor.getAllValues().get(0)[0]); Assert.assertEquals(expectedVmListAndCounter, result); } @@ -146,7 +146,7 @@ public class MetricsServiceImplTest { Mockito.verify(scMock).setParameters(stringCaptor1.capture(), objectArrayCaptor.capture()); Assert.assertEquals("idIN", stringCaptor1.getValue()); - Assert.assertEquals(expected, objectArrayCaptor.getAllValues()); + Assert.assertArrayEquals(expected.toArray(), objectArrayCaptor.getAllValues().get(0)); Assert.assertEquals(expectedVmListAndCounter, result); } @@ -163,7 +163,7 @@ public class MetricsServiceImplTest { Mockito.verify(scMock).setParameters(stringCaptor1.capture(), objectArrayCaptor.capture()); Assert.assertEquals("displayName", stringCaptor1.getValue()); - Assert.assertEquals("%fakeName%", objectArrayCaptor.getValue()); + Assert.assertEquals("%fakeName%", objectArrayCaptor.getValue()[0]); Assert.assertEquals(expectedVmListAndCounter, result); } @@ -184,8 +184,8 @@ public class MetricsServiceImplTest { List params = objectArrayCaptor.getAllValues(); Assert.assertEquals("displayName", conditions.get(0)); Assert.assertEquals("state", conditions.get(1)); - Assert.assertEquals("%fakeKeyword%", params.get(0)); - Assert.assertEquals("fakeKeyword", params.get(1)); + Assert.assertEquals("%fakeKeyword%", params.get(0)[0]); + Assert.assertEquals("fakeKeyword", params.get(1)[0]); Assert.assertEquals(expectedVmListAndCounter, result); } diff --git a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java index 31b7e38cda1..0a36058b6c1 100644 --- a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java +++ b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java @@ -21,7 +21,7 @@ package com.cloud.network.bigswitch; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java index 554eac9aa2a..a488888e5d0 100644 --- a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java +++ b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java @@ -21,6 +21,7 @@ package com.cloud.network.bigswitch; import static org.junit.Assert.assertEquals; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -73,16 +74,22 @@ public class BigSwitchBcfUtilsTest { NetworkModel networkModel; @Mock BigSwitchBcfUtils bsUtil; + private AutoCloseable closeable; @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); bsUtil = new BigSwitchBcfUtils(networkDao, nicDao, vmDao, hostDao, vpcDao, bigswitchBcfDao, agentMgr, vlanDao, ipAddressDao, fwRulesDao, fwCidrsDao, aclItemDao, aclItemCidrsDao, networkModel); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void getSubnetMaskLengthTest() { Integer rc = bsUtil.getSubnetMaskLength("255.255.255.254"); diff --git a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java index 005e2f6ee87..16b24441802 100644 --- a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java +++ b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java @@ -21,7 +21,7 @@ package com.cloud.network.resource; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/plugins/network-elements/brocade-vcs/src/test/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuruTest.java b/plugins/network-elements/brocade-vcs/src/test/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuruTest.java index b73ddabae19..9fbb96f046d 100644 --- a/plugins/network-elements/brocade-vcs/src/test/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuruTest.java +++ b/plugins/network-elements/brocade-vcs/src/test/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuruTest.java @@ -21,10 +21,10 @@ package com.cloud.network.guru; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java index 311dcf68c74..b013acd0f3e 100644 --- a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java +++ b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java @@ -18,8 +18,8 @@ package com.cloud.network.element; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java index a5be7b641c6..b331a2f7228 100644 --- a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java +++ b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java @@ -17,9 +17,9 @@ package com.cloud.network.resource; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/elastic-loadbalancer/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/network-elements/elastic-loadbalancer/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/network-elements/elastic-loadbalancer/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java index 23a3bd6c70f..77a737a35cf 100644 --- a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java +++ b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java @@ -16,8 +16,8 @@ */ package com.globo.globodns.cloudstack.element; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java index d89d7e7f463..74b270d61d3 100644 --- a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java +++ b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java @@ -18,7 +18,7 @@ package com.globo.globodns.cloudstack.resource; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.spy; diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java index 7bb4db1bb80..8643ea4ac74 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java @@ -26,7 +26,7 @@ import javax.inject.Inject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -86,7 +86,7 @@ public class InternalLbElementServiceTest { Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider); Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider); - Mockito.when(_vrProviderDao.persist(Matchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); + Mockito.when(_vrProviderDao.persist(ArgumentMatchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); } //TESTS FOR getInternalLoadBalancerElement METHOD diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java index 28a78960cdf..79482418ad0 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java @@ -31,7 +31,7 @@ import javax.inject.Inject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -116,10 +116,10 @@ public class InternalLbElementTest { Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider); Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider); - Mockito.when(_vrProviderDao.persist(Matchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); + Mockito.when(_vrProviderDao.persist(ArgumentMatchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null); - Mockito.when(_entityMgr.findById(Matchers.eq(DataCenter.class), Matchers.anyLong())).thenReturn(dc); + Mockito.when(_entityMgr.findById(ArgumentMatchers.eq(DataCenter.class), ArgumentMatchers.anyLong())).thenReturn(dc); } //TEST FOR getProvider() method diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java index 62fd2dd2845..1550649f847 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java @@ -31,7 +31,7 @@ import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -164,15 +164,15 @@ public class InternalLBVMManagerTest extends TestCase { } createNetwork(); - Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk); + Mockito.when(_ntwkModel.getNetwork(ArgumentMatchers.anyLong())).thenReturn(ntwk); - Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null); - Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm); + Mockito.when(_itMgr.toNicTO(ArgumentMatchers.any(NicProfile.class), ArgumentMatchers.any(HypervisorType.class))).thenReturn(null); + Mockito.when(_domainRouterDao.findById(ArgumentMatchers.anyLong())).thenReturn(vm); final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null); - Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc); + Mockito.when(_dcDao.findById(ArgumentMatchers.anyLong())).thenReturn(dc); final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO(); networkOfferingVO.setConcurrentConnections(500); - Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO); + Mockito.when(_offeringDao.findById(ArgumentMatchers.anyLong())).thenReturn(networkOfferingVO); Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm); Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null); diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java index 9141190df1f..afd75da50e1 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java @@ -30,7 +30,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -105,7 +105,7 @@ public class InternalLBVMServiceTest extends TestCase { Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1)); Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2)); - Mockito.when(_accountDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(new AccountVO(2)); + Mockito.when(_accountDao.findByIdIncludingRemoved(ArgumentMatchers.anyLong())).thenReturn(new AccountVO(2)); CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); final DomainRouterVO validVm = diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java index 61f83008389..19e617e9d13 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java @@ -24,7 +24,7 @@ import javax.inject.Inject; import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDaoImpl; import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDaoImpl; import org.eclipse.jetty.security.IdentityService; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -390,8 +390,8 @@ public class IntegrationTestConfiguration { } }); Mockito.when( - mock.createAffinityGroup(Matchers.any(String.class), Matchers.any(Long.class), Matchers.any(Long.class), Matchers.any(String.class), Matchers.any(String.class), - Matchers.any(String.class))).thenReturn(gmock); + mock.createAffinityGroup(ArgumentMatchers.any(String.class), ArgumentMatchers.any(Long.class), ArgumentMatchers.any(Long.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class), + ArgumentMatchers.any(String.class))).thenReturn(gmock); } catch (Exception e) { e.printStackTrace(); } @@ -482,7 +482,7 @@ public class IntegrationTestConfiguration { public DomainChecker domainChecker() { DomainChecker mock = Mockito.mock(DomainChecker.class); try { - Mockito.when(mock.checkAccess(Matchers.any(Account.class), Matchers.any(DataCenter.class))).thenReturn(true); + Mockito.when(mock.checkAccess(ArgumentMatchers.any(Account.class), ArgumentMatchers.any(DataCenter.class))).thenReturn(true); } catch (Exception e) { e.printStackTrace(); } @@ -498,23 +498,23 @@ public class IntegrationTestConfiguration { public EntityManager entityManager() { EntityManager mock = Mockito.mock(EntityManager.class); try { - Mockito.when(mock.findById(Matchers.same(Account.class), Matchers.anyLong())).thenReturn(_accountDao.findById(Account.ACCOUNT_ID_SYSTEM)); - Mockito.when(mock.findById(Matchers.same(User.class), Matchers.anyLong())).thenReturn(_userDao.findById(User.UID_SYSTEM)); - Mockito.when(mock.findById(Matchers.same(NetworkOffering.class), Matchers.any(Long.class))).thenAnswer(new Answer() { + Mockito.when(mock.findById(ArgumentMatchers.same(Account.class), ArgumentMatchers.anyLong())).thenReturn(_accountDao.findById(Account.ACCOUNT_ID_SYSTEM)); + Mockito.when(mock.findById(ArgumentMatchers.same(User.class), ArgumentMatchers.anyLong())).thenReturn(_userDao.findById(User.UID_SYSTEM)); + Mockito.when(mock.findById(ArgumentMatchers.same(NetworkOffering.class), ArgumentMatchers.any(Long.class))).thenAnswer(new Answer() { @Override public NetworkOffering answer(final InvocationOnMock invocation) throws Throwable { Long id = (Long)invocation.getArguments()[1]; return _networkOfferingDao.findById(id); } }); - Mockito.when(mock.findById(Matchers.same(IpAddress.class), Matchers.any(Long.class))).thenAnswer(new Answer() { + Mockito.when(mock.findById(ArgumentMatchers.same(IpAddress.class), ArgumentMatchers.any(Long.class))).thenAnswer(new Answer() { @Override public IpAddress answer(final InvocationOnMock invocation) throws Throwable { Long id = (Long)invocation.getArguments()[1]; return _ipAddressDao.findById(id); } }); - Mockito.when(mock.findById(Matchers.same(DataCenter.class), Matchers.any(Long.class))).thenAnswer(new Answer() { + Mockito.when(mock.findById(ArgumentMatchers.same(DataCenter.class), ArgumentMatchers.any(Long.class))).thenAnswer(new Answer() { @Override public DataCenter answer(final InvocationOnMock invocation) throws Throwable { Long id = (Long)invocation.getArguments()[1]; diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java index 99d46d57f67..740dfc95560 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java @@ -28,7 +28,7 @@ import java.util.UUID; import javax.inject.Inject; import org.apache.log4j.Logger; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -229,7 +229,7 @@ public class ManagementServerMock { } }; try { - Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback); + Mockito.when(_agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Commands.class))).thenAnswer(callback); } catch (AgentUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -278,7 +278,7 @@ public class ManagementServerMock { }; try { - Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback); + Mockito.when(_agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Commands.class))).thenAnswer(callback); } catch (AgentUnavailableException e) { e.printStackTrace(); } catch (OperationTimedoutException e) { diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java index 06ea2d986c0..9a4d0b6ebe1 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java @@ -17,9 +17,9 @@ package org.apache.cloudstack.network.contrail.model; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java index 71238a91e81..423ac616cd0 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java @@ -17,9 +17,9 @@ package org.apache.cloudstack.network.contrail.model; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java index dec4a409aea..757a7ab9339 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.network.contrail.model; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java index 7c698459f79..e037810cd8f 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java @@ -21,9 +21,9 @@ package com.cloud.network.element; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java index c99404a3ec3..5925fd98149 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java @@ -21,9 +21,9 @@ package com.cloud.network.guru; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java index 34518cedad5..ed3eccaaafc 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.hasSize; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/plugins/network-elements/nicira-nvp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/network-elements/nicira-nvp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/network-elements/nicira-nvp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/network-elements/tungsten/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/network-elements/tungsten/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/network-elements/tungsten/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java b/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java index 27c2ad53e8c..4d485e25a64 100644 --- a/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java +++ b/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java @@ -18,9 +18,9 @@ package com.cloud.network.guru; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java b/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java index 26115f7a8cf..01e4e2321b3 100644 --- a/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java +++ b/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java @@ -26,7 +26,7 @@ import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; import java.util.concurrent.ExecutorService; diff --git a/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java b/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java index 5629773b9ef..f0f045fa220 100644 --- a/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java +++ b/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java @@ -25,7 +25,7 @@ import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; diff --git a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java index ac88a0ded39..5b2faa8d2b5 100644 --- a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java +++ b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java @@ -37,6 +37,7 @@ import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao; import org.apache.cloudstack.storage.datastore.db.ObjectStoreDetailsDao; import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; import org.apache.cloudstack.storage.object.Bucket; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -87,9 +88,11 @@ public class MinIOObjectStoreDriverImplTest { Bucket bucket; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); minioObjectStoreDriverImpl._storeDao = objectStoreDao; minioObjectStoreDriverImpl._storeDetailsDao = objectStoreDetailsDao; minioObjectStoreDriverImpl._accountDao = accountDao; @@ -101,6 +104,11 @@ public class MinIOObjectStoreDriverImplTest { when(objectStoreDao.findById(any())).thenReturn(objectStoreVO); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testCreateBucket() throws Exception { doReturn(minioClient).when(minioObjectStoreDriverImpl).getMinIOClient(anyLong()); diff --git a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java index 8651e00b6ad..ba7ed270413 100644 --- a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java +++ b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.storage.datastore.provider; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.MockitoAnnotations; @@ -29,12 +30,19 @@ public class MinIOObjectStoreProviderImplTest { private MinIOObjectStoreProviderImpl minioObjectStoreProviderImpl; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); minioObjectStoreProviderImpl = new MinIOObjectStoreProviderImpl(); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testGetName() { String name = minioObjectStoreProviderImpl.getName(); diff --git a/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java b/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java index 57c7eee5cfb..b6e56925dc5 100644 --- a/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java +++ b/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.storage.datastore.provider; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.MockitoAnnotations; @@ -29,12 +30,19 @@ public class SimulatorObjectStoreProviderImplTest { private SimulatorObjectStoreProviderImpl simulatorObjectStoreProviderImpl; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); simulatorObjectStoreProviderImpl = new SimulatorObjectStoreProviderImpl(); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testGetName() { String name = simulatorObjectStoreProviderImpl.getName(); diff --git a/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java b/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java index dbd13d8f0de..8518d79417b 100644 --- a/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java +++ b/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java @@ -55,16 +55,16 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; /** diff --git a/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java b/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java index 749c04b8ebe..89b5ece576f 100644 --- a/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java +++ b/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java @@ -43,7 +43,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.exception.CloudRuntimeException; diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java index 1852ec1c0bd..de5e4d44c02 100644 --- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java @@ -49,6 +49,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -96,6 +97,8 @@ public class ScaleIOPrimaryDataStoreDriverTest { static MockedStatic remoteHostEndPointMock; + private AutoCloseable closeable; + @BeforeClass public static void init() { remoteHostEndPointMock = mockStatic(RemoteHostEndPoint.class); @@ -108,8 +111,14 @@ public class ScaleIOPrimaryDataStoreDriverTest { @Before public void initMocks() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); } + + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testSameScaleIOStorageInstance() { DataStore srcStore = Mockito.mock(DataStore.class); diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java index 4a6e73a327d..6a6a600098f 100644 --- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java @@ -26,7 +26,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.ArrayList; import java.util.List; @@ -46,6 +45,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,6 +53,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import com.cloud.host.Host; @@ -107,13 +108,19 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest { @InjectMocks private ScaleIOPrimaryDataStoreLifeCycle scaleIOPrimaryDataStoreLifeCycleTest; + private AutoCloseable closeable; @Before public void setUp() { - initMocks(this); + closeable = MockitoAnnotations.openMocks(this); ReflectionTestUtils.setField(scaleIOPrimaryDataStoreLifeCycleTest, "storageMgr", storageMgr); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testAttachZone() throws Exception { final DataStore dataStore = mock(DataStore.class); diff --git a/plugins/storage/volume/scaleio/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/storage/volume/scaleio/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/storage/volume/scaleio/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java b/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java index 71bc603a1b6..08f95b15d13 100644 --- a/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java @@ -27,7 +27,7 @@ import javax.inject.Inject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -108,7 +108,7 @@ public class VolumeTest { List results = new ArrayList(); results.add(host); Mockito.when(hostDao.listAll()).thenReturn(results); - Mockito.when(hostDao.findHypervisorHostInCluster(Matchers.anyLong())).thenReturn(results); + Mockito.when(hostDao.findHypervisorHostInCluster(ArgumentMatchers.anyLong())).thenReturn(results); // CreateObjectAnswer createVolumeFromImageAnswer = new // CreateObjectAnswer(null,UUID.randomUUID().toString(), null); diff --git a/plugins/storage/volume/storpool/pom.xml b/plugins/storage/volume/storpool/pom.xml index e5f1408f40a..e30ff922e0a 100644 --- a/plugins/storage/volume/storpool/pom.xml +++ b/plugins/storage/volume/storpool/pom.xml @@ -54,7 +54,7 @@ org.mockito mockito-inline - 4.7.0 + ${cs.mockito.version} pl.project13.maven diff --git a/plugins/user-authenticators/ldap/pom.xml b/plugins/user-authenticators/ldap/pom.xml index ed465d0e344..134dfb5efdb 100644 --- a/plugins/user-authenticators/ldap/pom.xml +++ b/plugins/user-authenticators/ldap/pom.xml @@ -162,7 +162,7 @@ net.bytebuddy byte-buddy - 1.10.5 + 1.14.5 junit diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java index 594c23fb786..3dc9d4054b9 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java @@ -37,9 +37,9 @@ import java.util.List; import java.util.UUID; import static junit.framework.TestCase.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java index 11d99f58858..bd55926e8e0 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java @@ -49,7 +49,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java index e355d77c343..62a3a809b16 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java @@ -30,12 +30,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java index 204e9853ffe..67d0e770522 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java @@ -29,12 +29,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java index bf9d7437446..58b14ec3684 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java @@ -26,7 +26,7 @@ import javax.naming.directory.SearchControls; import javax.naming.ldap.LdapContext; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java index a3b2311e2ce..0d1d840ce22 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java @@ -41,7 +41,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java index 58024b752ab..5defce948b2 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java @@ -21,7 +21,7 @@ import org.apache.cloudstack.ldap.dao.LdapConfigurationDaoImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java index 7e2c89e5556..85267dcbeca 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java @@ -24,7 +24,7 @@ import com.unboundid.ldap.sdk.SearchScope; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.zapodot.junit.ldap.EmbeddedLdapRule; import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java index 1bdfa9a91aa..a1923947e94 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java @@ -21,7 +21,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.btmatthews.ldapunit.DirectoryTester; import com.btmatthews.ldapunit.DirectoryServerConfiguration; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java index 206526b61a0..8d647039144 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; diff --git a/plugins/user-authenticators/ldap/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/user-authenticators/ldap/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/user-authenticators/ldap/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java b/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java index 78af8e532f0..ad86b16f39e 100644 --- a/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java +++ b/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.UserAccountVO; import com.cloud.user.dao.UserAccountDao; diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java index 06aa04d729c..c0d273a5fa5 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java @@ -24,6 +24,7 @@ import com.cloud.user.dao.UserAccountDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.Pair; import org.apache.cloudstack.auth.UserOAuth2Authenticator; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -55,9 +56,16 @@ public class OAuth2UserAuthenticatorTest { @InjectMocks private OAuth2UserAuthenticator authenticator; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java index be8670c1af9..cb99fde2410 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java @@ -24,13 +24,14 @@ import static org.mockito.Mockito.when; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.oauth2.OAuth2AuthManager; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class DeleteOAuthProviderCmdTest { @@ -41,9 +42,16 @@ public class DeleteOAuthProviderCmdTest { @InjectMocks private DeleteOAuthProviderCmd cmd; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test(expected = ServerApiException.class) diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java index 07df66f2026..ccbb53cfc80 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.oauth2.api.command; import com.cloud.api.ApiServer; import org.apache.cloudstack.api.ApiConstants; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -36,10 +37,18 @@ public class OauthLoginAPIAuthenticatorCmdTest { @InjectMocks private OauthLoginAPIAuthenticatorCmd cmd; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); } + + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testGetDomainNameWhenDomainNameIsNull() { StringBuilder auditTrailSb = new StringBuilder(); diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java index 987c7a5d01e..c61edd4610c 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java @@ -28,13 +28,14 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.oauth2.OAuth2AuthManager; import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class RegisterOAuthProviderCmdTest { @@ -45,9 +46,16 @@ public class RegisterOAuthProviderCmdTest { @InjectMocks private RegisterOAuthProviderCmd _cmd; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java index b8b1abcc4be..fa8a5a7c03c 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java @@ -23,6 +23,7 @@ import com.google.api.services.oauth2.Oauth2; import com.google.api.services.oauth2.model.Userinfo; import org.apache.cloudstack.oauth2.dao.OauthProviderDao; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -49,9 +50,16 @@ public class GoogleOAuth2ProviderTest { @InjectMocks private GoogleOAuth2Provider _googleOAuth2Provider; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test(expected = CloudAuthenticationException.class) diff --git a/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java b/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java index 3440f26c905..6498608ed98 100644 --- a/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java +++ b/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.security.NoSuchAlgorithmException; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java index 3df0fccadfa..2cddb126b1b 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java @@ -40,7 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.HttpUtils; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java index 94bf3f06696..81594db1009 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java @@ -30,7 +30,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.DomainManager; import com.cloud.user.User; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java index b4d230e3cd6..9342a0c7f09 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java @@ -44,7 +44,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java index 09391c5d7d2..2060d0baf31 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java @@ -37,7 +37,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.HttpUtils; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java index 073face6e2e..0a2955be04d 100755 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.doReturn; diff --git a/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java b/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java index 7a3af9d19d4..5f7d9105856 100644 --- a/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java +++ b/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.UserAccount; import com.cloud.user.dao.UserAccountDao; diff --git a/pom.xml b/pom.xml index 725d789f489..e6845f38717 100644 --- a/pom.xml +++ b/pom.xml @@ -114,7 +114,7 @@ 1.13.1 5.9.1 18.0 - 3.12.4 + 4.11.0 1.0-20081010.060147 1.0.1 7.1.0 @@ -717,7 +717,7 @@ org.mockito - mockito-core + mockito-inline ${cs.mockito.version} test diff --git a/server/src/test/java/com/cloud/alert/AlertControlsUnitTest.java b/server/src/test/java/com/cloud/alert/AlertControlsUnitTest.java index 5bbf2db61dc..20c437ea6d2 100644 --- a/server/src/test/java/com/cloud/alert/AlertControlsUnitTest.java +++ b/server/src/test/java/com/cloud/alert/AlertControlsUnitTest.java @@ -31,10 +31,10 @@ import org.mockito.Spy; import java.util.Date; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @@ -47,12 +47,13 @@ public class AlertControlsUnitTest extends TestCase { AccountManager _accountMgr; @Mock AlertDao _alertDao; + private AutoCloseable closeable; @Override @Before @SuppressWarnings("unchecked") - protected void setUp() { - MockitoAnnotations.initMocks(this); + public void setUp() { + closeable = MockitoAnnotations.openMocks(this); _mgmtServer._alertDao = _alertDao; _mgmtServer._accountMgr = _accountMgr; doReturn(3L).when(_accountMgr).checkAccessAndSpecifyAuthority(any(Account.class), anyLong()); @@ -63,6 +64,7 @@ public class AlertControlsUnitTest extends TestCase { @Override @After public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java b/server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java index cf2a43eceda..22c0ba5a795 100644 --- a/server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java +++ b/server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java @@ -37,7 +37,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.HashMap; diff --git a/server/src/test/java/com/cloud/api/query/MutualExclusiveIdsManagerBaseTest.java b/server/src/test/java/com/cloud/api/query/MutualExclusiveIdsManagerBaseTest.java index 8c4c71c3c77..6a3e87c54fc 100755 --- a/server/src/test/java/com/cloud/api/query/MutualExclusiveIdsManagerBaseTest.java +++ b/server/src/test/java/com/cloud/api/query/MutualExclusiveIdsManagerBaseTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; import java.util.List; diff --git a/server/src/test/java/com/cloud/api/query/dao/GenericDaoBaseWithTagInformationBaseTest.java b/server/src/test/java/com/cloud/api/query/dao/GenericDaoBaseWithTagInformationBaseTest.java index a227ae3fb34..3af907375d6 100755 --- a/server/src/test/java/com/cloud/api/query/dao/GenericDaoBaseWithTagInformationBaseTest.java +++ b/server/src/test/java/com/cloud/api/query/dao/GenericDaoBaseWithTagInformationBaseTest.java @@ -54,8 +54,10 @@ public abstract class GenericDaoBaseWithTagInformationBaseTest securityGroupVmMap_empty = new ArrayList(); @@ -111,6 +114,12 @@ public class SecurityGroupJoinDaoImplTest extends TestCase { when(userVmVOtwo.getUuid()).thenReturn(uuidTwo); } + @Override + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void virtualMachineCountEmptyTest() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { diff --git a/server/src/test/java/com/cloud/api/query/dao/UserVmJoinDaoImplTest.java b/server/src/test/java/com/cloud/api/query/dao/UserVmJoinDaoImplTest.java index 320c556fc51..fa95aefbd87 100755 --- a/server/src/test/java/com/cloud/api/query/dao/UserVmJoinDaoImplTest.java +++ b/server/src/test/java/com/cloud/api/query/dao/UserVmJoinDaoImplTest.java @@ -48,6 +48,7 @@ import java.util.Arrays; import java.util.EnumSet; import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.MockitoAnnotations.openMocks; @RunWith(MockitoJUnitRunner.class) public class UserVmJoinDaoImplTest extends GenericDaoBaseWithTagInformationBaseTest { @@ -88,15 +89,18 @@ public class UserVmJoinDaoImplTest extends GenericDaoBaseWithTagInformationBaseT private Long vmId = 100L; private Long templateId = 101L; + private AutoCloseable closeable; @Before public void setup() { + closeable = openMocks(this); prepareSetup(); } @Override @After - public void tearDown() { + public void tearDown() throws Exception { + closeable.close(); super.tearDown(); } diff --git a/server/src/test/java/com/cloud/capacity/CapacityManagerTest.java b/server/src/test/java/com/cloud/capacity/CapacityManagerTest.java index 54e1243f074..2c7a2a7fb52 100644 --- a/server/src/test/java/com/cloud/capacity/CapacityManagerTest.java +++ b/server/src/test/java/com/cloud/capacity/CapacityManagerTest.java @@ -26,9 +26,9 @@ import com.cloud.vm.VirtualMachine; import org.junit.Assert; import org.junit.Test; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java b/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java index c2d748ee587..d421c322393 100644 --- a/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java +++ b/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java @@ -220,9 +220,11 @@ public class ConfigurationManagerTest { @Mock Account account; + private AutoCloseable closeable; + @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Account account = new AccountVO("testaccount", 1, "networkdomain", Account.Type.NORMAL, UUID.randomUUID().toString()); when(configurationMgr._accountMgr.getAccount(anyLong())).thenReturn(account); @@ -262,8 +264,9 @@ public class ConfigurationManagerTest { } @After - public void tearDown() { + public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test diff --git a/server/src/test/java/com/cloud/configuration/ValidateIpRangeTest.java b/server/src/test/java/com/cloud/configuration/ValidateIpRangeTest.java index d090066f14f..a8a0ce0400c 100644 --- a/server/src/test/java/com/cloud/configuration/ValidateIpRangeTest.java +++ b/server/src/test/java/com/cloud/configuration/ValidateIpRangeTest.java @@ -20,6 +20,7 @@ import com.cloud.dc.VlanVO; import com.cloud.network.Network; import com.cloud.network.NetworkModel; import com.cloud.utils.Pair; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -40,10 +41,11 @@ public class ValidateIpRangeTest { Network network; ConfigurationManagerImpl configurationMgr = new ConfigurationManagerImpl(); List vlanVOList = new ArrayList(); + private AutoCloseable closeable; @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); configurationMgr._networkModel = _networkModel; vlanVOList.add(vlan); when(vlan.getVlanGateway()).thenReturn("10.147.33.1"); @@ -51,6 +53,11 @@ public class ValidateIpRangeTest { } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void SameSubnetTest() { Pair> sameSubnet = diff --git a/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerTest.java b/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerTest.java index 428b53a1ba3..ed23d1ecb70 100644 --- a/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerTest.java +++ b/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerTest.java @@ -32,6 +32,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import org.apache.log4j.Logger; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -46,9 +47,9 @@ import java.util.Collections; import java.util.List; import static org.mockito.AdditionalMatchers.not; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -66,19 +67,25 @@ public class ConsoleProxyManagerTest { NetworkDao networkDaoMock; @Mock ConsoleProxyManagerImpl consoleProxyManagerImplMock; + private AutoCloseable closeable; @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); ReflectionTestUtils.setField(consoleProxyManagerImplMock, "allocProxyLock", globalLockMock); ReflectionTestUtils.setField(consoleProxyManagerImplMock, "dataCenterDao", dataCenterDaoMock); ReflectionTestUtils.setField(consoleProxyManagerImplMock, "networkDao", networkDaoMock); - Mockito.doCallRealMethod().when(consoleProxyManagerImplMock).expandPool(Mockito.anyLong(), Mockito.anyObject()); + Mockito.doCallRealMethod().when(consoleProxyManagerImplMock).expandPool(Mockito.anyLong(), Mockito.any()); Mockito.doCallRealMethod().when(consoleProxyManagerImplMock).getDefaultNetworkForCreation(Mockito.any(DataCenter.class)); Mockito.doCallRealMethod().when(consoleProxyManagerImplMock).getDefaultNetworkForAdvancedZone(Mockito.any(DataCenter.class)); Mockito.doCallRealMethod().when(consoleProxyManagerImplMock).getDefaultNetworkForBasicZone(Mockito.any(DataCenter.class)); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testNewCPVMCreation() throws Exception { s_logger.info("Running test for new CPVM creation"); diff --git a/server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java b/server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java index 6bfc8fb629d..ea04a09cf92 100644 --- a/server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java +++ b/server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java @@ -97,6 +97,7 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.test.utils.SpringUtils; import org.apache.commons.collections.CollectionUtils; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -104,7 +105,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -231,6 +231,7 @@ public class DeploymentPlanningManagerImplTest { private static final long podId = 2L; private static final long clusterId = 3L; private static final long ADMIN_ACCOUNT_ROLE_ID = 1L; + private AutoCloseable closeable; @BeforeClass public static void setUp() throws ConfigurationException { @@ -238,14 +239,14 @@ public class DeploymentPlanningManagerImplTest { @Before public void testSetUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); ComponentContext.initComponentsLifeCycle(); PlannerHostReservationVO reservationVO = new PlannerHostReservationVO(hostId, dataCenterId, podId, clusterId, PlannerResourceUsage.Shared); - Mockito.when(_plannerHostReserveDao.persist(Matchers.any(PlannerHostReservationVO.class))).thenReturn(reservationVO); - Mockito.when(_plannerHostReserveDao.findById(Matchers.anyLong())).thenReturn(reservationVO); - Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(Matchers.anyLong())).thenReturn(0L); + Mockito.when(_plannerHostReserveDao.persist(ArgumentMatchers.any(PlannerHostReservationVO.class))).thenReturn(reservationVO); + Mockito.when(_plannerHostReserveDao.findById(ArgumentMatchers.anyLong())).thenReturn(reservationVO); + Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(ArgumentMatchers.anyLong())).thenReturn(0L); VMTemplateVO template = Mockito.mock(VMTemplateVO.class); Mockito.when(template.isDeployAsIs()).thenReturn(false); @@ -255,16 +256,16 @@ public class DeploymentPlanningManagerImplTest { Mockito.when(vmProfile.getVirtualMachine()).thenReturn(vm); Mockito.when(vmProfile.getId()).thenReturn(instanceId); - Mockito.when(vmDetailsDao.listDetailsKeyPairs(Matchers.anyLong())).thenReturn(null); + Mockito.when(vmDetailsDao.listDetailsKeyPairs(ArgumentMatchers.anyLong())).thenReturn(null); - Mockito.when(volDao.findByInstance(Matchers.anyLong())).thenReturn(new ArrayList<>()); + Mockito.when(volDao.findByInstance(ArgumentMatchers.anyLong())).thenReturn(new ArrayList<>()); - Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc); + Mockito.when(_dcDao.findById(ArgumentMatchers.anyLong())).thenReturn(dc); Mockito.when(dc.getId()).thenReturn(dataCenterId); ClusterVO clusterVO = new ClusterVO(); clusterVO.setHypervisorType(HypervisorType.XenServer.toString()); - Mockito.when(_clusterDao.findById(Matchers.anyLong())).thenReturn(clusterVO); + Mockito.when(_clusterDao.findById(ArgumentMatchers.anyLong())).thenReturn(clusterVO); Mockito.when(_planner.getName()).thenReturn("FirstFitPlanner"); List planners = new ArrayList(); @@ -277,6 +278,11 @@ public class DeploymentPlanningManagerImplTest { Mockito.doNothing().when(_dpm).avoidDisabledResources(vmProfile, dc, avoids); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void dataCenterAvoidTest() throws InsufficientServerCapacityException, AffinityConflictException { ServiceOfferingVO svcOffering = @@ -286,7 +292,7 @@ public class DeploymentPlanningManagerImplTest { DataCenterDeployment plan = new DataCenterDeployment(dataCenterId); - Mockito.when(avoids.shouldAvoid((DataCenterVO) Matchers.anyObject())).thenReturn(true); + Mockito.when(avoids.shouldAvoid((DataCenterVO) ArgumentMatchers.any())).thenReturn(true); DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids, null); assertNull("DataCenter is in avoid set, destination should be null! ", dest); } @@ -299,7 +305,7 @@ public class DeploymentPlanningManagerImplTest { Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering); DataCenterDeployment plan = new DataCenterDeployment(dataCenterId); - Mockito.when(avoids.shouldAvoid((DataCenterVO) Matchers.anyObject())).thenReturn(false); + Mockito.when(avoids.shouldAvoid((DataCenterVO) ArgumentMatchers.any())).thenReturn(false); Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(false); DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids, null); @@ -314,7 +320,7 @@ public class DeploymentPlanningManagerImplTest { Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering); DataCenterDeployment plan = new DataCenterDeployment(dataCenterId); - Mockito.when(avoids.shouldAvoid((DataCenterVO) Matchers.anyObject())).thenReturn(false); + Mockito.when(avoids.shouldAvoid((DataCenterVO) ArgumentMatchers.any())).thenReturn(false); Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(true); Mockito.when(((DeploymentClusterPlanner) _planner).orderClusters(vmProfile, plan, avoids)).thenReturn(null); diff --git a/server/src/test/java/com/cloud/event/EventControlsUnitTest.java b/server/src/test/java/com/cloud/event/EventControlsUnitTest.java index 2871de60cd3..5e29f219c50 100644 --- a/server/src/test/java/com/cloud/event/EventControlsUnitTest.java +++ b/server/src/test/java/com/cloud/event/EventControlsUnitTest.java @@ -34,9 +34,9 @@ import org.mockito.Spy; import java.util.Date; import java.util.List; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @@ -50,11 +50,12 @@ public class EventControlsUnitTest extends TestCase { @Mock EventDao _eventDao; List _events = null; + private AutoCloseable closeable; @Override @Before - protected void setUp() { - MockitoAnnotations.initMocks(this); + public void setUp() { + closeable = MockitoAnnotations.openMocks(this); _mgmtServer._eventDao = _eventDao; _mgmtServer._accountMgr = _accountMgr; doNothing().when(_accountMgr).checkAccess(any(Account.class), any(AccessType.class), any(Boolean.class), any(ControlledEntity.class)); @@ -64,6 +65,7 @@ public class EventControlsUnitTest extends TestCase { @Override @After public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/server/src/test/java/com/cloud/ha/HighAvailabilityManagerImplTest.java b/server/src/test/java/com/cloud/ha/HighAvailabilityManagerImplTest.java index 629fae2ac2e..06a078ae88c 100644 --- a/server/src/test/java/com/cloud/ha/HighAvailabilityManagerImplTest.java +++ b/server/src/test/java/com/cloud/ha/HighAvailabilityManagerImplTest.java @@ -41,7 +41,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.AgentManager; import com.cloud.alert.AlertManager; @@ -207,7 +207,7 @@ public class HighAvailabilityManagerImplTest { Mockito.when(_podDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(HostPodVO.class)); Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(DataCenterVO.class)); Mockito.when(_haDao.findPreviousHA(Mockito.anyLong())).thenReturn(Arrays.asList(Mockito.mock(HaWorkVO.class))); - Mockito.when(_haDao.persist((HaWorkVO)Mockito.anyObject())).thenReturn(Mockito.mock(HaWorkVO.class)); + Mockito.when(_haDao.persist((HaWorkVO)Mockito.any())).thenReturn(Mockito.mock(HaWorkVO.class)); Mockito.when(_serviceOfferingDao.findById(vm1.getServiceOfferingId())).thenReturn(Mockito.mock(ServiceOfferingVO.class)); highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true); diff --git a/server/src/test/java/com/cloud/ha/KVMFencerTest.java b/server/src/test/java/com/cloud/ha/KVMFencerTest.java index 617d0bc8973..c4b5666c020 100644 --- a/server/src/test/java/com/cloud/ha/KVMFencerTest.java +++ b/server/src/test/java/com/cloud/ha/KVMFencerTest.java @@ -34,10 +34,10 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; import java.util.Collections; @@ -118,7 +118,7 @@ public class KVMFencerTest { Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost)); FenceAnswer answer = new FenceAnswer(null, true, "ok"); - Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenReturn(answer); + Mockito.when(agentManager.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(FenceCommand.class))).thenReturn(answer); Assert.assertTrue(fencer.fenceOff(virtualMachine, host)); } @@ -145,7 +145,7 @@ public class KVMFencerTest { Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost)); - Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenThrow(new AgentUnavailableException(2l)); + Mockito.when(agentManager.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(FenceCommand.class))).thenThrow(new AgentUnavailableException(2l)); Assert.assertFalse(fencer.fenceOff(virtualMachine, host)); } @@ -172,7 +172,7 @@ public class KVMFencerTest { Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost)); - Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenThrow(new OperationTimedoutException(null, 2l, 0l, 0, false)); + Mockito.when(agentManager.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(FenceCommand.class))).thenThrow(new OperationTimedoutException(null, 2l, 0l, 0, false)); Assert.assertFalse(fencer.fenceOff(virtualMachine, host)); } diff --git a/server/src/test/java/com/cloud/hypervisor/KVMGuruTest.java b/server/src/test/java/com/cloud/hypervisor/KVMGuruTest.java index 7c5ef9257cd..eea8bb9de68 100644 --- a/server/src/test/java/com/cloud/hypervisor/KVMGuruTest.java +++ b/server/src/test/java/com/cloud/hypervisor/KVMGuruTest.java @@ -46,7 +46,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.UnsupportedEncodingException; import java.util.Arrays; diff --git a/server/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkHelperImplTest.java b/server/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkHelperImplTest.java index 2f1d6270c9c..64c5c04f3bb 100644 --- a/server/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkHelperImplTest.java +++ b/server/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkHelperImplTest.java @@ -36,7 +36,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/server/src/test/java/com/cloud/metadata/ResourceMetaDataManagerTest.java b/server/src/test/java/com/cloud/metadata/ResourceMetaDataManagerTest.java index 64b0de28d95..3e82d2b4cd5 100644 --- a/server/src/test/java/com/cloud/metadata/ResourceMetaDataManagerTest.java +++ b/server/src/test/java/com/cloud/metadata/ResourceMetaDataManagerTest.java @@ -24,6 +24,7 @@ import com.cloud.server.TaggedResourceService; import com.cloud.storage.dao.VolumeDetailsDao; import com.cloud.vm.dao.NicDetailsDao; import org.apache.commons.collections.map.HashedMap; +import org.junit.After; import org.junit.Before; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -32,9 +33,9 @@ import org.mockito.Spy; import javax.naming.ConfigurationException; import java.util.Map; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -50,10 +51,11 @@ public class ResourceMetaDataManagerTest { TaggedResourceService _taggedResourceMgr; @Mock ResourceManagerUtil resourceManagerUtil; + private AutoCloseable closeable; @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); try { _resourceMetaDataMgr.configure(null, null); @@ -66,6 +68,11 @@ public class ResourceMetaDataManagerTest { } + @After + public void tearDown() throws Exception { + closeable.close(); + } + // Test removing details //@Test public void testResourceDetails() throws ResourceAllocationException { diff --git a/server/src/test/java/com/cloud/network/CreatePrivateNetworkTest.java b/server/src/test/java/com/cloud/network/CreatePrivateNetworkTest.java index 826653fada7..6564f48ff26 100644 --- a/server/src/test/java/com/cloud/network/CreatePrivateNetworkTest.java +++ b/server/src/test/java/com/cloud/network/CreatePrivateNetworkTest.java @@ -49,6 +49,7 @@ import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.log4j.Logger; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -60,10 +61,10 @@ import java.util.UUID; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; //@Ignore("Requires database to be set up") @@ -87,10 +88,11 @@ public class CreatePrivateNetworkTest { NetworkOrchestrationService _networkMgr; @Mock PrivateIpDao _privateIpDao; + private AutoCloseable closeable; @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); networkService._accountMgr = _accountMgr; networkService._networkOfferingDao = _networkOfferingDao; @@ -136,6 +138,11 @@ public class CreatePrivateNetworkTest { when(networkService._privateIpDao.findByIpAndSourceNetworkIdAndVpcId(eq(1L), anyString(), eq(1L))).thenReturn(null); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test @DB public void createInvalidlyHostedPrivateNetwork() { diff --git a/server/src/test/java/com/cloud/network/DedicateGuestVlanRangesTest.java b/server/src/test/java/com/cloud/network/DedicateGuestVlanRangesTest.java index 3f9bda90a4e..5f39bfbeead 100644 --- a/server/src/test/java/com/cloud/network/DedicateGuestVlanRangesTest.java +++ b/server/src/test/java/com/cloud/network/DedicateGuestVlanRangesTest.java @@ -48,10 +48,10 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @@ -82,10 +82,11 @@ public class DedicateGuestVlanRangesTest { DataCenterVnetDao _dataCenterVnetDao; @Mock AccountGuestVlanMapDao _accountGuestVlanMapDao; + private AutoCloseable closeable; @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); networkService._accountMgr = _accountMgr; networkService._accountDao = _accountDao; @@ -124,8 +125,9 @@ public class DedicateGuestVlanRangesTest { } @After - public void tearDown() { + public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test diff --git a/server/src/test/java/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java b/server/src/test/java/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java index 91f6fc35277..dd9344e5602 100644 --- a/server/src/test/java/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java +++ b/server/src/test/java/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java @@ -66,7 +66,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.inject.Inject; import java.lang.reflect.Field; diff --git a/server/src/test/java/com/cloud/network/IpAddressManagerTest.java b/server/src/test/java/com/cloud/network/IpAddressManagerTest.java index 5b8399ad000..824d4ee4701 100644 --- a/server/src/test/java/com/cloud/network/IpAddressManagerTest.java +++ b/server/src/test/java/com/cloud/network/IpAddressManagerTest.java @@ -19,7 +19,7 @@ package com.cloud.network; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -46,7 +46,7 @@ import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network.Service; diff --git a/server/src/test/java/com/cloud/network/Ipv6AddressManagerTest.java b/server/src/test/java/com/cloud/network/Ipv6AddressManagerTest.java index 476a73ec313..0b8e7f43137 100644 --- a/server/src/test/java/com/cloud/network/Ipv6AddressManagerTest.java +++ b/server/src/test/java/com/cloud/network/Ipv6AddressManagerTest.java @@ -31,6 +31,7 @@ import com.cloud.utils.net.NetUtils; import com.cloud.vm.NicProfile; import com.cloud.vm.dao.NicSecondaryIpDaoImpl; import com.cloud.vm.dao.NicSecondaryIpVO; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -62,9 +63,16 @@ public class Ipv6AddressManagerTest { private Network network = mockNetwork(); + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/server/src/test/java/com/cloud/network/Ipv6ServiceImplTest.java b/server/src/test/java/com/cloud/network/Ipv6ServiceImplTest.java index e0c1da8cae4..02ddd0c983e 100644 --- a/server/src/test/java/com/cloud/network/Ipv6ServiceImplTest.java +++ b/server/src/test/java/com/cloud/network/Ipv6ServiceImplTest.java @@ -149,11 +149,13 @@ public class Ipv6ServiceImplTest { private MockedStatic usageEventUtilsMocked; + private AutoCloseable closeable; + @Before public void setup() { updatedPrefixSubnetMap = new ArrayList<>(); persistedPrefixSubnetMap = new ArrayList<>(); - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); ipv6Service.firewallManager = firewallManager; Mockito.when(ipv6GuestPrefixSubnetNetworkMapDao.update(Mockito.anyLong(), Mockito.any(Ipv6GuestPrefixSubnetNetworkMapVO.class))).thenAnswer((Answer) invocation -> { Ipv6GuestPrefixSubnetNetworkMapVO map = (Ipv6GuestPrefixSubnetNetworkMapVO)invocation.getArguments()[1]; @@ -176,6 +178,7 @@ public class Ipv6ServiceImplTest { apiDBUtilsMocked.close(); actionEventUtilsMocked.close(); usageEventUtilsMocked.close(); + closeable.close(); } private DataCenterGuestIpv6PrefixVO prepareMocksForIpv6Subnet() { diff --git a/server/src/test/java/com/cloud/network/NetworkModelTest.java b/server/src/test/java/com/cloud/network/NetworkModelTest.java index 13f38dea638..a1494a11d57 100644 --- a/server/src/test/java/com/cloud/network/NetworkModelTest.java +++ b/server/src/test/java/com/cloud/network/NetworkModelTest.java @@ -51,6 +51,7 @@ import com.cloud.utils.net.Ip; import junit.framework.Assert; import org.apache.cloudstack.network.NetworkPermissionVO; import org.apache.cloudstack.network.dao.NetworkPermissionDao; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -64,10 +65,10 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -125,10 +126,11 @@ public class NetworkModelTest { private static final String IPV6_GATEWAY = "fd59:16ba:559b:243d::1"; private static final String START_IPV6 = "fd59:16ba:559b:243d:0:0:0:2"; private static final String END_IPV6 = "fd59:16ba:559b:243d:ffff:ffff:ffff:ffff"; + private AutoCloseable closeable; @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); when(dataCenterDao.listEnabledZones()).thenReturn(Arrays.asList(zone1, zone2)); when(physicalNetworkDao.listByZoneAndTrafficType(ZONE_1_ID, Networks.TrafficType.Guest)). @@ -150,6 +152,11 @@ public class NetworkModelTest { when(physicalNetworkZone2.getId()).thenReturn(PHYSICAL_NETWORK_2_ID); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testGetSourceNatIpAddressForGuestNetwork() { NetworkModelImpl modelImpl = new NetworkModelImpl(); diff --git a/server/src/test/java/com/cloud/network/UpdatePhysicalNetworkTest.java b/server/src/test/java/com/cloud/network/UpdatePhysicalNetworkTest.java index eb654c0b719..ae70d137b0d 100644 --- a/server/src/test/java/com/cloud/network/UpdatePhysicalNetworkTest.java +++ b/server/src/test/java/com/cloud/network/UpdatePhysicalNetworkTest.java @@ -29,8 +29,8 @@ import java.util.ArrayList; import java.util.List; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/server/src/test/java/com/cloud/network/element/ConfigDriveNetworkElementTest.java b/server/src/test/java/com/cloud/network/element/ConfigDriveNetworkElementTest.java index 52ac5f45964..d83120d75f3 100644 --- a/server/src/test/java/com/cloud/network/element/ConfigDriveNetworkElementTest.java +++ b/server/src/test/java/com/cloud/network/element/ConfigDriveNetworkElementTest.java @@ -264,7 +264,7 @@ public class ConfigDriveNetworkElementTest { try (MockedStatic ignored1 = Mockito.mockStatic(ConfigDriveBuilder.class); MockedStatic ignored2 = Mockito.mockStatic(CallContext.class)) { Mockito.when(CallContext.current()).thenReturn(callContextMock); Mockito.doReturn(Mockito.mock(Account.class)).when(callContextMock).getCallingAccount(); - Mockito.when(ConfigDriveBuilder.buildConfigDrive(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.anyString(), Mockito.anyMap())).thenReturn("content"); + Mockito.when(ConfigDriveBuilder.buildConfigDrive(Mockito.anyList(), Mockito.anyString(), Mockito.anyString(), Mockito.anyMap())).thenReturn("content"); final HandleConfigDriveIsoAnswer answer = mock(HandleConfigDriveIsoAnswer.class); final UserVmDetailVO userVmDetailVO = mock(UserVmDetailVO.class); diff --git a/server/src/test/java/com/cloud/network/element/VirtualRouterElementTest.java b/server/src/test/java/com/cloud/network/element/VirtualRouterElementTest.java index 46b8eb95de7..b0d9cdc9dc4 100644 --- a/server/src/test/java/com/cloud/network/element/VirtualRouterElementTest.java +++ b/server/src/test/java/com/cloud/network/element/VirtualRouterElementTest.java @@ -103,11 +103,11 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import java.util.ArrayList; @@ -116,10 +116,10 @@ import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; @@ -342,7 +342,7 @@ public class VirtualRouterElementTest { VirtualMachine.Type.DomainRouter, /* defaultUse */ false); lenient().when(_serviceOfferingDao.findById(0L)).thenReturn(svcoff); - lenient().when(_serviceOfferingDao.findByName(Matchers.anyString())).thenReturn(svcoff); + lenient().when(_serviceOfferingDao.findByName(ArgumentMatchers.anyString())).thenReturn(svcoff); final DomainRouterVO router = new DomainRouterVO(/* id */ 1L, /* serviceOfferingId */ 1L, /* elementId */ 0L, diff --git a/server/src/test/java/com/cloud/network/element/VpcVirtualRouterElementTest.java b/server/src/test/java/com/cloud/network/element/VpcVirtualRouterElementTest.java index 3511262f9ac..8a5b965514c 100644 --- a/server/src/test/java/com/cloud/network/element/VpcVirtualRouterElementTest.java +++ b/server/src/test/java/com/cloud/network/element/VpcVirtualRouterElementTest.java @@ -34,7 +34,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.List; diff --git a/server/src/test/java/com/cloud/network/firewall/FirewallManagerTest.java b/server/src/test/java/com/cloud/network/firewall/FirewallManagerTest.java index 2200d6b125b..f8c37cd6bf7 100644 --- a/server/src/test/java/com/cloud/network/firewall/FirewallManagerTest.java +++ b/server/src/test/java/com/cloud/network/firewall/FirewallManagerTest.java @@ -38,6 +38,7 @@ import com.cloud.utils.component.ComponentContext; import junit.framework.Assert; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.log4j.Logger; +import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -45,14 +46,14 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -61,6 +62,7 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class FirewallManagerTest { private static final Logger s_logger = Logger.getLogger(FirewallManagerTest.class); + private AutoCloseable closeable; @Ignore("Requires database to be set up") @@ -113,7 +115,12 @@ public class FirewallManagerTest { @Before public void initMocks() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Ignore("Requires database to be set up") diff --git a/server/src/test/java/com/cloud/network/guru/DirectNetworkGuruTest.java b/server/src/test/java/com/cloud/network/guru/DirectNetworkGuruTest.java index a623be886e1..9818b43e650 100644 --- a/server/src/test/java/com/cloud/network/guru/DirectNetworkGuruTest.java +++ b/server/src/test/java/com/cloud/network/guru/DirectNetworkGuruTest.java @@ -33,6 +33,7 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.vm.NicProfile; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -84,9 +85,11 @@ public class DirectNetworkGuruTest { final String[] ip4Dns = {"5.5.5.5", "6.6.6.6"}; final String[] ip6Dns = {"2001:4860:4860::5555", "2001:4860:4860::6666"}; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); guru._ntwkOfferingSrvcDao = ntwkOfferingSrvcDao; guru._dcDao = dcDao; guru._physicalNetworkDao = physicalNetworkDao; @@ -103,6 +106,11 @@ public class DirectNetworkGuruTest { when(ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NiciraNvp)).thenReturn(false); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testIsMyIsolationMethod() { assertTrue(guru.isMyIsolationMethod(physicalNetwork)); diff --git a/server/src/test/java/com/cloud/network/lb/AssignLoadBalancerTest.java b/server/src/test/java/com/cloud/network/lb/AssignLoadBalancerTest.java index 37194b63ef7..6b7677221bb 100644 --- a/server/src/test/java/com/cloud/network/lb/AssignLoadBalancerTest.java +++ b/server/src/test/java/com/cloud/network/lb/AssignLoadBalancerTest.java @@ -64,9 +64,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.any; import static org.mockito.Mockito.when; diff --git a/server/src/test/java/com/cloud/network/lb/UpdateLoadBalancerTest.java b/server/src/test/java/com/cloud/network/lb/UpdateLoadBalancerTest.java index b9928a6d446..c3e8923b943 100644 --- a/server/src/test/java/com/cloud/network/lb/UpdateLoadBalancerTest.java +++ b/server/src/test/java/com/cloud/network/lb/UpdateLoadBalancerTest.java @@ -50,9 +50,9 @@ import java.util.ArrayList; import java.util.UUID; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; public class UpdateLoadBalancerTest { diff --git a/server/src/test/java/com/cloud/network/router/NetworkHelperImplTest.java b/server/src/test/java/com/cloud/network/router/NetworkHelperImplTest.java index 24a51059e05..8e1408d4998 100644 --- a/server/src/test/java/com/cloud/network/router/NetworkHelperImplTest.java +++ b/server/src/test/java/com/cloud/network/router/NetworkHelperImplTest.java @@ -26,9 +26,9 @@ import com.cloud.exception.ResourceUnavailableException; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -64,7 +64,7 @@ public class NetworkHelperImplTest { nwHelperUT.sendCommandsToRouter(vr, null); // Assert - verify(this.agentManager, times(0)).send((Long) Matchers.anyObject(), (Command) Matchers.anyObject()); + verify(this.agentManager, times(0)).send((Long) ArgumentMatchers.any(), (Command) ArgumentMatchers.any()); } @Test diff --git a/server/src/test/java/com/cloud/network/router/RouterControlHelperTest.java b/server/src/test/java/com/cloud/network/router/RouterControlHelperTest.java index 0b7e325018d..159e476a831 100644 --- a/server/src/test/java/com/cloud/network/router/RouterControlHelperTest.java +++ b/server/src/test/java/com/cloud/network/router/RouterControlHelperTest.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.List; diff --git a/server/src/test/java/com/cloud/network/router/VirtualNetworkApplianceManagerImplTest.java b/server/src/test/java/com/cloud/network/router/VirtualNetworkApplianceManagerImplTest.java index f25e5ef4dbc..ec5fdc0730f 100644 --- a/server/src/test/java/com/cloud/network/router/VirtualNetworkApplianceManagerImplTest.java +++ b/server/src/test/java/com/cloud/network/router/VirtualNetworkApplianceManagerImplTest.java @@ -75,7 +75,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.Date; @@ -83,9 +83,9 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; diff --git a/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerImplTest.java b/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerImplTest.java index 8e3f7da93a0..3d349d4ed0a 100644 --- a/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerImplTest.java +++ b/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerImplTest.java @@ -27,7 +27,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class NetworkACLManagerImplTest { diff --git a/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerTest.java b/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerTest.java index 2ed914ae7fa..651d7cb6aef 100644 --- a/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerTest.java +++ b/server/src/test/java/com/cloud/network/vpc/NetworkACLManagerTest.java @@ -44,7 +44,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -123,7 +123,7 @@ public class NetworkACLManagerTest extends TestCase { @Test public void testCreateACL() throws Exception { - Mockito.when(_networkACLDao.persist(Matchers.any(NetworkACLVO.class))).thenReturn(acl); + Mockito.when(_networkACLDao.persist(ArgumentMatchers.any(NetworkACLVO.class))).thenReturn(acl); assertNotNull(_aclMgr.createNetworkACL("acl_new", "acl desc", 1L, true)); } @@ -133,8 +133,8 @@ public class NetworkACLManagerTest extends TestCase { final NetworkVO network = Mockito.mock(NetworkVO.class); Mockito.when(_networkDao.findById(anyLong())).thenReturn(network); Mockito.when(networkOfferingDao.isIpv6Supported(anyLong())).thenReturn(false); - Mockito.when(_networkModel.isProviderSupportServiceInNetwork(anyLong(), Matchers.any(Network.Service.class), Matchers.any(Network.Provider.class))).thenReturn(true); - Mockito.when(_networkAclElements.get(0).applyNetworkACLs(Matchers.any(Network.class), Matchers.anyList())).thenReturn(true); + Mockito.when(_networkModel.isProviderSupportServiceInNetwork(anyLong(), ArgumentMatchers.any(Network.Service.class), ArgumentMatchers.any(Network.Provider.class))).thenReturn(true); + Mockito.when(_networkAclElements.get(0).applyNetworkACLs(ArgumentMatchers.any(Network.class), ArgumentMatchers.anyList())).thenReturn(true); assertTrue(_aclMgr.applyACLToNetwork(1L)); } diff --git a/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java b/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java index 3d63b1db507..cd1745cc2ef 100644 --- a/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java +++ b/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java @@ -787,7 +787,7 @@ public class NetworkACLServiceImplTest { Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setNumber(Mockito.anyInt()); Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setSourcePortStart(Mockito.anyInt()); Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setSourcePortEnd(Mockito.anyInt()); - Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setSourceCidrList(Mockito.anyListOf(String.class)); + Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setSourceCidrList(Mockito.anyList()); Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setProtocol(Mockito.anyString()); Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setIcmpCode(Mockito.anyInt()); Mockito.verify(networkAclItemVoMock, Mockito.times(0)).setIcmpType(Mockito.anyInt()); @@ -956,12 +956,12 @@ public class NetworkACLServiceImplTest { networkAclServiceImpl.moveNetworkAclRuleToNewPosition(moveNetworkAclItemCmdMock); - Mockito.verify(networkAclServiceImpl, Mockito.times(1)).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class), Mockito.eq(previousAclRuleMock), + Mockito.verify(networkAclServiceImpl, Mockito.times(1)).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList(), Mockito.eq(previousAclRuleMock), Mockito.eq(nextAclRuleMock)); Mockito.verify(networkAclServiceImpl, Mockito.times(1)).validateAclConsistency(Mockito.any(MoveNetworkAclItemCmd.class), Mockito.any(NetworkACLVO.class), - Mockito.anyListOf(NetworkACLItemVO.class)); + Mockito.anyList()); } @Test @@ -979,12 +979,12 @@ public class NetworkACLServiceImplTest { networkAclServiceImpl.moveNetworkAclRuleToNewPosition(moveNetworkAclItemCmdMock); - Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.verify(networkAclServiceImpl, Mockito.times(1)).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class), Mockito.eq(previousAclRuleMock), + Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.verify(networkAclServiceImpl, Mockito.times(1)).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList(), Mockito.eq(previousAclRuleMock), Mockito.eq(nextAclRuleMock)); Mockito.verify(networkAclServiceImpl, Mockito.times(1)).validateAclConsistency(Mockito.any(MoveNetworkAclItemCmd.class), Mockito.any(NetworkACLVO.class), - Mockito.anyListOf(NetworkACLItemVO.class)); + Mockito.anyList()); } @Test @@ -1002,23 +1002,23 @@ public class NetworkACLServiceImplTest { networkAclServiceImpl.moveNetworkAclRuleToNewPosition(moveNetworkAclItemCmdMock); - Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.verify(networkAclServiceImpl, Mockito.times(1)).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class), Mockito.eq(previousAclRuleMock), + Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.verify(networkAclServiceImpl, Mockito.times(0)).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.verify(networkAclServiceImpl, Mockito.times(1)).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList(), Mockito.eq(previousAclRuleMock), Mockito.eq(nextAclRuleMock)); Mockito.verify(networkAclServiceImpl, Mockito.times(1)).validateAclConsistency(Mockito.any(MoveNetworkAclItemCmd.class), Mockito.any(NetworkACLVO.class), - Mockito.anyListOf(NetworkACLItemVO.class)); + Mockito.anyList()); } private void configureMoveMethodsToDoNothing() { Mockito.doReturn(networkACLVOMock).when(networkAclDaoMock).acquireInLockTable(Mockito.anyLong()); Mockito.doReturn(true).when(networkAclDaoMock).releaseFromLockTable(Mockito.anyLong()); - Mockito.doNothing().when(networkAclServiceImpl).validateAclConsistency(Mockito.any(MoveNetworkAclItemCmd.class), Mockito.any(NetworkACLVO.class), Mockito.anyListOf(NetworkACLItemVO.class)); + Mockito.doNothing().when(networkAclServiceImpl).validateAclConsistency(Mockito.any(MoveNetworkAclItemCmd.class), Mockito.any(NetworkACLVO.class), Mockito.anyList()); - Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class)); - Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyListOf(NetworkACLItemVO.class), + Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).moveRuleToTheTop(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).moveRuleToTheBottom(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList()); + Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).moveRuleBetweenAclRules(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyList(), Mockito.eq(previousAclRuleMock), Mockito.eq(nextAclRuleMock)); } @@ -1164,11 +1164,11 @@ public class NetworkACLServiceImplTest { @Test public void moveRuleToTheTopTest() { Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).updateAclRuleToNewPositionAndExecuteShiftIfNecessary(Mockito.eq(aclRuleBeingMovedMock), Mockito.anyInt(), - Mockito.anyListOf(NetworkACLItemVO.class), Mockito.anyInt()); + Mockito.anyList(), Mockito.anyInt()); networkAclServiceImpl.moveRuleToTheTop(aclRuleBeingMovedMock, new ArrayList<>()); - Mockito.verify(networkAclServiceImpl).updateAclRuleToNewPositionAndExecuteShiftIfNecessary(Mockito.eq(aclRuleBeingMovedMock), Mockito.eq(1), Mockito.anyListOf(NetworkACLItemVO.class), + Mockito.verify(networkAclServiceImpl).updateAclRuleToNewPositionAndExecuteShiftIfNecessary(Mockito.eq(aclRuleBeingMovedMock), Mockito.eq(1), Mockito.anyList(), Mockito.eq(0)); } @@ -1230,14 +1230,14 @@ public class NetworkACLServiceImplTest { allAclRules.add(aclRuleBeingMovedMock); Mockito.doReturn(aclRuleBeingMovedMock).when(networkAclServiceImpl).updateAclRuleToNewPositionAndExecuteShiftIfNecessary(Mockito.any(NetworkACLItemVO.class), Mockito.anyInt(), - Mockito.anyListOf(NetworkACLItemVO.class), Mockito.anyInt()); + Mockito.anyList(), Mockito.anyInt()); networkAclServiceImpl.moveRuleBetweenAclRules(aclRuleBeingMovedMock, allAclRules, previousAclRuleMock, nextAclRuleMock); Mockito.verify(networkAclItemDaoMock, times(0)).updateNumberFieldNetworkItem(aclRuleBeingMovedMock.getId(), 11); Mockito.verify(networkAclItemDaoMock, times(0)).findById(1l); Mockito.verify(networkAclServiceImpl, Mockito.times(1)).updateAclRuleToNewPositionAndExecuteShiftIfNecessary(Mockito.any(NetworkACLItemVO.class), Mockito.eq(11), - Mockito.anyListOf(NetworkACLItemVO.class), Mockito.eq(1)); + Mockito.anyList(), Mockito.eq(1)); } @Test @@ -1261,7 +1261,7 @@ public class NetworkACLServiceImplTest { Mockito.verify(networkAclItemDaoMock).updateNumberFieldNetworkItem(aclRuleBeingMovedMock.getId(), 11); Mockito.verify(networkAclItemDaoMock).findById(1l); Mockito.verify(networkAclServiceImpl, Mockito.times(0)).updateAclRuleToNewPositionAndExecuteShiftIfNecessary(Mockito.any(NetworkACLItemVO.class), Mockito.anyInt(), - Mockito.anyListOf(NetworkACLItemVO.class), Mockito.anyInt()); + Mockito.anyList(), Mockito.anyInt()); } @Test diff --git a/server/src/test/java/com/cloud/resource/RollingMaintenanceManagerImplTest.java b/server/src/test/java/com/cloud/resource/RollingMaintenanceManagerImplTest.java index ef0277fd372..80d159fa3ea 100644 --- a/server/src/test/java/com/cloud/resource/RollingMaintenanceManagerImplTest.java +++ b/server/src/test/java/com/cloud/resource/RollingMaintenanceManagerImplTest.java @@ -24,6 +24,7 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor; import com.cloud.org.Cluster; import com.cloud.utils.exception.CloudRuntimeException; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -72,9 +73,11 @@ public class RollingMaintenanceManagerImplTest { private static final long podId = 1L; private static final long zoneId = 1L; + private AutoCloseable closeable; + @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Mockito.when(hostDao.findByClusterId(clusterId1)).thenReturn(Arrays.asList(host1, host2)); Mockito.when(hostDao.findByClusterId(clusterId2)).thenReturn(Arrays.asList(host3, host4)); List hosts = Arrays.asList(host1, host2, host3, host4); @@ -102,6 +105,11 @@ public class RollingMaintenanceManagerImplTest { Mockito.when(host2.getResourceState()).thenReturn(ResourceState.Enabled); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + private void checkResults(Map> result) { Assert.assertEquals(2, result.size()); Assert.assertTrue(result.containsKey(clusterId1)); diff --git a/server/src/test/java/com/cloud/server/ConfigurationServerImplTest.java b/server/src/test/java/com/cloud/server/ConfigurationServerImplTest.java index 1478892d166..fd1cb6a6313 100644 --- a/server/src/test/java/com/cloud/server/ConfigurationServerImplTest.java +++ b/server/src/test/java/com/cloud/server/ConfigurationServerImplTest.java @@ -39,7 +39,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class ConfigurationServerImplTest { diff --git a/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java b/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java index a41cbb82704..5427e6c839f 100644 --- a/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java +++ b/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java @@ -18,10 +18,10 @@ package com.cloud.storage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.lenient; diff --git a/server/src/test/java/com/cloud/storage/dao/AsyncJobJoinDaoTest.java b/server/src/test/java/com/cloud/storage/dao/AsyncJobJoinDaoTest.java index 3fb95d17034..c6876c7ea07 100644 --- a/server/src/test/java/com/cloud/storage/dao/AsyncJobJoinDaoTest.java +++ b/server/src/test/java/com/cloud/storage/dao/AsyncJobJoinDaoTest.java @@ -26,7 +26,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.Date; diff --git a/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java b/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java index fb7319bd46b..74b31283d9d 100755 --- a/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java +++ b/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java @@ -17,8 +17,8 @@ package com.cloud.storage.snapshot; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java b/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java index a69795cf2c8..98b1c05dba8 100755 --- a/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java +++ b/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java @@ -137,9 +137,9 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; diff --git a/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java b/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java index 21474a53ee7..2cd6f486943 100644 --- a/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java +++ b/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java @@ -56,7 +56,7 @@ import java.util.List; import java.util.Map; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/server/src/test/java/com/cloud/user/DomainManagerImplTest.java b/server/src/test/java/com/cloud/user/DomainManagerImplTest.java index 319263104c8..829f0c9cb20 100644 --- a/server/src/test/java/com/cloud/user/DomainManagerImplTest.java +++ b/server/src/test/java/com/cloud/user/DomainManagerImplTest.java @@ -55,7 +55,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -233,10 +233,10 @@ public class DomainManagerImplTest { @Test public void testPublishRemoveEventsAndRemoveDomainSuccessfulDelete() { domainManager.publishRemoveEventsAndRemoveDomain(domain); - Mockito.verify(_messageBus).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT), - Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); - Mockito.verify(_messageBus).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT), - Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); + Mockito.verify(_messageBus).publish(Mockito.anyString(), ArgumentMatchers.eq(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT), + ArgumentMatchers.eq(PublishScope.LOCAL), ArgumentMatchers.eq(domain)); + Mockito.verify(_messageBus).publish(Mockito.anyString(), ArgumentMatchers.eq(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT), + ArgumentMatchers.eq(PublishScope.LOCAL), ArgumentMatchers.eq(domain)); Mockito.verify(domainDaoMock).remove(DOMAIN_ID); } @@ -244,10 +244,10 @@ public class DomainManagerImplTest { public void testPublishRemoveEventsAndRemoveDomainExceptionDelete() { Mockito.when(domainDaoMock.remove(DOMAIN_ID)).thenReturn(false); domainManager.publishRemoveEventsAndRemoveDomain(domain); - Mockito.verify(_messageBus).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT), - Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); - Mockito.verify(_messageBus, Mockito.never()).publish(Mockito.anyString(), Matchers.eq(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT), - Matchers.eq(PublishScope.LOCAL), Matchers.eq(domain)); + Mockito.verify(_messageBus).publish(Mockito.anyString(), ArgumentMatchers.eq(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT), + ArgumentMatchers.eq(PublishScope.LOCAL), ArgumentMatchers.eq(domain)); + Mockito.verify(_messageBus, Mockito.never()).publish(Mockito.anyString(), ArgumentMatchers.eq(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT), + ArgumentMatchers.eq(PublishScope.LOCAL), ArgumentMatchers.eq(domain)); Mockito.verify(domainDaoMock).remove(DOMAIN_ID); } @@ -268,7 +268,7 @@ public class DomainManagerImplTest { Mockito.when(domainDaoMock.findById(20l)).thenReturn(domain); Mockito.doNothing().when(_accountMgr).checkAccess(Mockito.any(Account.class), Mockito.any(Domain.class)); Mockito.when(domainDaoMock.update(Mockito.eq(20l), Mockito.any(DomainVO.class))).thenReturn(true); - Mockito.lenient().when(_accountDao.search(Mockito.any(SearchCriteria.class), (Filter)org.mockito.Matchers.isNull())).thenReturn(new ArrayList()); + Mockito.lenient().when(_accountDao.search(Mockito.any(SearchCriteria.class), (Filter) org.mockito.ArgumentMatchers.isNull())).thenReturn(new ArrayList()); Mockito.when(_networkDomainDao.listNetworkIdsByDomain(Mockito.anyLong())).thenReturn(new ArrayList()); Mockito.when(_accountDao.findCleanupsForRemovedAccounts(Mockito.anyLong())).thenReturn(new ArrayList()); Mockito.when(_dedicatedDao.listByDomainId(Mockito.anyLong())).thenReturn(new ArrayList()); @@ -295,9 +295,9 @@ public class DomainManagerImplTest { Mockito.doNothing().when(_accountMgr).checkAccess(Mockito.any(Account.class), Mockito.any(Domain.class)); Mockito.when(domainDaoMock.update(Mockito.eq(20l), Mockito.any(DomainVO.class))).thenReturn(true); Mockito.when(domainDaoMock.createSearchCriteria()).thenReturn(Mockito.mock(SearchCriteria.class)); - Mockito.when(domainDaoMock.search(Mockito.any(SearchCriteria.class), (Filter)org.mockito.Matchers.isNull())).thenReturn(new ArrayList()); + Mockito.when(domainDaoMock.search(Mockito.any(SearchCriteria.class), (Filter) org.mockito.ArgumentMatchers.isNull())).thenReturn(new ArrayList()); Mockito.when(_accountDao.createSearchCriteria()).thenReturn(Mockito.mock(SearchCriteria.class)); - Mockito.when(_accountDao.search(Mockito.any(SearchCriteria.class), (Filter)org.mockito.Matchers.isNull())).thenReturn(new ArrayList()); + Mockito.when(_accountDao.search(Mockito.any(SearchCriteria.class), (Filter) org.mockito.ArgumentMatchers.isNull())).thenReturn(new ArrayList()); Mockito.when(_networkDomainDao.listNetworkIdsByDomain(Mockito.anyLong())).thenReturn(new ArrayList()); Mockito.when(_accountDao.findCleanupsForRemovedAccounts(Mockito.anyLong())).thenReturn(new ArrayList()); Mockito.when(_dedicatedDao.listByDomainId(Mockito.anyLong())).thenReturn(new ArrayList()); diff --git a/server/src/test/java/com/cloud/vm/FirstFitPlannerTest.java b/server/src/test/java/com/cloud/vm/FirstFitPlannerTest.java index eecd7cc2d35..33bccecac20 100644 --- a/server/src/test/java/com/cloud/vm/FirstFitPlannerTest.java +++ b/server/src/test/java/com/cloud/vm/FirstFitPlannerTest.java @@ -70,7 +70,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -93,7 +93,7 @@ import java.util.List; import java.util.Map; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -330,7 +330,7 @@ public class FirstFitPlannerTest { hostList6.add(new Long(15)); String[] implicitHostTags = {"GPU"}; int ramInBytes = ramInOffering * 1024 * 1024; - when(serviceOfferingDetailsDao.findDetail(Matchers.anyLong(), anyString())).thenReturn(null); + when(serviceOfferingDetailsDao.findDetail(ArgumentMatchers.anyLong(), anyString())).thenReturn(null); when(hostGpuGroupsDao.listHostIds()).thenReturn(hostList0); when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(1), Host.Type.Routing.toString())).thenReturn(hostList1); when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(2), Host.Type.Routing.toString())).thenReturn(hostList2); diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java index e2c2b8ef9e2..1b353c8626a 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java @@ -487,7 +487,7 @@ public class UserVmManagerImplTest { Mockito.doReturn(new ArrayList()).when(userVmManagerImpl).getSecurityGroupIdList(updateVmCommand); Mockito.lenient().doReturn(Mockito.mock(UserVm.class)).when(userVmManagerImpl).updateVirtualMachine(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyLong(), - Mockito.anyString(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any(HTTPMethod.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Long.class), + Mockito.anyString(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any(HTTPMethod.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), Mockito.anyMap()); } diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerTest.java index 4bdfd498c41..8be100d4570 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerTest.java @@ -101,13 +101,13 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.lenient; diff --git a/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java b/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java index 532b2fa9810..0ed17fcce76 100644 --- a/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java +++ b/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java @@ -62,11 +62,12 @@ import org.apache.cloudstack.api.ResourceDetail; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; @@ -78,9 +79,9 @@ import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -174,9 +175,11 @@ public class VMSnapshotManagerTest { @Captor ArgumentCaptor> listUserVmDetailsCaptor; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); doReturn(admin).when(_vmSnapshotMgr).getCaller(); _vmSnapshotMgr._accountDao = _accountDao; _vmSnapshotMgr._userVMDao = _userVMDao; @@ -247,6 +250,11 @@ public class VMSnapshotManagerTest { when(vmSnapshotVO.getServiceOfferingId()).thenReturn(SERVICE_OFFERING_ID); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + // vmId null case @Test(expected = InvalidParameterValueException.class) public void testAllocVMSnapshotF1() throws ResourceAllocationException { @@ -343,12 +351,12 @@ public class VMSnapshotManagerTest { @Test public void testUpdateUserVmServiceOfferingDifferentServiceOffering() throws ConcurrentOperationException, ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException { when(userVm.getServiceOfferingId()).thenReturn(SERVICE_OFFERING_DIFFERENT_ID); - when(_userVmManager.upgradeVirtualMachine(Matchers.eq(TEST_VM_ID), Matchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture())).thenReturn(true); + when(_userVmManager.upgradeVirtualMachine(ArgumentMatchers.eq(TEST_VM_ID), ArgumentMatchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture())).thenReturn(true); _vmSnapshotMgr.updateUserVmServiceOffering(userVm, vmSnapshotVO); verify(_vmSnapshotMgr).changeUserVmServiceOffering(userVm, vmSnapshotVO); verify(_vmSnapshotMgr).getVmMapDetails(userVm); - verify(_vmSnapshotMgr).upgradeUserVmServiceOffering(Matchers.eq(TEST_VM_ID), Matchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture()); + verify(_vmSnapshotMgr).upgradeUserVmServiceOffering(ArgumentMatchers.eq(TEST_VM_ID), ArgumentMatchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture()); } @Test @@ -363,18 +371,18 @@ public class VMSnapshotManagerTest { @Test public void testChangeUserVmServiceOffering() throws ConcurrentOperationException, ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException { - when(_userVmManager.upgradeVirtualMachine(Matchers.eq(TEST_VM_ID), Matchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture())).thenReturn(true); + when(_userVmManager.upgradeVirtualMachine(ArgumentMatchers.eq(TEST_VM_ID), ArgumentMatchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture())).thenReturn(true); _vmSnapshotMgr.changeUserVmServiceOffering(userVm, vmSnapshotVO); verify(_vmSnapshotMgr).getVmMapDetails(userVm); - verify(_vmSnapshotMgr).upgradeUserVmServiceOffering(Matchers.eq(TEST_VM_ID), Matchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture()); + verify(_vmSnapshotMgr).upgradeUserVmServiceOffering(ArgumentMatchers.eq(TEST_VM_ID), ArgumentMatchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture()); } @Test(expected=CloudRuntimeException.class) public void testChangeUserVmServiceOfferingFailOnUpgradeVMServiceOffering() throws ConcurrentOperationException, ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException { - when(_userVmManager.upgradeVirtualMachine(Matchers.eq(TEST_VM_ID), Matchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture())).thenReturn(false); + when(_userVmManager.upgradeVirtualMachine(ArgumentMatchers.eq(TEST_VM_ID), ArgumentMatchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture())).thenReturn(false); _vmSnapshotMgr.changeUserVmServiceOffering(userVm, vmSnapshotVO); verify(_vmSnapshotMgr).getVmMapDetails(userVm); - verify(_vmSnapshotMgr).upgradeUserVmServiceOffering(Matchers.eq(TEST_VM_ID), Matchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture()); + verify(_vmSnapshotMgr).upgradeUserVmServiceOffering(ArgumentMatchers.eq(TEST_VM_ID), ArgumentMatchers.eq(SERVICE_OFFERING_ID), mapDetailsCaptor.capture()); } @Test diff --git a/server/src/test/java/com/cloud/vpc/NetworkACLServiceTest.java b/server/src/test/java/com/cloud/vpc/NetworkACLServiceTest.java index 0709243d927..d2f00c409ae 100644 --- a/server/src/test/java/com/cloud/vpc/NetworkACLServiceTest.java +++ b/server/src/test/java/com/cloud/vpc/NetworkACLServiceTest.java @@ -47,7 +47,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -100,16 +100,16 @@ public class NetworkACLServiceTest extends TestCase { @Test(expected = InvalidParameterValueException.class) public void testDeleteDefaultACL() throws Exception { - Mockito.when(_networkACLDao.findById(Matchers.anyLong())).thenReturn(acl); + Mockito.when(_networkACLDao.findById(ArgumentMatchers.anyLong())).thenReturn(acl); Mockito.when(_networkAclMgr.deleteNetworkACL(acl)).thenReturn(true); _aclService.deleteNetworkACL(1L); } @Test public void testDeleteACLItem() throws Exception { - Mockito.when(_networkACLItemDao.findById(Matchers.anyLong())).thenReturn(aclItem); - Mockito.when(_networkAclMgr.getNetworkACL(Matchers.anyLong())).thenReturn(acl); - Mockito.when(_networkAclMgr.revokeNetworkACLItem(Matchers.anyLong())).thenReturn(true); + Mockito.when(_networkACLItemDao.findById(ArgumentMatchers.anyLong())).thenReturn(aclItem); + Mockito.when(_networkAclMgr.getNetworkACL(ArgumentMatchers.anyLong())).thenReturn(acl); + Mockito.when(_networkAclMgr.revokeNetworkACLItem(ArgumentMatchers.anyLong())).thenReturn(true); Mockito.when(_entityMgr.findById(Mockito.eq(Vpc.class), Mockito.anyLong())).thenReturn(new VpcVO()); assertTrue(_aclService.revokeNetworkACLItem(1L)); } diff --git a/server/src/test/java/org/apache/cloudstack/acl/RoleManagerImplTest.java b/server/src/test/java/org/apache/cloudstack/acl/RoleManagerImplTest.java index a1350462277..2bb46c0deee 100644 --- a/server/src/test/java/org/apache/cloudstack/acl/RoleManagerImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/acl/RoleManagerImplTest.java @@ -30,7 +30,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.List; diff --git a/server/src/test/java/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/src/test/java/org/apache/cloudstack/affinity/AffinityApiUnitTest.java index 361d026c22f..e27d9618c92 100644 --- a/server/src/test/java/org/apache/cloudstack/affinity/AffinityApiUnitTest.java +++ b/server/src/test/java/org/apache/cloudstack/affinity/AffinityApiUnitTest.java @@ -52,7 +52,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -76,10 +76,10 @@ import java.util.UUID; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @RunWith(SpringJUnit4ClassRunner.class) @@ -149,12 +149,12 @@ public class AffinityApiUnitTest { _affinityService.setAffinityGroupProcessors(affinityProcessors); AffinityGroupVO group = new AffinityGroupVO("group1", "mock", "mock group", domainId, 200L, ControlledEntity.ACLType.Account); - Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group); - Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group); - Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group); - Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group); - Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true); - Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO()); + Mockito.when(_affinityGroupDao.persist(ArgumentMatchers.any(AffinityGroupVO.class))).thenReturn(group); + Mockito.when(_affinityGroupDao.findById(ArgumentMatchers.anyLong())).thenReturn(group); + Mockito.when(_affinityGroupDao.findByAccountAndName(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString())).thenReturn(group); + Mockito.when(_affinityGroupDao.lockRow(ArgumentMatchers.anyLong(), anyBoolean())).thenReturn(group); + Mockito.when(_affinityGroupDao.expunge(ArgumentMatchers.anyLong())).thenReturn(true); + Mockito.when(_eventDao.persist(ArgumentMatchers.any(EventVO.class))).thenReturn(new EventVO()); } @After diff --git a/server/src/test/java/org/apache/cloudstack/affinity/AffinityGroupServiceImplTest.java b/server/src/test/java/org/apache/cloudstack/affinity/AffinityGroupServiceImplTest.java index e25ea6a09d4..5657bd1f506 100644 --- a/server/src/test/java/org/apache/cloudstack/affinity/AffinityGroupServiceImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/affinity/AffinityGroupServiceImplTest.java @@ -54,7 +54,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -78,11 +78,10 @@ import java.util.UUID; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @RunWith(SpringJUnit4ClassRunner.class) @@ -157,12 +156,12 @@ public class AffinityGroupServiceImplTest { _affinityService.setAffinityGroupProcessors(affinityProcessors); AffinityGroupVO group = new AffinityGroupVO(AFFINITY_GROUP_NAME, "mock", "mock group", DOMAIN_ID, 200L, ControlledEntity.ACLType.Account); - Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group); - Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group); - Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group); - Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group); - Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true); - Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO()); + Mockito.when(_affinityGroupDao.persist(ArgumentMatchers.any(AffinityGroupVO.class))).thenReturn(group); + Mockito.when(_affinityGroupDao.findById(ArgumentMatchers.anyLong())).thenReturn(group); + Mockito.when(_affinityGroupDao.findByAccountAndName(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString())).thenReturn(group); + Mockito.when(_affinityGroupDao.lockRow(ArgumentMatchers.anyLong(), anyBoolean())).thenReturn(group); + Mockito.when(_affinityGroupDao.expunge(ArgumentMatchers.anyLong())).thenReturn(true); + Mockito.when(_eventDao.persist(ArgumentMatchers.any(EventVO.class))).thenReturn(new EventVO()); } @After @@ -216,7 +215,7 @@ public class AffinityGroupServiceImplTest { public void shouldDeleteDomainLevelAffinityGroup() { AffinityGroupVO mockGroup = Mockito.mock(AffinityGroupVO.class); when(mockGroup.getId()).thenReturn(2L); - when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(mockGroup); + when(_affinityGroupDao.findById(ArgumentMatchers.anyLong())).thenReturn(mockGroup); _affinityService.deleteAffinityGroup(2L, null, null, DOMAIN_ID, null); Mockito.verify(_affinityGroupDao).expunge(2L); } @@ -225,14 +224,14 @@ public class AffinityGroupServiceImplTest { public void shouldDeleteAffintyGroupById() { AffinityGroupVO mockGroup = Mockito.mock(AffinityGroupVO.class); when(mockGroup.getId()).thenReturn(1L); - when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(mockGroup); + when(_affinityGroupDao.findById(ArgumentMatchers.anyLong())).thenReturn(mockGroup); _affinityService.deleteAffinityGroup(1L, ACCOUNT_NAME, null, DOMAIN_ID, null); Mockito.verify(_affinityGroupDao).expunge(1L); } @Test(expected = InvalidParameterValueException.class) public void invalidAffinityTypeTest() { - when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); + when(_acctMgr.finalizeOwner((Account)any(), anyString(), anyLong(), anyLong())).thenReturn(acct); _affinityService.createAffinityGroup(ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME, "invalid", "affinity group one"); } @@ -246,14 +245,14 @@ public class AffinityGroupServiceImplTest { @Test(expected = InvalidParameterValueException.class) public void deleteAffinityGroupInvalidIdTest() throws ResourceInUseException { - when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); + when(_acctMgr.finalizeOwner((Account)any(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_groupDao.findById(20L)).thenReturn(null); _affinityService.deleteAffinityGroup(20L, ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME); } @Test(expected = InvalidParameterValueException.class) public void deleteAffinityGroupInvalidIdName() throws ResourceInUseException { - when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); + when(_acctMgr.finalizeOwner((Account)any(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_acctMgr.finalyzeAccountId(ACCOUNT_NAME, DOMAIN_ID, null, true)).thenReturn(200L); when(_groupDao.findByAccountAndName(200L, AFFINITY_GROUP_NAME)).thenReturn(null); _affinityService.deleteAffinityGroup(null, ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME); @@ -261,13 +260,13 @@ public class AffinityGroupServiceImplTest { @Test(expected = InvalidParameterValueException.class) public void deleteAffinityGroupNullIdName() throws ResourceInUseException { - when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); + when(_acctMgr.finalizeOwner((Account)any(), anyString(), anyLong(), anyLong())).thenReturn(acct); _affinityService.deleteAffinityGroup(null, ACCOUNT_NAME, null, DOMAIN_ID, null); } @Test(expected = InvalidParameterValueException.class) public void updateAffinityGroupVMRunning() throws ResourceInUseException { - when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); + when(_acctMgr.finalizeOwner((Account)any(), anyString(), anyLong(), anyLong())).thenReturn(acct); UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, DOMAIN_ID, 200L, 1, 5L, "", null, null, "test"); vm.setState(VirtualMachine.State.Running); when(_vmDao.findById(10L)).thenReturn(vm); diff --git a/server/src/test/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImplTest.java b/server/src/test/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImplTest.java index 4ba381ee0ac..2f0c1c3185c 100644 --- a/server/src/test/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImplTest.java @@ -26,6 +26,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.config.ApiServiceConfiguration; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.messagebus.MessageBus; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -69,6 +70,7 @@ public class IndirectAgentLBServiceImplTest { private static final long DC_1_ID = 1L; private static final long DC_2_ID = 2L; + private AutoCloseable closeable; private void overrideDefaultConfigValue(final ConfigKey configKey, final String name, final Object o) throws IllegalAccessException, NoSuchFieldException { final Field f = ConfigKey.class.getDeclaredField(name); @@ -101,12 +103,17 @@ public class IndirectAgentLBServiceImplTest { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); configureMocks(); agentMSLB.configure("someName", null); overrideDefaultConfigValue(ApiServiceConfiguration.ManagementServerAddresses, "_defaultValue", msCSVList); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testStaticLBSetting() throws NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(IndirectAgentLBServiceImpl.IndirectAgentLBAlgorithm, "_defaultValue", "static"); diff --git a/server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java b/server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java index 37fbf049b0a..7726af09361 100644 --- a/server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java +++ b/server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java @@ -31,6 +31,7 @@ import com.cloud.vm.VirtualMachineManager; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.admin.backup.UpdateBackupOfferingCmd; import org.apache.cloudstack.backup.dao.BackupOfferingDao; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -72,10 +73,11 @@ public class BackupManagerTest { private String[] hostPossibleValues = {"127.0.0.1", "hostname"}; private String[] datastoresPossibleValues = {"e9804933-8609-4de3-bccc-6278072a496c", "datastore-name"}; + private AutoCloseable closeable; @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); when(backupOfferingDao.findById(null)).thenReturn(null); when(backupOfferingDao.findById(123l)).thenReturn(null); @@ -96,6 +98,11 @@ public class BackupManagerTest { }); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testExceptionWhenUpdateWithNullId() { try { diff --git a/server/src/test/java/org/apache/cloudstack/ca/CABackgroundTaskTest.java b/server/src/test/java/org/apache/cloudstack/ca/CABackgroundTaskTest.java index c02a345bc67..691bd882c07 100644 --- a/server/src/test/java/org/apache/cloudstack/ca/CABackgroundTaskTest.java +++ b/server/src/test/java/org/apache/cloudstack/ca/CABackgroundTaskTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.security.KeyPair; diff --git a/server/src/test/java/org/apache/cloudstack/cluster/ClusterDrsServiceImplTest.java b/server/src/test/java/org/apache/cloudstack/cluster/ClusterDrsServiceImplTest.java index e82b39a47ec..315e976b0a4 100644 --- a/server/src/test/java/org/apache/cloudstack/cluster/ClusterDrsServiceImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/cluster/ClusterDrsServiceImplTest.java @@ -268,7 +268,7 @@ public class ClusterDrsServiceImplTest { Mockito.when(cluster.getAllocationState()).thenReturn(Grouping.AllocationState.Enabled); Mockito.when(clusterDao.findById(1L)).thenReturn(cluster); Mockito.when(clusterDrsService.getDrsPlan(cluster, 5)).thenThrow(new ConfigurationException("test")); - Mockito.when(cmd.getMaxMigrations()).thenReturn(1); + Mockito.when(cmd.getMaxMigrations()).thenReturn(5); clusterDrsService.generateDrsPlan(cmd); } diff --git a/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsFilesListFactoryTest.java b/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsFilesListFactoryTest.java index 7f7690bd41f..e1838678cfa 100644 --- a/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsFilesListFactoryTest.java +++ b/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsFilesListFactoryTest.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.List; diff --git a/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsServiceImplTest.java b/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsServiceImplTest.java index 421880d4a37..2855196f9dc 100644 --- a/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsServiceImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/diagnostics/DiagnosticsServiceImplTest.java @@ -37,7 +37,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.HashMap; import java.util.Map; diff --git a/server/src/test/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImplTest.java b/server/src/test/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImplTest.java index bee3a354c52..3f79a03a4f4 100644 --- a/server/src/test/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImplTest.java @@ -29,7 +29,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.HashMap; import java.util.Map; diff --git a/server/src/test/java/org/apache/cloudstack/network/lb/ApplicationLoadBalancerTest.java b/server/src/test/java/org/apache/cloudstack/network/lb/ApplicationLoadBalancerTest.java index d29f58806e9..1e547343c7f 100644 --- a/server/src/test/java/org/apache/cloudstack/network/lb/ApplicationLoadBalancerTest.java +++ b/server/src/test/java/org/apache/cloudstack/network/lb/ApplicationLoadBalancerTest.java @@ -53,7 +53,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -144,21 +144,21 @@ public class ApplicationLoadBalancerTest extends TestCase { ApplicationLoadBalancerRuleVO lbRule = new ApplicationLoadBalancerRuleVO("new", "new", 22, 22, "roundrobin", validGuestNetworkId, validAccountId, 1L, new Ip(validRequestedIp), validGuestNetworkId, Scheme.Internal); - Mockito.when(_lbDao.persist(Matchers.any(ApplicationLoadBalancerRuleVO.class))).thenReturn(lbRule); + Mockito.when(_lbDao.persist(ArgumentMatchers.any(ApplicationLoadBalancerRuleVO.class))).thenReturn(lbRule); - Mockito.when(_lbMgr.validateLbRule(Matchers.any(LoadBalancingRule.class))).thenReturn(true); + Mockito.when(_lbMgr.validateLbRule(ArgumentMatchers.any(LoadBalancingRule.class))).thenReturn(true); - Mockito.when(_firewallDao.setStateToAdd(Matchers.any(FirewallRuleVO.class))).thenReturn(true); + Mockito.when(_firewallDao.setStateToAdd(ArgumentMatchers.any(FirewallRuleVO.class))).thenReturn(true); Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1)); Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2)); CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); - Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(true); + Mockito.when(_ntwkModel.areServicesSupportedInNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Network.Service.class))).thenReturn(true); Map caps = new HashMap(); caps.put(Capability.SupportedProtocols, NetUtils.TCP_PROTO); - Mockito.when(_ntwkModel.getNetworkServiceCapabilities(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(caps); + Mockito.when(_ntwkModel.getNetworkServiceCapabilities(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Network.Service.class))).thenReturn(caps); Mockito.when(_lbDao.countBySourceIp(new Ip(validRequestedIp), validGuestNetworkId)).thenReturn(1L); diff --git a/server/src/test/java/org/apache/cloudstack/network/router/deployment/RouterDeploymentDefinitionTest.java b/server/src/test/java/org/apache/cloudstack/network/router/deployment/RouterDeploymentDefinitionTest.java index c84db90d84b..f9d6d0dfcba 100644 --- a/server/src/test/java/org/apache/cloudstack/network/router/deployment/RouterDeploymentDefinitionTest.java +++ b/server/src/test/java/org/apache/cloudstack/network/router/deployment/RouterDeploymentDefinitionTest.java @@ -45,9 +45,9 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationSe import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.List; @@ -58,7 +58,7 @@ import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; @@ -688,7 +688,7 @@ public class RouterDeploymentDefinitionTest extends RouterDeploymentDefinitionTe when(mockNw.getNetworkOfferingId()).thenReturn(OFFERING_ID); when(mockNetworkOfferingDao.findById(OFFERING_ID)).thenReturn(mockNwOfferingVO); when(mockNwOfferingVO.getServiceOfferingId()).thenReturn(null); - when(mockServiceOfferingDao.findDefaultSystemOffering(Matchers.anyString(), Matchers.anyBoolean())).thenReturn(mockSvcOfferingVO); + when(mockServiceOfferingDao.findDefaultSystemOffering(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean())).thenReturn(mockSvcOfferingVO); when(mockSvcOfferingVO.getId()).thenReturn(DEFAULT_OFFERING_ID); // Execute diff --git a/server/src/test/java/org/apache/cloudstack/network/router/deployment/VpcRouterDeploymentDefinitionTest.java b/server/src/test/java/org/apache/cloudstack/network/router/deployment/VpcRouterDeploymentDefinitionTest.java index 26601ff1db9..969fb1f209c 100644 --- a/server/src/test/java/org/apache/cloudstack/network/router/deployment/VpcRouterDeploymentDefinitionTest.java +++ b/server/src/test/java/org/apache/cloudstack/network/router/deployment/VpcRouterDeploymentDefinitionTest.java @@ -35,7 +35,7 @@ import com.cloud.network.vpc.dao.VpcOfferingDao; import com.cloud.vm.DomainRouterVO; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import java.util.List; @@ -45,7 +45,7 @@ import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -205,7 +205,7 @@ public class VpcRouterDeploymentDefinitionTest extends RouterDeploymentDefinitio final VpcOfferingVO vpcOffering = mock(VpcOfferingVO.class); when(mockVpcOffDao.findById(VPC_OFFERING_ID)).thenReturn(vpcOffering); when(vpcOffering.getServiceOfferingId()).thenReturn(null); - when(mockServiceOfferingDao.findDefaultSystemOffering(Matchers.anyString(), Matchers.anyBoolean())).thenReturn(mockSvcOfferingVO); + when(mockServiceOfferingDao.findDefaultSystemOffering(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean())).thenReturn(mockSvcOfferingVO); when(mockSvcOfferingVO.getId()).thenReturn(DEFAULT_OFFERING_ID); // Execute diff --git a/server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java b/server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java index f75860b2588..5a2f12ff524 100644 --- a/server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java +++ b/server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java @@ -39,7 +39,7 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import java.io.File; @@ -118,7 +118,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); certService._accountDao = Mockito.mock(AccountDao.class); when(certService._accountDao.findByIdIncludingRemoved(anyLong())).thenReturn((AccountVO)account); @@ -175,7 +175,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); certService._accountDao = Mockito.mock(AccountDao.class); when(certService._accountDao.findByIdIncludingRemoved(anyLong())).thenReturn((AccountVO)account); @@ -234,7 +234,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); certService._accountDao = Mockito.mock(AccountDao.class); when(certService._accountDao.findByIdIncludingRemoved(anyLong())).thenReturn((AccountVO)account); @@ -284,7 +284,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); certService._accountDao = Mockito.mock(AccountDao.class); when(certService._accountDao.findByIdIncludingRemoved(anyLong())).thenReturn((AccountVO)account); @@ -331,7 +331,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -383,7 +383,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -433,7 +433,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -482,7 +482,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -525,7 +525,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -570,7 +570,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -614,7 +614,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); @@ -658,7 +658,7 @@ public class CertServiceTest { when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain); certService._sslCertDao = Mockito.mock(SslCertDao.class); - when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); + when(certService._sslCertDao.persist(ArgumentMatchers.any(SslCertVO.class))).thenReturn(new SslCertVO()); //creating the command final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn(); diff --git a/server/src/test/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceTest.java b/server/src/test/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceTest.java index 7f848191524..7cb384e8c15 100644 --- a/server/src/test/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceTest.java +++ b/server/src/test/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceTest.java @@ -23,7 +23,7 @@ import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDrive import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class OutOfBandManagementServiceTest { diff --git a/server/src/test/java/org/apache/cloudstack/privategw/AclOnPrivateGwTest.java b/server/src/test/java/org/apache/cloudstack/privategw/AclOnPrivateGwTest.java index 8fee969975a..5a3ccc79fcb 100644 --- a/server/src/test/java/org/apache/cloudstack/privategw/AclOnPrivateGwTest.java +++ b/server/src/test/java/org/apache/cloudstack/privategw/AclOnPrivateGwTest.java @@ -56,7 +56,7 @@ import org.apache.cloudstack.test.utils.SpringUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -96,7 +96,7 @@ public class AclOnPrivateGwTest { VpcService _vpcService = Mockito.mock(VpcService.class); try { - _vpcService.applyVpcPrivateGateway(Matchers.anyLong(), Matchers.anyBoolean()); + _vpcService.applyVpcPrivateGateway(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean()); } catch (ResourceUnavailableException e) { e.printStackTrace(); } catch (ConcurrentOperationException e) { @@ -111,7 +111,7 @@ public class AclOnPrivateGwTest { createPrivateGwCmd._vpcService = vpcService; try { - Mockito.when(vpcService.applyVpcPrivateGateway(Matchers.anyLong(), Matchers.anyBoolean())).thenReturn(null); + Mockito.when(vpcService.applyVpcPrivateGateway(ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean())).thenReturn(null); } catch (ResourceUnavailableException e) { e.printStackTrace(); } catch (ConcurrentOperationException e) { diff --git a/server/src/test/java/org/apache/cloudstack/region/RegionManagerTest.java b/server/src/test/java/org/apache/cloudstack/region/RegionManagerTest.java index 2c42cad4cea..4baa68d1a67 100644 --- a/server/src/test/java/org/apache/cloudstack/region/RegionManagerTest.java +++ b/server/src/test/java/org/apache/cloudstack/region/RegionManagerTest.java @@ -21,7 +21,7 @@ import com.cloud.exception.InvalidParameterValueException; import junit.framework.Assert; import org.apache.cloudstack.region.dao.RegionDao; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import javax.naming.ConfigurationException; @@ -34,7 +34,7 @@ public class RegionManagerTest { RegionManagerImpl regionMgr = new RegionManagerImpl(); RegionDao regionDao = Mockito.mock(RegionDao.class); RegionVO region = new RegionVO(2, "APAC", ""); - Mockito.when(regionDao.findByName(Matchers.anyString())).thenReturn(region); + Mockito.when(regionDao.findByName(ArgumentMatchers.anyString())).thenReturn(region); regionMgr._regionDao = regionDao; try { regionMgr.addRegion(2, "APAC", ""); diff --git a/server/src/test/java/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java b/server/src/test/java/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java index 9062b9e1f68..50d0996d9cb 100644 --- a/server/src/test/java/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java @@ -54,9 +54,9 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { diff --git a/server/src/test/java/org/apache/cloudstack/service/ServiceOfferingVOTest.java b/server/src/test/java/org/apache/cloudstack/service/ServiceOfferingVOTest.java index c42f9205eed..0a1cac35a67 100644 --- a/server/src/test/java/org/apache/cloudstack/service/ServiceOfferingVOTest.java +++ b/server/src/test/java/org/apache/cloudstack/service/ServiceOfferingVOTest.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.service; import com.cloud.service.ServiceOfferingVO; import com.cloud.vm.VirtualMachine; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -26,14 +27,20 @@ import org.mockito.MockitoAnnotations; public class ServiceOfferingVOTest { ServiceOfferingVO offeringCustom; ServiceOfferingVO offering; + private AutoCloseable closeable; @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); offeringCustom = new ServiceOfferingVO("custom", null, null, 500, 10, 10, false, "custom", false, VirtualMachine.Type.User, false); offering = new ServiceOfferingVO("normal", 1, 1000, 500, 10, 10, false, "normal", false, VirtualMachine.Type.User, false); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + // Test restoreVm when VM state not in running/stopped case @Test public void isDynamic() { diff --git a/server/src/test/java/org/apache/cloudstack/vm/schedule/VMScheduleManagerImplTest.java b/server/src/test/java/org/apache/cloudstack/vm/schedule/VMScheduleManagerImplTest.java index 3d21be54ff9..84b1c577f6a 100644 --- a/server/src/test/java/org/apache/cloudstack/vm/schedule/VMScheduleManagerImplTest.java +++ b/server/src/test/java/org/apache/cloudstack/vm/schedule/VMScheduleManagerImplTest.java @@ -36,6 +36,7 @@ import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.schedule.dao.VMScheduleDao; import org.apache.commons.lang.time.DateUtils; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -72,14 +73,21 @@ public class VMScheduleManagerImplTest { @Mock AccountManager accountManager; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Account callingAccount = Mockito.mock(Account.class); User callingUser = Mockito.mock(User.class); CallContext.register(callingUser, callingAccount); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + private void validateResponse(VMScheduleResponse response, VMSchedule vmSchedule, VirtualMachine vm) { assertNotNull(response); Assert.assertEquals(ReflectionTestUtils.getField(response, "id"), vmSchedule.getUuid()); diff --git a/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/services/console-proxy/rdpconsole/src/test/java/streamer/BaseElementTest.java b/services/console-proxy/rdpconsole/src/test/java/streamer/BaseElementTest.java index 1521d2f8b35..2acb9703576 100644 --- a/services/console-proxy/rdpconsole/src/test/java/streamer/BaseElementTest.java +++ b/services/console-proxy/rdpconsole/src/test/java/streamer/BaseElementTest.java @@ -18,7 +18,7 @@ // package streamer; -import static org.mockito.Matchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/services/console-proxy/rdpconsole/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/services/console-proxy/rdpconsole/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/services/console-proxy/rdpconsole/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/services/console-proxy/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/services/console-proxy/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/services/console-proxy/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/services/secondary-storage/controller/src/test/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerTest.java b/services/secondary-storage/controller/src/test/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerTest.java index fe67b24cac2..feae8719f27 100644 --- a/services/secondary-storage/controller/src/test/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerTest.java +++ b/services/secondary-storage/controller/src/test/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerTest.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -58,9 +59,16 @@ public class SecondaryStorageManagerTest { @InjectMocks SecondaryStorageManagerImpl _ssMgr = new SecondaryStorageManagerImpl(); + private AutoCloseable closeable; + @Before public void initMocks() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java b/services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java index 72b9f5abe19..7deab3da8eb 100644 --- a/services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java +++ b/services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java @@ -18,7 +18,7 @@ */ package org.apache.cloudstack.storage.resource; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; diff --git a/services/secondary-storage/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/services/secondary-storage/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/services/secondary-storage/server/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/utils/src/test/java/com/cloud/utils/ScriptTest.java b/utils/src/test/java/com/cloud/utils/ScriptTest.java index 12963dc2637..b5b5d16ae87 100644 --- a/utils/src/test/java/com/cloud/utils/ScriptTest.java +++ b/utils/src/test/java/com/cloud/utils/ScriptTest.java @@ -28,7 +28,7 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Ignore; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import com.cloud.utils.script.OutputInterpreter; @@ -51,7 +51,7 @@ public class ScriptTest { public void testLogger() { Assume.assumeTrue(SystemUtils.IS_OS_LINUX); Logger mock = Mockito.mock(Logger.class); - Mockito.doNothing().when(mock).debug(Matchers.any()); + Mockito.doNothing().when(mock).debug(ArgumentMatchers.any()); Script script = new Script("/bin/echo", mock); script.execute(); } @@ -80,7 +80,7 @@ public class ScriptTest { public void testExecute() { Assume.assumeTrue(SystemUtils.IS_OS_LINUX); Logger mock = Mockito.mock(Logger.class); - Mockito.doNothing().when(mock).debug(Matchers.any()); + Mockito.doNothing().when(mock).debug(ArgumentMatchers.any()); for (int i = 0; i < 100000; i++) { Script script = new Script("/bin/false", mock); script.execute(); diff --git a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java index 5da4ac96d69..1261c606de3 100644 --- a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java +++ b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java @@ -54,7 +54,7 @@ import com.googlecode.ipv6.IPv6Network; import org.junit.runner.RunWith; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) diff --git a/utils/src/test/java/com/cloud/utils/net/NetworkProtocolsTest.java b/utils/src/test/java/com/cloud/utils/net/NetworkProtocolsTest.java index 9f1780ba2e7..32b294577f6 100644 --- a/utils/src/test/java/com/cloud/utils/net/NetworkProtocolsTest.java +++ b/utils/src/test/java/com/cloud/utils/net/NetworkProtocolsTest.java @@ -23,7 +23,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) diff --git a/utils/src/test/java/com/cloud/utils/rest/BasicRestClientTest.java b/utils/src/test/java/com/cloud/utils/rest/BasicRestClientTest.java index 77c5b3de046..79b8db068cb 100644 --- a/utils/src/test/java/com/cloud/utils/rest/BasicRestClientTest.java +++ b/utils/src/test/java/com/cloud/utils/rest/BasicRestClientTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.sameInstance; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/utils/src/test/java/com/cloud/utils/rest/HttpRequestMatcher.java b/utils/src/test/java/com/cloud/utils/rest/HttpRequestMatcher.java index cf20a876484..5c87fffad66 100644 --- a/utils/src/test/java/com/cloud/utils/rest/HttpRequestMatcher.java +++ b/utils/src/test/java/com/cloud/utils/rest/HttpRequestMatcher.java @@ -19,7 +19,7 @@ package com.cloud.utils.rest; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import java.io.IOException; diff --git a/utils/src/test/java/com/cloud/utils/rest/RESTServiceConnectorTest.java b/utils/src/test/java/com/cloud/utils/rest/RESTServiceConnectorTest.java index 63add63181a..9ed594b17d5 100644 --- a/utils/src/test/java/com/cloud/utils/rest/RESTServiceConnectorTest.java +++ b/utils/src/test/java/com/cloud/utils/rest/RESTServiceConnectorTest.java @@ -22,7 +22,7 @@ package com.cloud.utils.rest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/utils/src/test/java/com/cloud/utils/security/SSLUtilsTest.java b/utils/src/test/java/com/cloud/utils/security/SSLUtilsTest.java index 625b538d7f2..0acbf4004f9 100644 --- a/utils/src/test/java/com/cloud/utils/security/SSLUtilsTest.java +++ b/utils/src/test/java/com/cloud/utils/security/SSLUtilsTest.java @@ -29,7 +29,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SSLUtilsTest { diff --git a/utils/src/test/java/com/cloud/utils/ssh/SshHelperTest.java b/utils/src/test/java/com/cloud/utils/ssh/SshHelperTest.java index 04d84435abe..61d746bc12d 100644 --- a/utils/src/test/java/com/cloud/utils/ssh/SshHelperTest.java +++ b/utils/src/test/java/com/cloud/utils/ssh/SshHelperTest.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.trilead.ssh2.ChannelCondition; import com.trilead.ssh2.Connection; diff --git a/utils/src/test/java/org/apache/cloudstack/utils/hypervisor/HypervisorUtilsTest.java b/utils/src/test/java/org/apache/cloudstack/utils/hypervisor/HypervisorUtilsTest.java index 64b6972c033..0eee5899e5c 100644 --- a/utils/src/test/java/org/apache/cloudstack/utils/hypervisor/HypervisorUtilsTest.java +++ b/utils/src/test/java/org/apache/cloudstack/utils/hypervisor/HypervisorUtilsTest.java @@ -23,7 +23,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.File; import java.io.FileWriter; diff --git a/utils/src/test/java/org/apache/cloudstack/utils/mailing/SMTPMailSenderTest.java b/utils/src/test/java/org/apache/cloudstack/utils/mailing/SMTPMailSenderTest.java index 5cce309e76e..93930e9dfd5 100644 --- a/utils/src/test/java/org/apache/cloudstack/utils/mailing/SMTPMailSenderTest.java +++ b/utils/src/test/java/org/apache/cloudstack/utils/mailing/SMTPMailSenderTest.java @@ -35,14 +35,16 @@ import junit.framework.TestCase; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.mail.EmailConstants; import org.apache.log4j.Logger; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SMTPMailSenderTest extends TestCase { @@ -63,11 +65,20 @@ public class SMTPMailSenderTest extends TestCase { private String namespace = "test"; private String enabledProtocols = "mail.smtp.ssl.protocols"; + private AutoCloseable closeable; + @Before public void before() { + closeable = MockitoAnnotations.openMocks(this); smtpMailSender = new SMTPMailSender(configsMock, namespace); } + @Override + @After + public void tearDown() throws Exception { + closeable.close(); + } + private String getConfigName(String config) { return String.format("%s.%s", namespace, config); } diff --git a/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java b/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java index 581a7d56beb..b63e8676c0a 100644 --- a/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java +++ b/utils/src/test/java/org/apache/cloudstack/utils/process/ProcessTest.java @@ -25,7 +25,7 @@ import org.joda.time.Duration; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; import java.util.concurrent.ExecutorService; diff --git a/utils/src/test/java/org/apache/cloudstack/utils/reflectiontostringbuilderutils/ReflectionToStringBuilderUtilsTest.java b/utils/src/test/java/org/apache/cloudstack/utils/reflectiontostringbuilderutils/ReflectionToStringBuilderUtilsTest.java index 48bb972b8a2..afd033c7b04 100644 --- a/utils/src/test/java/org/apache/cloudstack/utils/reflectiontostringbuilderutils/ReflectionToStringBuilderUtilsTest.java +++ b/utils/src/test/java/org/apache/cloudstack/utils/reflectiontostringbuilderutils/ReflectionToStringBuilderUtilsTest.java @@ -251,7 +251,7 @@ public class ReflectionToStringBuilderUtilsTest extends TestCase { @Test public void validateReflectOnlySelectedFieldsNullNonSelectedFieldsMustReturnNull() throws Exception{ try (MockedStatic reflectionToStringBuilderUtilsMocked = Mockito.mockStatic(ReflectionToStringBuilderUtils.class, Mockito.CALLS_REAL_METHODS)) { - reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.getNonSelectedFields(Mockito.any(), Mockito.any())).thenReturn(null); + reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.getNonSelectedFields(Mockito.any(), Mockito.any(String[].class))).thenReturn(null); TO_STRING_STYLES.forEach(style -> { String result = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(null, style, "-"); @@ -280,8 +280,8 @@ public class ReflectionToStringBuilderUtilsTest extends TestCase { String expectedResult = "test"; try (MockedStatic reflectionToStringBuilderUtilsMocked = Mockito.mockStatic(ReflectionToStringBuilderUtils.class, Mockito.CALLS_REAL_METHODS)) { - reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.getNonSelectedFields(Mockito.any(), Mockito.any())).thenReturn(classToReflectFieldsNamesArray); - reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.reflectCollection(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any())).thenReturn(expectedResult); + reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.getNonSelectedFields(Mockito.any(), Mockito.any(String[].class))).thenReturn(classToReflectFieldsNamesArray); + reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.reflectCollection(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(expectedResult); TO_STRING_STYLES.forEach(style -> { String result = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(new Object(), style, "-", fieldToRemove); @@ -323,7 +323,7 @@ public class ReflectionToStringBuilderUtilsTest extends TestCase { String expectedResult = "[test]"; try (MockedStatic reflectionToStringBuilderUtilsMocked = Mockito.mockStatic(ReflectionToStringBuilderUtils.class, Mockito.CALLS_REAL_METHODS)) { - reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.reflectOnlySelectedFields(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any())).thenReturn("test"); + reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.reflectOnlySelectedFields(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(String[].class))).thenReturn("test"); reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.isCollection(Mockito.any())).thenReturn(true); String result = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(new Object()); @@ -336,7 +336,7 @@ public class ReflectionToStringBuilderUtilsTest extends TestCase { String expectedResult = "test"; try (MockedStatic reflectionToStringBuilderUtilsMocked = Mockito.mockStatic(ReflectionToStringBuilderUtils.class, Mockito.CALLS_REAL_METHODS)) { - reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.reflectOnlySelectedFields(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any())).thenReturn(expectedResult); + reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.reflectOnlySelectedFields(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(expectedResult); reflectionToStringBuilderUtilsMocked.when(() -> ReflectionToStringBuilderUtils.isCollection(Mockito.any())).thenReturn(false); String result = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(new Object()); diff --git a/utils/src/test/java/org/apache/cloudstack/utils/volume/VirtualMachineDiskInfoTest.java b/utils/src/test/java/org/apache/cloudstack/utils/volume/VirtualMachineDiskInfoTest.java index 8b858d4c9ab..9cd60bfc0d5 100644 --- a/utils/src/test/java/org/apache/cloudstack/utils/volume/VirtualMachineDiskInfoTest.java +++ b/utils/src/test/java/org/apache/cloudstack/utils/volume/VirtualMachineDiskInfoTest.java @@ -24,7 +24,7 @@ import com.google.gson.JsonParseException; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class VirtualMachineDiskInfoTest { diff --git a/utils/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/utils/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/utils/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/vmware-base/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/vmware-base/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/vmware-base/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline