Capture values

There are times when we are unable to assert values directly. In such test scenarios, we usually capture the invoked values and then assert them separately. Reactor provides a recordWith API to capture values generated by the publisher under test. This method takes a Supplier function, which is invoked in order to instantiate a Collection for storing values. The recorder collection can then be asserted using the expectRecordedMatches method:

@Test    public void testRecordWith() throws Exception {        Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,                Long>of(0L, 1L), (state, sink) -> {          //   Removed for Brevity     });        StepVerifier.create(fibonacciGenerator, Long.MAX_VALUE)                .recordWith(() -> new ArrayList<>()) .thenConsumeWhile(x ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.