### Question:
InstanceStateHandler implements CloudPlatformEventHandler<GetInstancesStateRequest> { @Override public void accept(Event<GetInstancesStateRequest> event) { LOGGER.debug("Received event: {}", event); GetInstancesStateRequest<GetInstancesStateResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); GetInstancesStateResult result; try { List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses( request.getCloudCredential(), cloudContext, request.getInstances()); result = new GetInstancesStateResult(request.getResourceId(), instanceStatuses); } catch (CloudOperationNotSupportedException e) { List<CloudVmInstanceStatus> unknownStatuses = request.getInstances().stream() .map(instance -> new CloudVmInstanceStatus(instance, InstanceStatus.UNKNOWN)) .collect(Collectors.toList()); result = new GetInstancesStateResult(request.getResourceId(), unknownStatuses); } catch (RuntimeException e) { result = new GetInstancesStateResult("Instance state synchronizing failed", e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }  @Override Class<GetInstancesStateRequest> type(); @Override void accept(Event<GetInstancesStateRequest> event);  }### Answer:
@Test public void returnsUnknownStatusWhenUnsupported() { when(instanceStateQuery.getCloudVmInstanceStatuses(any(), any(), eq(instances))) .thenThrow(new CloudOperationNotSupportedException("No check on mock cloud")); subject.accept(event); verifyResult(new GetInstancesStateResult(request.getResourceId(), allInstancesInStatus(InstanceStatus.UNKNOWN))); }
@Test public void returnsErrorWhenFailsToSync() { String message = "Some error happened"; CloudConnectorException exception = new CloudConnectorException(message); when(instanceStateQuery.getCloudVmInstanceStatuses(any(), any(), eq(instances))) .thenThrow(exception); subject.accept(event); verifyResult(new GetInstancesStateResult("some message", exception, request.getResourceId())); }
@Test public void handlesInstanceStatusWhenAvailable() { List<CloudVmInstanceStatus> allStarted = allInstancesInStatus(InstanceStatus.STARTED); when(instanceStateQuery.getCloudVmInstanceStatuses(any(), any(), eq(instances))) .thenReturn(allStarted); subject.accept(event); verifyResult(new GetInstancesStateResult(request.getResourceId(), allStarted)); }