tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: added some tests (and fixes).
Date Wed, 14 Sep 2016 00:24:10 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 9d976304c -> a41d14368


added some tests (and fixes).


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a41d1436
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a41d1436
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a41d1436

Branch: refs/heads/master
Commit: a41d143687f455d2a6e5128f3397be4496294e3e
Parents: 9d97630
Author: anatole <anatole@apache.org>
Authored: Wed Sep 14 02:23:58 2016 +0200
Committer: anatole <anatole@apache.org>
Committed: Wed Sep 14 02:23:58 2016 +0200

----------------------------------------------------------------------
 .../internal/converters/ClassConverter.java     |  3 +
 .../core/internal/converters/URIConverter.java  |  3 +
 .../core/internal/converters/URLConverter.java  |  3 +
 .../internal/converters/ClassConverterTest.java | 69 ++++++++++++++++++++
 4 files changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a41d1436/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
index 15e78d2..e1823e9 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
@@ -38,6 +38,9 @@ public class ClassConverter implements PropertyConverter<Class<?>>{
 
     @Override
     public Class<?> convert(String value, ConversionContext context) {
+        if(value==null){
+            return null;
+        }
         context.addSupportedFormats(getClass(),"<fullyQualifiedClassName>");
         String trimmed = Objects.requireNonNull(value).trim();
         try{

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a41d1436/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
index ac30bfc..55273e0 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
@@ -35,6 +35,9 @@ public class URIConverter implements PropertyConverter<URI> {
 
     @Override
     public URI convert(String value, ConversionContext context) {
+        if(value==null || value.isEmpty()){
+            return null;
+        }
         context.addSupportedFormats(getClass(), "<uri> -> new URI(uri)");
         String trimmed = Objects.requireNonNull(value).trim();
         try {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a41d1436/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
index 9a85a16..e250943 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
@@ -35,6 +35,9 @@ public class URLConverter implements PropertyConverter<URL> {
 
     @Override
     public URL convert(String value, ConversionContext context) {
+        if(value==null || value.isEmpty()){
+            return null;
+        }
         context.addSupportedFormats(getClass(),"<URL>");
         String trimmed = Objects.requireNonNull(value).trim();
         try {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a41d1436/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
new file mode 100644
index 0000000..c344ac6
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests conversion of the {@link ClassConverter}.
+ */
+public class ClassConverterTest {
+
+    ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Class.class))
+            .build();
+
+    @Test
+    public void testConvert_Class() throws Exception {
+        ClassConverter converter = new ClassConverter();
+        assertEquals(BigDecimal.class, converter.convert("java.math.BigDecimal", context));
+    }
+
+    @Test
+    public void testConvert_Class_WithSpaces() throws Exception {
+        ClassConverter converter = new ClassConverter();
+        assertEquals(BigDecimal.class, converter.convert("  java.math.BigDecimal\t", context));
+    }
+
+    @Test
+    public void testConvert_Class_WithSpacesBefore() throws Exception {
+        ClassConverter converter = new ClassConverter();
+        assertEquals(BigDecimal.class, converter.convert("  java.math.BigDecimal", context));
+    }
+
+    @Test
+    public void testConvert_Class_WithSpacesAfter() throws Exception {
+        ClassConverter converter = new ClassConverter();
+        assertEquals(BigDecimal.class, converter.convert("java.math.BigDecimal  ", context));
+    }
+
+    @Test
+    public void testConvert_NotPresent() throws Exception {
+        ClassConverter converter = new ClassConverter();
+        assertNull(converter.convert("", context));
+        assertNull(converter.convert(null, context));
+    }
+}


Mime
View raw message