### Question:
MessageReaderAdapter implements BeekeeperEventReader { @Override public Optional<BeekeeperEvent> read() { Optional<MessageEvent> messageEvent = delegate.read(); if (messageEvent.isEmpty()) { return Optional.empty(); } MessageEvent message = messageEvent.get(); List<HousekeepingEntity> housekeepingEntities = handlers.parallelStream() .map(eventHandler -> eventHandler.handleMessage(message)) .flatMap(Collection::stream) .collect(Collectors.toList()); if (housekeepingEntities.size() <= 0) { delete(new BeekeeperEvent(Collections.emptyList(), message)); return Optional.empty(); } return Optional.of(new BeekeeperEvent(housekeepingEntities, message)); } MessageReaderAdapter(MessageReader delegate,
      List<MessageEventHandler> handlers); @Override Optional<BeekeeperEvent> read(); @Override void delete(BeekeeperEvent beekeeperEvent); @Override void close();  }### Answer:
@Test public void typicalRead() { when(delegate.read()).thenReturn(Optional.of(messageEvent)); when(unreferencedEventHandler.handleMessage(messageEvent)).thenReturn(List.of(path)); when(expiredEventHandler.handleMessage(messageEvent)).thenReturn(List.of(metadata)); Optional<BeekeeperEvent> read = messageReaderAdapter.read(); assertThat(read).isPresent(); assertThat(read.get().getMessageEvent()).isEqualTo(messageEvent); assertThat(read.get().getHousekeepingEntities()).isEqualTo(housekeepingEntities); }
@Test public void typicalEmptyRead() { when(delegate.read()).thenReturn(Optional.empty()); Optional<BeekeeperEvent> read = messageReaderAdapter.read(); assertThat(read).isEmpty(); }