Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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 {
Expand All @@ -65,9 +65,11 @@ public class AddObjectStoragePoolCmdTest {

Map<String, String> 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);
Expand All @@ -81,14 +83,15 @@ public void setUp() throws Exception {
@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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ 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;
}

@After
public void tearDown() throws Exception {
CallContext.unregister();
closeable.close();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
public class FindStoragePoolsForMigrationCmdTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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());
Expand All @@ -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;
Expand All @@ -70,13 +72,14 @@ public void setUp() throws Exception {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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;
Expand Down Expand Up @@ -57,7 +57,7 @@ public Long getId() {
@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 {
Expand All @@ -74,9 +74,9 @@ public void testGetEntityOwnerIdForProject() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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;
Expand Down Expand Up @@ -101,9 +101,9 @@ public void testGetEntityOwnerIdForProject() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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;
Expand Down Expand Up @@ -59,7 +59,7 @@ public void testCreateSuccess() throws ResourceAllocationException, ResourceUnav
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;
Expand All @@ -79,7 +79,7 @@ public void testCreateFailure() throws ResourceAllocationException, ResourceUnav
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;
Expand All @@ -98,7 +98,7 @@ public void testRemoveIpFromVmNicSuccess() throws ResourceAllocationException, R
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();
Expand All @@ -109,7 +109,7 @@ public void testRemoveIpFromVmNicFailure() throws InsufficientAddressCapacityExc
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testCreateProviderToPhysicalNetworkSuccess() {
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 {
Expand All @@ -103,7 +103,7 @@ public void testCreateProviderToPhysicalNetworkFailure() throws ResourceAllocati
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


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;

Expand Down Expand Up @@ -86,7 +86,7 @@ public void testExecuteForNullResult() throws Exception {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testCreateFailure() {

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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -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();
}

/**
Expand Down
Loading