SW360ComponentClientAdapterAsyncImpl implements SW360ComponentClientAdapterAsync { @Override public CompletableFuture<Optional<SW360Component>> getComponentById(String componentId) { return optionalFuture(getComponentClient().getComponent(componentId)); } SW360ComponentClientAdapterAsyncImpl(SW360ComponentClient client); @Override SW360ComponentClient getComponentClient(); @Override CompletableFuture<SW360Component> createComponent(SW360Component component); @Override CompletableFuture<Optional<SW360Component>> getComponentById(String componentId); @Override CompletableFuture<Optional<SW360Component>> getComponentByName(String componentName); @Override CompletableFuture<List<SW360SparseComponent>> search(ComponentSearchParams searchParams); @Override CompletableFuture<PagingResult<SW360SparseComponent>> searchWithPaging(ComponentSearchParams searchParams); @Override CompletableFuture<SW360Component> updateComponent(SW360Component component); @Override CompletableFuture<MultiStatusResponse> deleteComponents(Collection<String> idsToDelete); @Override CompletableFuture<Void> deleteComponent(String componentId);  }
@Test public void testGetComponentById() { when(componentClient.getComponent(COMPONENT_ID)) .thenReturn(CompletableFuture.completedFuture(component)); Optional<SW360Component> componentById = block(componentClientAdapter.getComponentById(COMPONENT_ID)); assertThat(componentById).isPresent(); assertThat(componentById).hasValue(component); verify(componentClient).getComponent(COMPONENT_ID); }
@Test public void testGetComponentByIdNotFound() { CompletableFuture<SW360Component> failedFuture = new CompletableFuture<>(); failedFuture.completeExceptionally(new FailedRequestException("tag", HttpConstants.STATUS_ERR_NOT_FOUND)); when(componentClient.getComponent(COMPONENT_ID)).thenReturn(failedFuture); Optional<SW360Component> componentById = block(componentClientAdapter.getComponentById(COMPONENT_ID)); assertThat(componentById).isNotPresent(); }