PublisherCache { public Mono<O> lookup(I input) { return Mono.justOrEmpty(cache.get(input)) .doOnNext(i -> print("cache hit for key '%s'", input)) .otherwiseIfEmpty(transformer.apply(input) .doOnNext(o -> cache.put(input, o)) ); } PublisherCache(Function<I, Mono<O>> transformer);  PublisherCache(Function<I, Mono<O>> transformer, int cacheSize); Mono<O> lookup(I input);  }
@Test public void shouldNotExecutePublisherWhenNotSubscribing() { cache.lookup(0); Assert.assertEquals(0, counter.get()); }