MailLoader { Mono<MailWithEnqueueId> load(MailReferenceDTO dto) { return Mono.fromCallable(() -> dto.toMailReference(blobIdFactory)) .flatMap(mailReference -> buildMail(mailReference) .map(mail -> new MailWithEnqueueId( mailReference.getEnqueueId(), mail, mailReference.getPartsId()))); } MailLoader(Store<MimeMessage, MimeMessagePartsId> mimeMessageStore, BlobId.Factory blobIdFactory);   }
@Test void storeExceptionShouldBePropagated() { Store<MimeMessage, MimeMessagePartsId> store = mock(Store.class); when(store.read(any())).thenReturn(Mono.error(new RuntimeException("Cassandra problem"))); MailReferenceDTO dto = mock(MailReferenceDTO.class); when(dto.toMailReference(any())).thenReturn(mock(MailReference.class)); MailLoader loader = new MailLoader(store, new HashBlobId.Factory()); String result = loader.load(dto) .thenReturn("continued") .onErrorResume(RuntimeException.class, e -> Mono.just("caught")) .block(); assertThat(result).isEqualTo("caught"); }