public static <T> ValuePatch<T> ofOptional(Optional<T> value) { Preconditions.checkNotNull(value); return value.map(ValuePatch::modifyTo) .orElse(ValuePatch.remove()); }
public static <T> ValuePatch<T> ofOptional(Optional<T> value) { Preconditions.checkNotNull(value); return value.map(ValuePatch::modifyTo) .orElse(ValuePatch.remove()); }
public static <T> ValuePatch<T> ofOptional(Optional<T> value) { Preconditions.checkNotNull(value); return value.map(ValuePatch::modifyTo) .orElse(ValuePatch.remove()); }
@Test void removedShouldNotBeModified() { assertThat(ValuePatch.<Integer>remove().isModified()).isFalse(); }
@Test public void removedShouldNotBeModified() { assertThat(ValuePatch.<Integer>remove().isModified()).isFalse(); }
@Test void ofOptionalShouldBeEquivalentToRemoveWhenEmpty() { assertThat(ValuePatch.ofOptional(Optional.empty())).isEqualTo(ValuePatch.remove()); }
@Test public void ofOptionalShouldBeEquivalentToRemoveWhenEmpty() { assertThat(ValuePatch.ofOptional(Optional.empty())).isEqualTo(ValuePatch.remove()); }
@Test public void ofNullableShouldBeEquivalentToRemoveWhenNullParameter() { assertThat(ValuePatch.<Integer>ofNullable(null)).isEqualTo(ValuePatch.<Integer>remove()); }
@Test void removeShouldNotBeKept() { assertThat(ValuePatch.<Integer>remove().isKept()).isFalse(); }
@Test void ofNullableShouldBeEquivalentToRemoveWhenNullParameter() { assertThat(ValuePatch.<Integer>ofNullable(null)).isEqualTo(ValuePatch.<Integer>remove()); }
@Test public void removeShouldBeRemoved() { assertThat(ValuePatch.<Integer>remove().isRemoved()).isTrue(); }
@Test void removeShouldBeRemoved() { assertThat(ValuePatch.<Integer>remove().isRemoved()).isTrue(); }
@Test void mapNotKeptToValueShouldTransformRemoved() { assertThat( ValuePatch.<Integer>remove() .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) .contains(REPLACEMENT_VALUE); }
@Test public void mapNotKeptToValueShouldTransformRemoved() { assertThat( ValuePatch.<Integer>remove() .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) .contains(REPLACEMENT_VALUE); }
@Test void notKeptOrElseShouldReturnEmptyWhenRemoved() { assertThat(ValuePatch.<Integer>remove().notKeptOrElse(REPLACEMENT)).isEqualTo(Optional.empty()); }
@Test public void toOptionalShouldReturnEmptyWhenRemoved() { assertThat(ValuePatch.<Integer>remove().toOptional()).isEqualTo(Optional.empty()); }
@Test public void notKeptOrElseShouldReturnEmptyWhenRemoved() { assertThat(ValuePatch.<Integer>remove().notKeptOrElse(REPLACEMENT)).isEqualTo(Optional.empty()); }
@Test void toOptionalShouldReturnEmptyWhenRemoved() { assertThat(ValuePatch.<Integer>remove().toOptional()).isEqualTo(Optional.empty()); }
@Test void getOrElseShouldReturnNullWhenRemovedAndNullSpecified() { assertThat(ValuePatch.<Integer>remove().getOrElse(null)).isNull(); }
@Test public void getOrElseShouldReturnNullWhenRemovedAndNullSpecified() { assertThat(ValuePatch.<Integer>remove().getOrElse(null)).isNull(); }