SfcGeniusReaderAbstract { protected <T extends DataObject> CompletableFuture<Optional<T>> doReadOptional( LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> instanceIdentifier) { return SfcGeniusUtils.toCompletableFuture( readTransaction.read(logicalDatastoreType, instanceIdentifier), executor).thenApply( optional -> { if (optional.isPresent()) { return Optional.of(optional.get()); } else { return Optional.empty(); } }); } protected  SfcGeniusReaderAbstract(ReadTransaction readTransaction, Executor executor);   }
@Test public void readOptional() throws Exception { when(readTransaction.read(LogicalDatastoreType.CONFIGURATION, null)) .thenReturn(Futures.immediateCheckedFuture(Optional.of(dataObject))); CompletableFuture<java.util.Optional<DataObject>> completableFuture = reader.doReadOptional( LogicalDatastoreType.CONFIGURATION, null); assertFalse(completableFuture.isDone()); verify(executor).execute(runnableCaptor.capture()); runnableCaptor.getValue().run(); assertTrue(completableFuture.isDone()); assertEquals(dataObject, completableFuture.get().get()); }
@Test public void readOptionalNotFound() throws Exception { when(readTransaction.read(LogicalDatastoreType.CONFIGURATION, null)) .thenReturn(Futures.immediateCheckedFuture(Optional.absent())); CompletableFuture<java.util.Optional<DataObject>> completableFuture = reader.doReadOptional( LogicalDatastoreType.CONFIGURATION, null); assertFalse(completableFuture.isDone()); verify(executor).execute(runnableCaptor.capture()); runnableCaptor.getValue().run(); assertTrue(completableFuture.isDone()); assertFalse(completableFuture.get().isPresent()); }