@Test public void numberOfViews() { StatisticDocument statisticDocument1 = new StatisticDocument(); statisticDocument1.setId("Stat1"); statisticDocument1.setEventType(EventType.SHORTENER_VIEWED); StatisticDocument statisticDocument2 = new StatisticDocument(); statisticDocument2.setId("Stat2"); statisticDocument2.setEventType(EventType.SHORTENER_VIEWED); Mockito.when(repository.findByEventType(any(EventType.class))).thenReturn(Flux.just (statisticDocument1, statisticDocument2)); Mono<Long> source = stub.eventsCount(EventType.SHORTENER_VIEWED); StepVerifier.create(source) .expectNext(2L) .expectComplete().verify(); }
@Override public Mono<Long> eventsCount(EventType type) { return repository.findByEventType(type) .map(r -> 1) .reduce(0L, Long::sum); }
StatisticServiceImpl implements StatisticService { @Override public Mono<Long> eventsCount(EventType type) { return repository.findByEventType(type) .map(r -> 1) .reduce(0L, Long::sum); } }
StatisticServiceImpl implements StatisticService { @Override public Mono<Long> eventsCount(EventType type) { return repository.findByEventType(type) .map(r -> 1) .reduce(0L, Long::sum); } @Autowired  StatisticServiceImpl(StatisticRepository repository,
                              ShortenerSubscriber shortenerSubscriber,
                              UserSubscriber userSubscriber); }
StatisticServiceImpl implements StatisticService { @Override public Mono<Long> eventsCount(EventType type) { return repository.findByEventType(type) .map(r -> 1) .reduce(0L, Long::sum); } @Autowired  StatisticServiceImpl(StatisticRepository repository,
                              ShortenerSubscriber shortenerSubscriber,
                              UserSubscriber userSubscriber); void subscribeToEvents(); @Override Flux<StatisticDocument> getAll(); @Override Mono<Long> eventsCount(EventType type); }
StatisticServiceImpl implements StatisticService { @Override public Mono<Long> eventsCount(EventType type) { return repository.findByEventType(type) .map(r -> 1) .reduce(0L, Long::sum); } @Autowired  StatisticServiceImpl(StatisticRepository repository,
                              ShortenerSubscriber shortenerSubscriber,
                              UserSubscriber userSubscriber); void subscribeToEvents(); @Override Flux<StatisticDocument> getAll(); @Override Mono<Long> eventsCount(EventType type);  }