private CompletableFuture<Optional<ComposedMessageIdWithMetaData>> retrieveComposedId(CassandraId mailboxId, MessageUid uid) { return messageIdDAO.retrieve(mailboxId, uid) .thenApply(optional -> OptionalUtils.executeIfEmpty(optional, () -> LOGGER.warn("Could not retrieve message {} {}", mailboxId, uid))); }
public static Optional<Right> forRight(MailboxACL.Right right) { return OptionalUtils.executeIfEmpty( Arrays.stream(values()) .filter(jmapRight -> jmapRight.right == right) .findAny(), () -> LOGGER.warn("Non handled right '{}'", right)); }
private CompletableFuture<Optional<SimpleMailbox>> retrieveMailbox(CassandraIdAndPath idAndPath) { return retrieveMailbox(idAndPath.getCassandraId()) .thenApply(optional -> OptionalUtils.executeIfEmpty(optional, () -> LOGGER.warn("Could not retrieve mailbox {} with path {} in mailbox table.", idAndPath.getCassandraId(), idAndPath.getMailboxPath()))); }
@Test void ifEmptyShouldNotPerformOperationIfPresent() { AtomicInteger operationCounter = new AtomicInteger(0); OptionalUtils.executeIfEmpty(Optional.of("value"), operationCounter::incrementAndGet); assertThat(operationCounter.get()).isEqualTo(0); }
@Test void ifEmptyShouldPerformOperationIfEmpty() { AtomicInteger operationCounter = new AtomicInteger(0); OptionalUtils.executeIfEmpty(Optional.empty(), operationCounter::incrementAndGet); assertThat(operationCounter.get()).isEqualTo(1); }
@Test public void ifEmptyShouldPerformOperationIfEmpty() { AtomicInteger operationCounter = new AtomicInteger(0); OptionalUtils.executeIfEmpty(Optional.empty(), operationCounter::incrementAndGet); assertThat(operationCounter.get()).isEqualTo(1); }
@Test public void ifEmptyShouldNotPerformOperationIfPresent() { AtomicInteger operationCounter = new AtomicInteger(0); OptionalUtils.executeIfEmpty(Optional.of("value"), operationCounter::incrementAndGet); assertThat(operationCounter.get()).isEqualTo(0); }
@Test public void ifEmptyShouldPreserveValueOfPresentOptionals() { String value = "value"; Optional<String> expected = OptionalUtils.executeIfEmpty(Optional.of(value), () -> { }); assertThat(expected).contains(value); }
@Test void ifEmptyShouldPreserveValueOfPresentOptionals() { String value = "value"; Optional<String> expected = OptionalUtils.executeIfEmpty(Optional.of(value), () -> { }); assertThat(expected).contains(value); }
@Test void ifEmptyShouldPreserveValueOfEmptyOptionals() { Optional<Object> expected = OptionalUtils.executeIfEmpty(Optional.empty(), () -> { }); assertThat(expected).isEmpty(); }
@Test public void ifEmptyShouldPreserveValueOfEmptyOptionals() { Optional<Object> expected = OptionalUtils.executeIfEmpty(Optional.empty(), () -> { }); assertThat(expected).isEmpty(); }