### Question:
VirtualMachineToStatus implements Function<VirtualMachine, StatusAndBackendStatus> { @Override public StatusAndBackendStatus apply(VirtualMachine virtualMachine) { String resourceGroup = extractResourceGroup(virtualMachine.id()); ProvisioningState provisioningState = virtualMachine.properties().provisioningState(); NodeMetadata.Status status = PROVISIONINGSTATE_TO_NODESTATUS.apply(provisioningState); String backendStatus = provisioningState.name(); if (ProvisioningState.SUCCEEDED.equals(provisioningState)) { VirtualMachineInstance instanceDetails = api.getVirtualMachineApi(resourceGroup).getInstanceDetails( virtualMachine.name()); if (instanceDetails != null && instanceDetails.powerState() != null) { status = POWERSTATE_TO_NODESTATUS.apply(instanceDetails.powerState()); backendStatus = Joiner.on(',').join(transform(instanceDetails.statuses(), new Function<Status, String>() { @Override public String apply(Status input) { return input.code(); } })); } else { status = NodeMetadata.Status.PENDING; } } return StatusAndBackendStatus.create(status, backendStatus); } @Inject  VirtualMachineToStatus(AzureComputeApi api); @Override StatusAndBackendStatus apply(VirtualMachine virtualMachine);  }### Answer:
@Test public void testPendingWhenInstanceNotFound() { AzureComputeApi api = createMock(AzureComputeApi.class); VirtualMachineApi vmApi = createMock(VirtualMachineApi.class); VirtualMachine vm = createMock(VirtualMachine.class); VirtualMachineProperties props = createMock(VirtualMachineProperties.class); expect(vm.id()).andReturn("/resourceGroups/test/virtualMachines/vm"); expect(vm.properties()).andReturn(props); expect(vm.name()).andReturn("vm"); expect(props.provisioningState()).andReturn(ProvisioningState.SUCCEEDED); expect(api.getVirtualMachineApi("test")).andReturn(vmApi); expect(vmApi.getInstanceDetails("vm")).andReturn(null); replay(props, vm, vmApi, api); assertEquals(new VirtualMachineToStatus(api).apply(vm).status(), NodeMetadata.Status.PENDING); verify(props, vm, vmApi, api); }
@Test public void testPendingWhenInstanceHasNoPowerState() { AzureComputeApi api = createMock(AzureComputeApi.class); VirtualMachineApi vmApi = createMock(VirtualMachineApi.class); VirtualMachine vm = createMock(VirtualMachine.class); VirtualMachineProperties props = createMock(VirtualMachineProperties.class); VirtualMachineInstance instance = createMock(VirtualMachineInstance.class); expect(vm.id()).andReturn("/resourceGroups/test/virtualMachines/vm"); expect(vm.properties()).andReturn(props); expect(vm.name()).andReturn("vm"); expect(props.provisioningState()).andReturn(ProvisioningState.SUCCEEDED); expect(api.getVirtualMachineApi("test")).andReturn(vmApi); expect(vmApi.getInstanceDetails("vm")).andReturn(instance); expect(instance.powerState()).andReturn(null); replay(props, vm, vmApi, api, instance); assertEquals(new VirtualMachineToStatus(api).apply(vm).status(), NodeMetadata.Status.PENDING); verify(props, vm, vmApi, api, instance); }