@Test public void testCreateSuccess() { UserVmService userVmService = Mockito.mock(UserVmService.class); UserVm uservm = Mockito.mock(UserVm.class); try { Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(uservm); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } scaleVMCmd._userVmService = userVmService; responseGenerator = Mockito.mock(ResponseGenerator.class); UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class); List<UserVmResponse> responseList = new ArrayList<UserVmResponse>(); responseList.add(userVmResponse); Mockito.when(responseGenerator.createUserVmResponse("virtualmachine", uservm)) .thenReturn(responseList); scaleVMCmd._responseGenerator = responseGenerator; scaleVMCmd.execute(); }
@Test public void testCreateFailure() { UserVmService userVmService = Mockito.mock(UserVmService.class); try { UserVm uservm = Mockito.mock(UserVm.class); Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(null); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } scaleVMCmd._userVmService = userVmService; try { scaleVMCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to scale vm", exception.getDescription()); } }