Repository: incubator-tamaya Updated Branches: refs/heads/master aa55969e9 -> bd07d7e69
TAMAYA-260: Add more tests And simplify Optional usage for null parameters. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bd07d7e6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bd07d7e6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bd07d7e6 Branch: refs/heads/master Commit: bd07d7e69d5818e4a891bb5db1e126cd5cec6c29 Parents: aa55969 Author: Phil Ottlinger <[email protected]> Authored: Sun Oct 15 22:37:40 2017 +0200 Committer: Phil Ottlinger <[email protected]> Committed: Sun Oct 15 22:37:40 2017 +0200 ---------------------------------------------------------------------- .../internal/converters/OptionalConverter.java | 2 +- .../converters/OptionalConverterTest.java | 36 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bd07d7e6/code/core/src/main/java/org/apache/tamaya/core/internal/converters/OptionalConverter.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/OptionalConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/OptionalConverter.java index 8cf614a..8be1533 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/OptionalConverter.java +++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/OptionalConverter.java @@ -47,7 +47,7 @@ public class OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext context) { if(value==null){ - return Optional.ofNullable(null); + return Optional.empty(); } try{ Type targetType = context.getTargetType().getType(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bd07d7e6/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java new file mode 100644 index 0000000..c9c9676 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java @@ -0,0 +1,36 @@ +/* + * 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.tamaya.core.internal.converters; + +import org.junit.Test; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +public class OptionalConverterTest { + + @Test + public void nullConversionYieldsEmptyOptional() { + final Optional result = new OptionalConverter().convert(null, null); + assertThat(result).isNotNull(); + assertThat(result.isPresent()).isFalse(); + } + +}
