JAMES-1781 Rename PatchedValue to ValuePatch
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5cfe856b Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5cfe856b Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5cfe856b Branch: refs/heads/master Commit: 5cfe856b391e8188e1a62c68406d0bc5783bfe15 Parents: 560f062 Author: Benoit Tellier <[email protected]> Authored: Tue Sep 27 14:35:48 2016 +0200 Committer: Benoit Tellier <[email protected]> Committed: Thu Sep 29 12:51:00 2016 +0200 ---------------------------------------------------------------------- .../org/apache/james/util/PatchedValue.java | 125 ----------- .../java/org/apache/james/util/ValuePatch.java | 125 +++++++++++ .../org/apache/james/util/PatchedValueTest.java | 220 ------------------- .../org/apache/james/util/ValuePatchTest.java | 220 +++++++++++++++++++ .../vacation/CassandraVacationDAO.java | 10 +- .../james/jmap/api/vacation/VacationPatch.java | 80 +++---- .../AbstractVacationRepositoryTest.java | 12 +- .../jmap/api/vacation/VacationPatchTest.java | 66 +++--- .../integration/SetVacationResponseTest.java | 8 +- .../james/jmap/model/VacationResponse.java | 64 +++--- 10 files changed, 464 insertions(+), 466 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/container/util-java8/src/main/java/org/apache/james/util/PatchedValue.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/PatchedValue.java b/server/container/util-java8/src/main/java/org/apache/james/util/PatchedValue.java deleted file mode 100644 index 438e27a..0000000 --- a/server/container/util-java8/src/main/java/org/apache/james/util/PatchedValue.java +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.util; - -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Function; - -import com.google.common.base.Preconditions; - -public class PatchedValue<T> { - - private enum State { - KEEP, - REMOVE, - MODIFY - } - - public static <T> PatchedValue<T> modifyTo(T value) { - Preconditions.checkNotNull(value); - return new PatchedValue<>(value, State.MODIFY); - } - - public static <T> PatchedValue<T> ofNullable(T value) { - return ofOptional(Optional.ofNullable(value)); - } - - public static <T> PatchedValue<T> ofOptional(Optional<T> value) { - Preconditions.checkNotNull(value); - return value.map(PatchedValue::modifyTo) - .orElse(PatchedValue.remove()); - } - - public static <T> PatchedValue<T> remove() { - return new PatchedValue<>(null, State.REMOVE); - } - - public static <T> PatchedValue<T> keep() { - return new PatchedValue<>(null, State.KEEP); - } - - private final T value; - private final State state; - - private PatchedValue(T value, State state) { - this.value = value; - this.state = state; - } - - public boolean isRemoved() { - return state == State.REMOVE; - } - - public boolean isModified() { - return state == State.MODIFY; - } - - public boolean isKept() { - return state == State.KEEP; - } - - public <S> Optional<S> mapNotKeptToOptional(Function<Optional<T>, S> updateTransformation) { - if (isKept()) { - return Optional.empty(); - } - return Optional.of(updateTransformation.apply(Optional.ofNullable(value))); - } - - public T get() { - if (isModified()) { - return value; - } else { - throw new NoSuchElementException(); - } - } - - public Optional<T> notKeptOrElse(Optional<T> replacement) { - if (isKept()) { - return replacement; - } - return Optional.ofNullable(value); - } - - public Optional<T> toOptional() { - return Optional.ofNullable(value); - } - - public T getOrElse(T replacement) { - return toOptional().orElse(replacement); - } - - @Override - public boolean equals(Object o) { - if (o instanceof PatchedValue) { - PatchedValue<?> that = (PatchedValue<?>) o; - return Objects.equals(this.value, that.value) && - Objects.equals(this.state, that.state); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hash(value, state); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java b/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java new file mode 100644 index 0000000..5c3d01a --- /dev/null +++ b/server/container/util-java8/src/main/java/org/apache/james/util/ValuePatch.java @@ -0,0 +1,125 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.util; + +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; + +import com.google.common.base.Preconditions; + +public class ValuePatch<T> { + + private enum State { + KEEP, + REMOVE, + MODIFY + } + + public static <T> ValuePatch<T> modifyTo(T value) { + Preconditions.checkNotNull(value); + return new ValuePatch<>(value, State.MODIFY); + } + + public static <T> ValuePatch<T> ofNullable(T value) { + return ofOptional(Optional.ofNullable(value)); + } + + 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> remove() { + return new ValuePatch<>(null, State.REMOVE); + } + + public static <T> ValuePatch<T> keep() { + return new ValuePatch<>(null, State.KEEP); + } + + private final T value; + private final State state; + + private ValuePatch(T value, State state) { + this.value = value; + this.state = state; + } + + public boolean isRemoved() { + return state == State.REMOVE; + } + + public boolean isModified() { + return state == State.MODIFY; + } + + public boolean isKept() { + return state == State.KEEP; + } + + public <S> Optional<S> mapNotKeptToOptional(Function<Optional<T>, S> updateTransformation) { + if (isKept()) { + return Optional.empty(); + } + return Optional.of(updateTransformation.apply(Optional.ofNullable(value))); + } + + public T get() { + if (isModified()) { + return value; + } else { + throw new NoSuchElementException(); + } + } + + public Optional<T> notKeptOrElse(Optional<T> replacement) { + if (isKept()) { + return replacement; + } + return Optional.ofNullable(value); + } + + public Optional<T> toOptional() { + return Optional.ofNullable(value); + } + + public T getOrElse(T replacement) { + return toOptional().orElse(replacement); + } + + @Override + public boolean equals(Object o) { + if (o instanceof ValuePatch) { + ValuePatch<?> that = (ValuePatch<?>) o; + return Objects.equals(this.value, that.value) && + Objects.equals(this.state, that.state); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hash(value, state); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/container/util-java8/src/test/java/org/apache/james/util/PatchedValueTest.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/PatchedValueTest.java b/server/container/util-java8/src/test/java/org/apache/james/util/PatchedValueTest.java deleted file mode 100644 index 4929f6d..0000000 --- a/server/container/util-java8/src/test/java/org/apache/james/util/PatchedValueTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy modifyTo the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.util; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.util.NoSuchElementException; -import java.util.Optional; - -import org.junit.Test; - -public class PatchedValueTest { - - public static final int REPLACEMENT_VALUE = 24; - public static final Optional<Integer> REPLACEMENT = Optional.of(REPLACEMENT_VALUE); - public static final int VALUE = 12; - public static final Optional<Integer> OPTIONAL_OF_VALUE = Optional.of(VALUE); - - @Test - public void keepShouldProduceKeptValues() { - assertThat(PatchedValue.<Integer>keep().isKept()).isTrue(); - } - - @Test - public void keepShouldThrowOnGet() { - assertThatThrownBy(() -> PatchedValue.<Integer>keep().get()).isInstanceOf(NoSuchElementException.class); - } - - @Test - public void keepShouldNotBeModified() { - assertThat(PatchedValue.<Integer>keep().isModified()).isFalse(); - } - - @Test - public void keepShouldNotBeRemoved() { - assertThat(PatchedValue.<Integer>keep().isRemoved()).isFalse(); - } - - @Test - public void removeShouldNotBeKept() { - assertThat(PatchedValue.<Integer>remove().isKept()).isFalse(); - } - - @Test - public void removeShouldBeRemoved() { - assertThat(PatchedValue.<Integer>remove().isRemoved()).isTrue(); - } - - @Test - public void removedShouldNotBeModified() { - assertThat(PatchedValue.<Integer>remove().isModified()).isFalse(); - } - - @Test - public void removeShouldThrowOnGet() { - assertThatThrownBy(() -> PatchedValue.<Integer>remove().get()).isInstanceOf(NoSuchElementException.class); - } - - @Test - public void ofNullableShouldBeEquivalentToRemoveWhenNullParameter() { - assertThat(PatchedValue.<Integer>ofNullable(null)).isEqualTo(PatchedValue.<Integer>remove()); - } - - @Test - public void ofNullableShouldBeEquivalentToModifyWhenNonNullParameter() { - assertThat(PatchedValue.ofNullable(VALUE)).isEqualTo(PatchedValue.modifyTo(VALUE)); - } - - @Test - public void modifyToShouldNotBeKept() { - assertThat(PatchedValue.modifyTo(VALUE).isKept()).isFalse(); - } - - @Test - public void modifyToShouldNotBeRemoved() { - assertThat(PatchedValue.modifyTo(VALUE).isRemoved()).isFalse(); - } - - @Test - public void modifyToShouldBeModified() { - assertThat(PatchedValue.modifyTo(VALUE).isModified()).isTrue(); - } - - @Test - public void modifyToShouldThrowOnNullValue() { - assertThatThrownBy(() -> PatchedValue.modifyTo(null)).isInstanceOf(NullPointerException.class); - } - - @Test - public void modifyToShouldBeRetrievedByGet() { - assertThat(PatchedValue.modifyTo(VALUE).get()).isEqualTo(VALUE); - } - - @Test - public void ofOptionalShouldThrowOnNullValue() { - assertThatThrownBy(() -> PatchedValue.ofOptional(null)).isInstanceOf(NullPointerException.class); - } - - @Test - public void ofOptionalShouldBeEquivalentToModifyToWhenPresent() { - assertThat(PatchedValue.ofOptional(OPTIONAL_OF_VALUE)).isEqualTo(PatchedValue.modifyTo(VALUE)); - } - - @Test - public void ofOptionalShouldBeEquivalentToRemoveWhenEmpty() { - assertThat(PatchedValue.ofOptional(Optional.empty())).isEqualTo(PatchedValue.remove()); - } - - @Test - public void notKeptOrElseShouldReturnElseWhenKept() { - assertThat(PatchedValue.<Integer>keep().notKeptOrElse(REPLACEMENT)).isEqualTo(REPLACEMENT); - } - - @Test - public void notKeptOrElseShouldReturnEmptyWhenRemoved() { - assertThat(PatchedValue.<Integer>remove().notKeptOrElse(REPLACEMENT)).isEqualTo(Optional.empty()); - } - - @Test - public void notKeptOrElseShouldReturnOptionalWhenModified() { - assertThat(PatchedValue.modifyTo(VALUE).notKeptOrElse(REPLACEMENT)).isEqualTo(OPTIONAL_OF_VALUE); - } - - @Test - public void toOptionalShouldReturnElseWhenKept() { - assertThat(PatchedValue.<Integer>keep().toOptional()).isEqualTo(Optional.empty()); - } - - @Test - public void toOptionalShouldReturnEmptyWhenRemoved() { - assertThat(PatchedValue.<Integer>remove().toOptional()).isEqualTo(Optional.empty()); - } - - @Test - public void toOptionalShouldReturnOptionalWhenModified() { - assertThat(PatchedValue.modifyTo(VALUE).toOptional()).isEqualTo(OPTIONAL_OF_VALUE); - } - - @Test - public void getOrElseShouldReturnReplacementWhenKept() { - assertThat(PatchedValue.<Integer>keep().getOrElse(REPLACEMENT_VALUE)).isEqualTo(REPLACEMENT_VALUE); - } - - @Test - public void getOrElseShouldReturnReplacementWhenRemoved() { - assertThat(PatchedValue.<Integer>remove().getOrElse(REPLACEMENT_VALUE)).isEqualTo(REPLACEMENT_VALUE); - } - - @Test - public void getOrElseShouldReturnValueWhenPresent() { - assertThat(PatchedValue.modifyTo(VALUE).getOrElse(REPLACEMENT_VALUE)).isEqualTo(VALUE); - } - - @Test - public void getOrElseShouldReturnNullWhenKeptAndNullSpecified() { - assertThat(PatchedValue.<Integer>keep().getOrElse(null)).isNull(); - } - - @Test - public void getOrElseShouldReturnNullWhenRemovedAndNullSpecified() { - assertThat(PatchedValue.<Integer>remove().getOrElse(null)).isNull(); - } - - @Test - public void getOrElseShouldReturnValueWhenPresentAndNullSpecified() { - assertThat(PatchedValue.modifyTo(VALUE).getOrElse(null)).isEqualTo(VALUE); - } - - @Test - public void mapNotKeptToValueShouldPreserveKept() { - assertThat( - PatchedValue.<Integer>keep() - .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) - .isEmpty(); - } - - @Test - public void mapNotKeptToValueShouldTransformOf() { - assertThat( - PatchedValue.modifyTo(VALUE) - .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) - .contains(VALUE + 1); - } - - @Test - public void mapNotKeptToValueShouldTransformRemoved() { - assertThat( - PatchedValue.<Integer>remove() - .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) - .contains(REPLACEMENT_VALUE); - } - - @Test - public void mapNotKeptToValueShouldThrowWhenNull() { - assertThatThrownBy( - () -> PatchedValue.modifyTo(12) - .mapNotKeptToOptional(any -> null) - .isPresent()) - .isInstanceOf(NullPointerException.class); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/container/util-java8/src/test/java/org/apache/james/util/ValuePatchTest.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/ValuePatchTest.java b/server/container/util-java8/src/test/java/org/apache/james/util/ValuePatchTest.java new file mode 100644 index 0000000..ef84393 --- /dev/null +++ b/server/container/util-java8/src/test/java/org/apache/james/util/ValuePatchTest.java @@ -0,0 +1,220 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy modifyTo the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.NoSuchElementException; +import java.util.Optional; + +import org.junit.Test; + +public class ValuePatchTest { + + public static final int REPLACEMENT_VALUE = 24; + public static final Optional<Integer> REPLACEMENT = Optional.of(REPLACEMENT_VALUE); + public static final int VALUE = 12; + public static final Optional<Integer> OPTIONAL_OF_VALUE = Optional.of(VALUE); + + @Test + public void keepShouldProduceKeptValues() { + assertThat(ValuePatch.<Integer>keep().isKept()).isTrue(); + } + + @Test + public void keepShouldThrowOnGet() { + assertThatThrownBy(() -> ValuePatch.<Integer>keep().get()).isInstanceOf(NoSuchElementException.class); + } + + @Test + public void keepShouldNotBeModified() { + assertThat(ValuePatch.<Integer>keep().isModified()).isFalse(); + } + + @Test + public void keepShouldNotBeRemoved() { + assertThat(ValuePatch.<Integer>keep().isRemoved()).isFalse(); + } + + @Test + public void removeShouldNotBeKept() { + assertThat(ValuePatch.<Integer>remove().isKept()).isFalse(); + } + + @Test + public void removeShouldBeRemoved() { + assertThat(ValuePatch.<Integer>remove().isRemoved()).isTrue(); + } + + @Test + public void removedShouldNotBeModified() { + assertThat(ValuePatch.<Integer>remove().isModified()).isFalse(); + } + + @Test + public void removeShouldThrowOnGet() { + assertThatThrownBy(() -> ValuePatch.<Integer>remove().get()).isInstanceOf(NoSuchElementException.class); + } + + @Test + public void ofNullableShouldBeEquivalentToRemoveWhenNullParameter() { + assertThat(ValuePatch.<Integer>ofNullable(null)).isEqualTo(ValuePatch.<Integer>remove()); + } + + @Test + public void ofNullableShouldBeEquivalentToModifyWhenNonNullParameter() { + assertThat(ValuePatch.ofNullable(VALUE)).isEqualTo(ValuePatch.modifyTo(VALUE)); + } + + @Test + public void modifyToShouldNotBeKept() { + assertThat(ValuePatch.modifyTo(VALUE).isKept()).isFalse(); + } + + @Test + public void modifyToShouldNotBeRemoved() { + assertThat(ValuePatch.modifyTo(VALUE).isRemoved()).isFalse(); + } + + @Test + public void modifyToShouldBeModified() { + assertThat(ValuePatch.modifyTo(VALUE).isModified()).isTrue(); + } + + @Test + public void modifyToShouldThrowOnNullValue() { + assertThatThrownBy(() -> ValuePatch.modifyTo(null)).isInstanceOf(NullPointerException.class); + } + + @Test + public void modifyToShouldBeRetrievedByGet() { + assertThat(ValuePatch.modifyTo(VALUE).get()).isEqualTo(VALUE); + } + + @Test + public void ofOptionalShouldThrowOnNullValue() { + assertThatThrownBy(() -> ValuePatch.ofOptional(null)).isInstanceOf(NullPointerException.class); + } + + @Test + public void ofOptionalShouldBeEquivalentToModifyToWhenPresent() { + assertThat(ValuePatch.ofOptional(OPTIONAL_OF_VALUE)).isEqualTo(ValuePatch.modifyTo(VALUE)); + } + + @Test + public void ofOptionalShouldBeEquivalentToRemoveWhenEmpty() { + assertThat(ValuePatch.ofOptional(Optional.empty())).isEqualTo(ValuePatch.remove()); + } + + @Test + public void notKeptOrElseShouldReturnElseWhenKept() { + assertThat(ValuePatch.<Integer>keep().notKeptOrElse(REPLACEMENT)).isEqualTo(REPLACEMENT); + } + + @Test + public void notKeptOrElseShouldReturnEmptyWhenRemoved() { + assertThat(ValuePatch.<Integer>remove().notKeptOrElse(REPLACEMENT)).isEqualTo(Optional.empty()); + } + + @Test + public void notKeptOrElseShouldReturnOptionalWhenModified() { + assertThat(ValuePatch.modifyTo(VALUE).notKeptOrElse(REPLACEMENT)).isEqualTo(OPTIONAL_OF_VALUE); + } + + @Test + public void toOptionalShouldReturnElseWhenKept() { + assertThat(ValuePatch.<Integer>keep().toOptional()).isEqualTo(Optional.empty()); + } + + @Test + public void toOptionalShouldReturnEmptyWhenRemoved() { + assertThat(ValuePatch.<Integer>remove().toOptional()).isEqualTo(Optional.empty()); + } + + @Test + public void toOptionalShouldReturnOptionalWhenModified() { + assertThat(ValuePatch.modifyTo(VALUE).toOptional()).isEqualTo(OPTIONAL_OF_VALUE); + } + + @Test + public void getOrElseShouldReturnReplacementWhenKept() { + assertThat(ValuePatch.<Integer>keep().getOrElse(REPLACEMENT_VALUE)).isEqualTo(REPLACEMENT_VALUE); + } + + @Test + public void getOrElseShouldReturnReplacementWhenRemoved() { + assertThat(ValuePatch.<Integer>remove().getOrElse(REPLACEMENT_VALUE)).isEqualTo(REPLACEMENT_VALUE); + } + + @Test + public void getOrElseShouldReturnValueWhenPresent() { + assertThat(ValuePatch.modifyTo(VALUE).getOrElse(REPLACEMENT_VALUE)).isEqualTo(VALUE); + } + + @Test + public void getOrElseShouldReturnNullWhenKeptAndNullSpecified() { + assertThat(ValuePatch.<Integer>keep().getOrElse(null)).isNull(); + } + + @Test + public void getOrElseShouldReturnNullWhenRemovedAndNullSpecified() { + assertThat(ValuePatch.<Integer>remove().getOrElse(null)).isNull(); + } + + @Test + public void getOrElseShouldReturnValueWhenPresentAndNullSpecified() { + assertThat(ValuePatch.modifyTo(VALUE).getOrElse(null)).isEqualTo(VALUE); + } + + @Test + public void mapNotKeptToValueShouldPreserveKept() { + assertThat( + ValuePatch.<Integer>keep() + .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) + .isEmpty(); + } + + @Test + public void mapNotKeptToValueShouldTransformOf() { + assertThat( + ValuePatch.modifyTo(VALUE) + .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) + .contains(VALUE + 1); + } + + @Test + public void mapNotKeptToValueShouldTransformRemoved() { + assertThat( + ValuePatch.<Integer>remove() + .mapNotKeptToOptional(optional -> optional.map(i -> i + 1).orElse(REPLACEMENT_VALUE))) + .contains(REPLACEMENT_VALUE); + } + + @Test + public void mapNotKeptToValueShouldThrowWhenNull() { + assertThatThrownBy( + () -> ValuePatch.modifyTo(12) + .mapNotKeptToOptional(any -> null) + .isPresent()) + .isInstanceOf(NullPointerException.class); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java ---------------------------------------------------------------------- diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java index 2ac0823..6cecbcb 100644 --- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java +++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/vacation/CassandraVacationDAO.java @@ -40,7 +40,7 @@ import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationPatch; import org.apache.james.jmap.cassandra.vacation.tables.CassandraVacationTable; import org.apache.james.util.FunctionGenerator; -import org.apache.james.util.PatchedValue; +import org.apache.james.util.ValuePatch; import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.Row; @@ -113,13 +113,13 @@ public class CassandraVacationDAO { .apply(baseInsert); } - public <T> Function<Insert, Insert> applyPatchForField(String field, PatchedValue<T> patchedValue) { - return patchedValue.mapNotKeptToOptional(optionalValue -> applyPatchForField(field, optionalValue)) + public <T> Function<Insert, Insert> applyPatchForField(String field, ValuePatch<T> valuePatch) { + return valuePatch.mapNotKeptToOptional(optionalValue -> applyPatchForField(field, optionalValue)) .orElse(Function.identity()); } - public Function<Insert, Insert> applyPatchForFieldZonedDateTime(String field, PatchedValue<ZonedDateTime> patchedValue) { - return patchedValue.mapNotKeptToOptional(optionalValue -> applyPatchForField(field, convertToUDTOptional(optionalValue))) + public Function<Insert, Insert> applyPatchForFieldZonedDateTime(String field, ValuePatch<ZonedDateTime> valuePatch) { + return valuePatch.mapNotKeptToOptional(optionalValue -> applyPatchForField(field, convertToUDTOptional(optionalValue))) .orElse(Function.identity()); } http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/VacationPatch.java ---------------------------------------------------------------------- diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/VacationPatch.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/VacationPatch.java index 721ab34..6a2cee1 100644 --- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/VacationPatch.java +++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/vacation/VacationPatch.java @@ -23,7 +23,7 @@ import java.time.ZonedDateTime; import java.util.Objects; import java.util.Optional; -import org.apache.james.util.PatchedValue; +import org.apache.james.util.ValuePatch; import com.google.common.base.Preconditions; @@ -35,85 +35,85 @@ public class VacationPatch { public static Builder builderFrom(Vacation vacation) { return VacationPatch.builder() - .subject(PatchedValue.ofOptional(vacation.getSubject())) - .textBody(PatchedValue.ofOptional(vacation.getTextBody())) - .htmlBody(PatchedValue.ofOptional(vacation.getHtmlBody())) - .fromDate(PatchedValue.ofOptional(vacation.getFromDate())) - .toDate(PatchedValue.ofOptional(vacation.getToDate())) - .isEnabled(PatchedValue.modifyTo(vacation.isEnabled())); + .subject(ValuePatch.ofOptional(vacation.getSubject())) + .textBody(ValuePatch.ofOptional(vacation.getTextBody())) + .htmlBody(ValuePatch.ofOptional(vacation.getHtmlBody())) + .fromDate(ValuePatch.ofOptional(vacation.getFromDate())) + .toDate(ValuePatch.ofOptional(vacation.getToDate())) + .isEnabled(ValuePatch.modifyTo(vacation.isEnabled())); } public static class Builder { - private PatchedValue<String> subject = PatchedValue.keep(); - private PatchedValue<String> textBody = PatchedValue.keep(); - private PatchedValue<String> htmlBody = PatchedValue.keep(); - private PatchedValue<ZonedDateTime> toDate = PatchedValue.keep(); - private PatchedValue<ZonedDateTime> fromDate = PatchedValue.keep(); - private PatchedValue<Boolean> isEnabled = PatchedValue.keep(); - - public Builder subject(PatchedValue<String> subject) { + private ValuePatch<String> subject = ValuePatch.keep(); + private ValuePatch<String> textBody = ValuePatch.keep(); + private ValuePatch<String> htmlBody = ValuePatch.keep(); + private ValuePatch<ZonedDateTime> toDate = ValuePatch.keep(); + private ValuePatch<ZonedDateTime> fromDate = ValuePatch.keep(); + private ValuePatch<Boolean> isEnabled = ValuePatch.keep(); + + public Builder subject(ValuePatch<String> subject) { Preconditions.checkNotNull(subject); this.subject = subject; return this; } public Builder subject(String subject) { - this.subject = PatchedValue.modifyTo(subject); + this.subject = ValuePatch.modifyTo(subject); return this; } - public Builder textBody(PatchedValue<String> textBody) { + public Builder textBody(ValuePatch<String> textBody) { Preconditions.checkNotNull(textBody); this.textBody = textBody; return this; } public Builder textBody(String textBody) { - this.textBody = PatchedValue.modifyTo(textBody); + this.textBody = ValuePatch.modifyTo(textBody); return this; } - public Builder htmlBody(PatchedValue<String> htmlBody) { + public Builder htmlBody(ValuePatch<String> htmlBody) { Preconditions.checkNotNull(htmlBody); this.htmlBody = htmlBody; return this; } public Builder htmlBody(String htmlBody) { - this.htmlBody = PatchedValue.modifyTo(htmlBody); + this.htmlBody = ValuePatch.modifyTo(htmlBody); return this; } - public Builder toDate(PatchedValue<ZonedDateTime> toDate) { + public Builder toDate(ValuePatch<ZonedDateTime> toDate) { Preconditions.checkNotNull(toDate); this.toDate = toDate; return this; } public Builder toDate(ZonedDateTime toDate) { - this.toDate = PatchedValue.modifyTo(toDate); + this.toDate = ValuePatch.modifyTo(toDate); return this; } - public Builder fromDate(PatchedValue<ZonedDateTime> fromDate) { + public Builder fromDate(ValuePatch<ZonedDateTime> fromDate) { Preconditions.checkNotNull(fromDate); this.fromDate = fromDate; return this; } public Builder fromDate(ZonedDateTime fromDate) { - this.fromDate = PatchedValue.modifyTo(fromDate); + this.fromDate = ValuePatch.modifyTo(fromDate); return this; } - public Builder isEnabled(PatchedValue<Boolean> isEnabled) { + public Builder isEnabled(ValuePatch<Boolean> isEnabled) { Preconditions.checkNotNull(isEnabled); this.isEnabled = isEnabled; return this; } public Builder isEnabled(Boolean isEnabled) { - this.isEnabled = PatchedValue.modifyTo(isEnabled); + this.isEnabled = ValuePatch.modifyTo(isEnabled); return this; } @@ -122,15 +122,15 @@ public class VacationPatch { } } - private final PatchedValue<String> subject; - private final PatchedValue<String> textBody; - private final PatchedValue<String> htmlBody; - private final PatchedValue<ZonedDateTime> toDate; - private final PatchedValue<ZonedDateTime> fromDate; - private final PatchedValue<Boolean> isEnabled; + private final ValuePatch<String> subject; + private final ValuePatch<String> textBody; + private final ValuePatch<String> htmlBody; + private final ValuePatch<ZonedDateTime> toDate; + private final ValuePatch<ZonedDateTime> fromDate; + private final ValuePatch<Boolean> isEnabled; - private VacationPatch(PatchedValue<String> subject, PatchedValue<String> textBody, PatchedValue<String> htmlBody, - PatchedValue<ZonedDateTime> toDate, PatchedValue<ZonedDateTime> fromDate, PatchedValue<Boolean> isEnabled) { + private VacationPatch(ValuePatch<String> subject, ValuePatch<String> textBody, ValuePatch<String> htmlBody, + ValuePatch<ZonedDateTime> toDate, ValuePatch<ZonedDateTime> fromDate, ValuePatch<Boolean> isEnabled) { Preconditions.checkState(!isEnabled.isRemoved()); this.subject = subject; this.textBody = textBody; @@ -140,27 +140,27 @@ public class VacationPatch { this.isEnabled = isEnabled; } - public PatchedValue<String> getSubject() { + public ValuePatch<String> getSubject() { return subject; } - public PatchedValue<String> getTextBody() { + public ValuePatch<String> getTextBody() { return textBody; } - public PatchedValue<String> getHtmlBody() { + public ValuePatch<String> getHtmlBody() { return htmlBody; } - public PatchedValue<ZonedDateTime> getToDate() { + public ValuePatch<ZonedDateTime> getToDate() { return toDate; } - public PatchedValue<ZonedDateTime> getFromDate() { + public ValuePatch<ZonedDateTime> getFromDate() { return fromDate; } - public PatchedValue<Boolean> getIsEnabled() { + public ValuePatch<Boolean> getIsEnabled() { return isEnabled; } http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java index ef90fb4..3b72f18 100644 --- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java +++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/AbstractVacationRepositoryTest.java @@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.time.ZonedDateTime; import java.util.Optional; -import org.apache.james.util.PatchedValue; +import org.apache.james.util.ValuePatch; import org.junit.Before; import org.junit.Test; @@ -201,7 +201,7 @@ public abstract class AbstractVacationRepositoryTest { // When vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder() - .subject(PatchedValue.remove()) + .subject(ValuePatch.remove()) .build()) .join(); @@ -228,7 +228,7 @@ public abstract class AbstractVacationRepositoryTest { // When vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder() - .textBody(PatchedValue.remove()) + .textBody(ValuePatch.remove()) .build()) .join(); @@ -255,7 +255,7 @@ public abstract class AbstractVacationRepositoryTest { // When vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder() - .htmlBody(PatchedValue.remove()) + .htmlBody(ValuePatch.remove()) .build()) .join(); @@ -282,7 +282,7 @@ public abstract class AbstractVacationRepositoryTest { // When vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder() - .toDate(PatchedValue.remove()) + .toDate(ValuePatch.remove()) .build()) .join(); @@ -309,7 +309,7 @@ public abstract class AbstractVacationRepositoryTest { // When vacationRepository.modifyVacation(ACCOUNT_ID, VacationPatch.builder() - .fromDate(PatchedValue.remove()) + .fromDate(ValuePatch.remove()) .build()) .join(); http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java index 13db92a..101e5dd 100644 --- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java +++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/vacation/VacationPatchTest.java @@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.ZonedDateTime; import java.util.Optional; -import org.apache.james.util.PatchedValue; +import org.apache.james.util.ValuePatch; import org.junit.Test; public class VacationPatchTest { @@ -44,32 +44,32 @@ public class VacationPatchTest { @Test public void fromDateShouldThrowNPEOnNullInput() { - assertThatThrownBy(() -> VacationPatch.builder().fromDate((PatchedValue) null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> VacationPatch.builder().fromDate((ValuePatch) null)).isInstanceOf(NullPointerException.class); } @Test public void toDateShouldThrowNPEOnNullInput() { - assertThatThrownBy(() -> VacationPatch.builder().toDate((PatchedValue) null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> VacationPatch.builder().toDate((ValuePatch) null)).isInstanceOf(NullPointerException.class); } @Test public void textBodyShouldThrowNPEOnNullInput() { - assertThatThrownBy(() -> VacationPatch.builder().textBody((PatchedValue) null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> VacationPatch.builder().textBody((ValuePatch) null)).isInstanceOf(NullPointerException.class); } @Test public void htmlBodyShouldThrowNPEOnNullInput() { - assertThatThrownBy(() -> VacationPatch.builder().htmlBody((PatchedValue) null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> VacationPatch.builder().htmlBody((ValuePatch) null)).isInstanceOf(NullPointerException.class); } @Test public void subjectShouldThrowNPEOnNullInput() { - assertThatThrownBy(() -> VacationPatch.builder().subject((PatchedValue) null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> VacationPatch.builder().subject((ValuePatch) null)).isInstanceOf(NullPointerException.class); } @Test public void isEnabledShouldThrowNPEOnNullInput() { - assertThatThrownBy(() -> VacationPatch.builder().isEnabled((PatchedValue) null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> VacationPatch.builder().isEnabled((ValuePatch) null)).isInstanceOf(NullPointerException.class); } @Test @@ -85,7 +85,7 @@ public class VacationPatchTest { public void isIdentityShouldBeFalseWhenUpdateIsNotEmpty() { assertThat( VacationPatch.builder() - .subject(PatchedValue.modifyTo("any subject")) + .subject(ValuePatch.modifyTo("any subject")) .build() .isIdentity()) .isFalse(); @@ -93,22 +93,22 @@ public class VacationPatchTest { @Test public void builderShouldWellSetFields() { - PatchedValue<String> subject = PatchedValue.modifyTo("subject"); - PatchedValue<String> htmlBody = PatchedValue.modifyTo("html text"); - PatchedValue<String> textBody = PatchedValue.modifyTo("simple text"); - PatchedValue<Boolean> isEnabled = PatchedValue.modifyTo(true); + ValuePatch<String> subject = ValuePatch.modifyTo("subject"); + ValuePatch<String> htmlBody = ValuePatch.modifyTo("html text"); + ValuePatch<String> textBody = ValuePatch.modifyTo("simple text"); + ValuePatch<Boolean> isEnabled = ValuePatch.modifyTo(true); VacationPatch update = VacationPatch.builder() - .fromDate(PatchedValue.modifyTo(DATE_2014)) - .toDate(PatchedValue.modifyTo(DATE_2015)) + .fromDate(ValuePatch.modifyTo(DATE_2014)) + .toDate(ValuePatch.modifyTo(DATE_2015)) .subject(subject) .htmlBody(htmlBody) .textBody(textBody) .isEnabled(isEnabled) .build(); - assertThat(update.getFromDate()).isEqualTo(PatchedValue.modifyTo(DATE_2014)); - assertThat(update.getToDate()).isEqualTo(PatchedValue.modifyTo(DATE_2015)); + assertThat(update.getFromDate()).isEqualTo(ValuePatch.modifyTo(DATE_2014)); + assertThat(update.getToDate()).isEqualTo(ValuePatch.modifyTo(DATE_2015)); assertThat(update.getSubject()).isEqualTo(subject); assertThat(update.getHtmlBody()).isEqualTo(htmlBody); assertThat(update.getTextBody()).isEqualTo(textBody); @@ -118,7 +118,7 @@ public class VacationPatchTest { @Test public void patchVacationShouldUpdateEnabled() { VacationPatch vacationPatch = VacationPatch.builder() - .isEnabled(PatchedValue.modifyTo(true)) + .isEnabled(ValuePatch.modifyTo(true)) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -130,7 +130,7 @@ public class VacationPatchTest { @Test public void patchVacationShouldUpdateFromDate() { VacationPatch vacationPatch = VacationPatch.builder() - .fromDate(PatchedValue.modifyTo(DATE_2014)) + .fromDate(ValuePatch.modifyTo(DATE_2014)) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -143,7 +143,7 @@ public class VacationPatchTest { @Test public void patchVacationShouldUpdateToDate() { VacationPatch vacationPatch = VacationPatch.builder() - .toDate(PatchedValue.modifyTo(DATE_2017)) + .toDate(ValuePatch.modifyTo(DATE_2017)) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -157,7 +157,7 @@ public class VacationPatchTest { public void patchVacationShouldUpdateSubject() { String newSubject = "new subject"; VacationPatch vacationPatch = VacationPatch.builder() - .subject(PatchedValue.modifyTo(newSubject)) + .subject(ValuePatch.modifyTo(newSubject)) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -171,7 +171,7 @@ public class VacationPatchTest { public void patchVacationShouldUpdateTextBody() { String newTextBody = "new text body"; VacationPatch vacationPatch = VacationPatch.builder() - .textBody(PatchedValue.modifyTo(newTextBody)) + .textBody(ValuePatch.modifyTo(newTextBody)) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -185,7 +185,7 @@ public class VacationPatchTest { public void patchVacationShouldUpdateHtmlBody() { String newHtmlBody = "new <b>html</b> body"; VacationPatch vacationPatch = VacationPatch.builder() - .htmlBody(PatchedValue.modifyTo(newHtmlBody)) + .htmlBody(ValuePatch.modifyTo(newHtmlBody)) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -198,12 +198,12 @@ public class VacationPatchTest { @Test public void patchVacationShouldAllowToUpdateAllFieldsAtOnce() { VacationPatch vacationPatch = VacationPatch.builder() - .subject(PatchedValue.ofOptional(VACATION.getSubject())) - .textBody(PatchedValue.ofOptional(VACATION.getTextBody())) - .htmlBody(PatchedValue.ofOptional(VACATION.getHtmlBody())) - .fromDate(PatchedValue.ofOptional(VACATION.getFromDate())) - .toDate(PatchedValue.ofOptional(VACATION.getToDate())) - .isEnabled(PatchedValue.modifyTo(VACATION.isEnabled())) + .subject(ValuePatch.ofOptional(VACATION.getSubject())) + .textBody(ValuePatch.ofOptional(VACATION.getTextBody())) + .htmlBody(ValuePatch.ofOptional(VACATION.getHtmlBody())) + .fromDate(ValuePatch.ofOptional(VACATION.getFromDate())) + .toDate(ValuePatch.ofOptional(VACATION.getToDate())) + .isEnabled(ValuePatch.modifyTo(VACATION.isEnabled())) .build(); assertThat(vacationPatch.patch(VacationRepository.DEFAULT_VACATION)) @@ -221,7 +221,7 @@ public class VacationPatchTest { @Test public void nullUpdateShouldResetSubject() { Vacation vacation = VacationPatch.builderFrom(VACATION) - .subject(PatchedValue.remove()) + .subject(ValuePatch.remove()) .build() .patch(VACATION); @@ -239,7 +239,7 @@ public class VacationPatchTest { @Test public void nullUpdateShouldResetText() { Vacation vacation = VacationPatch.builderFrom(VACATION) - .textBody(PatchedValue.remove()) + .textBody(ValuePatch.remove()) .build() .patch(VACATION); @@ -257,7 +257,7 @@ public class VacationPatchTest { @Test public void nullUpdateShouldResetHtml() { Vacation vacation = VacationPatch.builderFrom(VACATION) - .htmlBody(PatchedValue.remove()) + .htmlBody(ValuePatch.remove()) .build() .patch(VACATION); @@ -275,7 +275,7 @@ public class VacationPatchTest { @Test public void nullUpdateShouldResetToDate() { Vacation vacation = VacationPatch.builderFrom(VACATION) - .toDate(PatchedValue.remove()) + .toDate(ValuePatch.remove()) .build() .patch(VACATION); @@ -293,7 +293,7 @@ public class VacationPatchTest { @Test public void nullUpdateShouldResetFromDate() { Vacation vacation = VacationPatch.builderFrom(VACATION) - .fromDate(PatchedValue.remove()) + .fromDate(ValuePatch.remove()) .build() .patch(VACATION); http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java index 64b2bc0..4303e23 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java @@ -34,7 +34,7 @@ import org.apache.james.jmap.api.access.AccessToken; import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationPatch; -import org.apache.james.util.PatchedValue; +import org.apache.james.util.ValuePatch; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -212,7 +212,7 @@ public abstract class SetVacationResponseTest { public void setVacationResponseShouldAllowResets() { jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), VacationPatch.builder() - .textBody(PatchedValue.modifyTo("any value")) + .textBody(ValuePatch.modifyTo("any value")) .build()); String bodyRequest = "[[" + @@ -250,7 +250,7 @@ public abstract class SetVacationResponseTest { String subject = "any subject"; jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), VacationPatch.builder() - .textBody(PatchedValue.modifyTo(textBody)) + .textBody(ValuePatch.modifyTo(textBody)) .build()); String bodyRequest = "[[" + @@ -290,7 +290,7 @@ public abstract class SetVacationResponseTest { public void setVacationResponseShouldAllowPartialUpdates() { jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), VacationPatch.builder() - .textBody(PatchedValue.modifyTo("any value")) + .textBody(ValuePatch.modifyTo("any value")) .build()); String newTextBody = "Awesome text message 2"; http://git-wip-us.apache.org/repos/asf/james-project/blob/5cfe856b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java index fbd8991..37816a0 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java @@ -19,8 +19,6 @@ package org.apache.james.jmap.model; -import static org.apache.james.jmap.api.vacation.Vacation.DEFAULT_DISABLED; - import java.time.ZonedDateTime; import java.util.Objects; import java.util.Optional; @@ -29,7 +27,7 @@ import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationPatch; import org.apache.james.jmap.json.OptionalZonedDateTimeDeserializer; import org.apache.james.jmap.json.OptionalZonedDateTimeSerializer; -import org.apache.james.util.PatchedValue; +import org.apache.james.util.ValuePatch; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; @@ -47,23 +45,23 @@ public class VacationResponse { @JsonPOJOBuilder(withPrefix = "") public static class Builder { - private PatchedValue<String> id = PatchedValue.keep(); - private PatchedValue<Boolean> isEnabled = PatchedValue.keep(); - private PatchedValue<ZonedDateTime> fromDate = PatchedValue.keep(); - private PatchedValue<ZonedDateTime> toDate = PatchedValue.keep(); - private PatchedValue<String> subject = PatchedValue.keep(); - private PatchedValue<String> textBody = PatchedValue.keep(); - private PatchedValue<String> htmlBody = PatchedValue.keep(); + private ValuePatch<String> id = ValuePatch.keep(); + private ValuePatch<Boolean> isEnabled = ValuePatch.keep(); + private ValuePatch<ZonedDateTime> fromDate = ValuePatch.keep(); + private ValuePatch<ZonedDateTime> toDate = ValuePatch.keep(); + private ValuePatch<String> subject = ValuePatch.keep(); + private ValuePatch<String> textBody = ValuePatch.keep(); + private ValuePatch<String> htmlBody = ValuePatch.keep(); private Optional<Boolean> isActivated = Optional.empty(); public Builder id(String id) { - this.id = PatchedValue.modifyTo(id); + this.id = ValuePatch.modifyTo(id); return this; } @JsonProperty("isEnabled") public Builder enabled(boolean enabled) { - isEnabled = PatchedValue.modifyTo(enabled); + isEnabled = ValuePatch.modifyTo(enabled); return this; } @@ -81,39 +79,39 @@ public class VacationResponse { @JsonDeserialize(using = OptionalZonedDateTimeDeserializer.class) public Builder fromDate(Optional<ZonedDateTime> fromDate) { - this.fromDate = PatchedValue.ofOptional(fromDate); + this.fromDate = ValuePatch.ofOptional(fromDate); return this; } @JsonDeserialize(using = OptionalZonedDateTimeDeserializer.class) public Builder toDate(Optional<ZonedDateTime> toDate) { - this.toDate = PatchedValue.ofOptional(toDate); + this.toDate = ValuePatch.ofOptional(toDate); return this; } public Builder textBody(Optional<String> textBody) { - this.textBody = PatchedValue.ofOptional(textBody); + this.textBody = ValuePatch.ofOptional(textBody); return this; } public Builder subject(Optional<String> subject) { - this.subject = PatchedValue.ofOptional(subject); + this.subject = ValuePatch.ofOptional(subject); return this; } public Builder htmlBody(Optional<String> htmlBody) { - this.htmlBody = PatchedValue.ofOptional(htmlBody); + this.htmlBody = ValuePatch.ofOptional(htmlBody); return this; } public Builder fromVacation(Vacation vacation) { - this.id = PatchedValue.modifyTo(Vacation.ID); - this.isEnabled = PatchedValue.modifyTo(vacation.isEnabled()); - this.fromDate = PatchedValue.ofOptional(vacation.getFromDate()); - this.toDate = PatchedValue.ofOptional(vacation.getToDate()); - this.textBody = PatchedValue.ofOptional(vacation.getTextBody()); - this.subject = PatchedValue.ofOptional(vacation.getSubject()); - this.htmlBody = PatchedValue.ofOptional(vacation.getHtmlBody()); + this.id = ValuePatch.modifyTo(Vacation.ID); + this.isEnabled = ValuePatch.modifyTo(vacation.isEnabled()); + this.fromDate = ValuePatch.ofOptional(vacation.getFromDate()); + this.toDate = ValuePatch.ofOptional(vacation.getToDate()); + this.textBody = ValuePatch.ofOptional(vacation.getTextBody()); + this.subject = ValuePatch.ofOptional(vacation.getSubject()); + this.htmlBody = ValuePatch.ofOptional(vacation.getHtmlBody()); return this; } @@ -122,17 +120,17 @@ public class VacationResponse { } } - private final PatchedValue<String> id; - private final PatchedValue<Boolean> isEnabled; - private final PatchedValue<ZonedDateTime> fromDate; - private final PatchedValue<ZonedDateTime> toDate; - private final PatchedValue<String> subject; - private final PatchedValue<String> textBody; - private final PatchedValue<String> htmlBody; + private final ValuePatch<String> id; + private final ValuePatch<Boolean> isEnabled; + private final ValuePatch<ZonedDateTime> fromDate; + private final ValuePatch<ZonedDateTime> toDate; + private final ValuePatch<String> subject; + private final ValuePatch<String> textBody; + private final ValuePatch<String> htmlBody; private final Optional<Boolean> isActivated; - private VacationResponse(PatchedValue<String> id, PatchedValue<Boolean> isEnabled, PatchedValue<ZonedDateTime> fromDate, PatchedValue<ZonedDateTime> toDate, - PatchedValue<String> textBody, PatchedValue<String> subject, PatchedValue<String> htmlBody, Optional<Boolean> isActivated) { + private VacationResponse(ValuePatch<String> id, ValuePatch<Boolean> isEnabled, ValuePatch<ZonedDateTime> fromDate, ValuePatch<ZonedDateTime> toDate, + ValuePatch<String> textBody, ValuePatch<String> subject, ValuePatch<String> htmlBody, Optional<Boolean> isActivated) { this.id = id; this.isEnabled = isEnabled; this.fromDate = fromDate; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
