### Question:
RuntimeServiceImpl implements RuntimeService { @Override public RuntimeListItem getRuntimeItem(final PipelineExecutionTraceKey pipelineExecutionTraceKey) { checkNotNull("pipelineExecutionTraceKey", pipelineExecutionTraceKey); final RuntimeQuery query = RuntimeQueryBuilder.newInstance() .withPipelineExecutionId(pipelineExecutionTraceKey.getId()) .build(); return buildRuntimeQueryResult(runtimeProvisioningService.executeQuery(query)).stream() .findFirst() .orElse(null); } RuntimeServiceImpl(); @Inject  RuntimeServiceImpl(final RuntimeProvisioningServiceBackend runtimeProvisioningService,
                              final PipelineServiceBackend pipelineService,
                              final ProviderService providerService,
                              final Event<RuntimeChangeEvent> runtimeChangeEvent,
                              final Event<PipelineExecutionChangeEvent> pipelineExecutionChangeEvent); @Override Collection<RuntimeListItem> getRuntimeItems(final ProviderKey providerKey); @Override RuntimeListItem getRuntimeItem(final PipelineExecutionTraceKey pipelineExecutionTraceKey); @Override RuntimeListItem getRuntimeItem(final RuntimeKey runtimeKey); @Override Collection<PipelineKey> getPipelines(final ProviderTypeKey providerTypeKey); @Override PipelineExecutionTraceKey createRuntime(final ProviderKey providerKey,
                                                   final String runtimeName,
                                                   final PipelineKey pipelineKey,
                                                   final Map<String, String> params); @Override void stopPipelineExecution(final PipelineExecutionTraceKey pipelineExecutionTraceKey); @Override void deletePipelineExecution(final PipelineExecutionTraceKey pipelineExecutionTraceKey); @Override void stopRuntime(final RuntimeKey runtimeKey); @Override void startRuntime(final RuntimeKey runtimeKey); @Override void deleteRuntime(final RuntimeKey runtimeKey,
                              final boolean forced);  }### Answer:
@Test public void getRuntimeItemByPipelineExecutionKeyExisting() { PipelineExecutionTraceKey traceKey = new PipelineExecutionTraceKey(PIPELINE_EXECUTION_ID); List<RuntimeQueryResultItem> singleResult = mockRuntimeQueryResultItemList(1); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem expectedItem = buildExpectedResult(singleResult).iterator().next(); RuntimeListItem result = service.getRuntimeItem(traceKey); assertEquals(expectedItem, result); }
@Test public void getRuntimeItemByPipelineExecutionKeyNotExisting() { PipelineExecutionTraceKey traceKey = new PipelineExecutionTraceKey(PIPELINE_EXECUTION_ID); List<RuntimeQueryResultItem> singleResult = new ArrayList<>(); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem result = service.getRuntimeItem(traceKey); assertNull(result); }
@Test public void getRuntimeItemByRuntimeKeyExisting() { ProviderKey providerKey = mock(ProviderKey.class); RuntimeKey runtimeKey = new RuntimeKey(providerKey, RUNTIME_ID); List<RuntimeQueryResultItem> singleResult = mockRuntimeQueryResultItemList(1); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem expectedItem = buildExpectedResult(singleResult).iterator().next(); RuntimeListItem result = service.getRuntimeItem(runtimeKey); assertEquals(expectedItem, result); }
@Test public void getRuntimeItemByRuntimeKeyNotExisting() { ProviderKey providerKey = mock(ProviderKey.class); RuntimeKey runtimeKey = new RuntimeKey(providerKey, RUNTIME_ID); List<RuntimeQueryResultItem> singleResult = new ArrayList<>(); when(runtimeProvisioningService.executeQuery(any(RuntimeQuery.class))).thenReturn(singleResult); RuntimeListItem result = service.getRuntimeItem(runtimeKey); assertNull(result); }