SfcGeniusReaderAbstract { protected <T extends DataObject> CompletableFuture<T> doRead(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> instanceIdentifier) { return SfcGeniusUtils.toCompletableFuture( readTransaction.read(logicalDatastoreType, instanceIdentifier), executor ).thenApply(optional -> { if (optional.isPresent()) { return optional.get(); } else { throw new SfcGeniusRuntimeException( new NoSuchElementException("Data store object not found: " + instanceIdentifier)); } }); } protected  SfcGeniusReaderAbstract(ReadTransaction readTransaction, Executor executor);   }
@Test public void read() throws Exception { when(readTransaction.read(LogicalDatastoreType.CONFIGURATION, null)) .thenReturn(Futures.immediateCheckedFuture(Optional.of(dataObject))); CompletableFuture completableFuture = reader.doRead(LogicalDatastoreType.CONFIGURATION, null); verify(executor).execute(runnableCaptor.capture()); runnableCaptor.getValue().run(); assertThat(completableFuture.get(), is(dataObject)); }
@Test public void readNotFound() throws Exception { when(readTransaction.read(LogicalDatastoreType.CONFIGURATION, null)) .thenReturn(Futures.immediateCheckedFuture(Optional.absent())); CompletableFuture completableFuture = reader.doRead(LogicalDatastoreType.CONFIGURATION, null); verify(executor).execute(runnableCaptor.capture()); runnableCaptor.getValue().run(); assertThat(completableFuture.isCompletedExceptionally(), is(true)); try { completableFuture.join(); } catch (Exception e) { assertThat(e.getCause(), is(instanceOf(SfcGeniusRuntimeException.class))); } }