InternalRxResult implements RxResult { synchronized CompletionStage<RxResultCursor> initCursorFuture() { if ( cursorFuture != null ) { return cursorFuture; } cursorFuture = cursorFutureSupplier.get(); cursorFutureSupplier = null; return this.cursorFuture; } InternalRxResult(Supplier<CompletionStage<RxResultCursor>> cursorFuture ); @Override Publisher<List<String>> keys(); @Override Publisher<Record> records(); @Override Publisher<ResultSummary> consume();  }
@Test void shouldInitCursorFuture() { RxResultCursor cursor = mock( RxResultCursorImpl.class ); InternalRxResult rxResult = newRxResult( cursor ); CompletableFuture<RxResultCursor> cursorFuture = rxResult.initCursorFuture().toCompletableFuture(); assertTrue( cursorFuture.isDone() ); assertThat( Futures.getNow( cursorFuture ), equalTo( cursor ) ); }
@Test void shouldInitCursorFutureWithFailedCursor() { RuntimeException error = new RuntimeException( "Failed to obtain cursor probably due to connection problem" ); InternalRxResult rxResult = newRxResult( error ); CompletableFuture<RxResultCursor> cursorFuture = rxResult.initCursorFuture().toCompletableFuture(); assertTrue( cursorFuture.isDone() ); RuntimeException actualError = assertThrows( RuntimeException.class, () -> Futures.getNow( cursorFuture ) ); assertThat( actualError.getCause(), equalTo( error ) ); }