Repository: incubator-tamaya
Updated Branches:
  refs/heads/master ca4de3dc4 -> 47972d89b


TAMAYA-329: mapBoxedType should work with boolean[]

Simple copy-and-paste miss.  All the other primitives have both a simple
and array type check.  Boolean has two simple checks and no arrays.
This corrects the copy and adds a test.


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

Branch: refs/heads/master
Commit: 47972d89b5d062495e1cd3b4fa948c73df45f95c
Parents: ca4de3d
Author: William Lieurance <william.lieura...@namikoda.com>
Authored: Sun Feb 11 19:48:45 2018 -0600
Committer: William Lieurance <william.lieura...@namikoda.com>
Committed: Sun Feb 11 19:48:45 2018 -0600

----------------------------------------------------------------------
 .../spisupport/PropertyConverterManager.java    |  4 +-
 .../PropertyConverterManagerTest.java           | 62 ++++++++++++++------
 2 files changed, 45 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/47972d89/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git 
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
 
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
index 921cac6..9d1a79f 100644
--- 
a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
+++ 
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
@@ -324,8 +324,8 @@ public class PropertyConverterManager {
         if (parameterType == long[].class) {
             return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
         }
-        if (parameterType == boolean.class) {
-            return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
+        if (parameterType == boolean[].class) {
+            return TypeLiteral.class.cast(TypeLiteral.of(Boolean[].class));
         }
         if (parameterType == char[].class) {
             return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/47972d89/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git 
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
 
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
index b91e6e4..668409a 100644
--- 
a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
+++ 
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
@@ -18,9 +18,7 @@
  */
 package org.apache.tamaya.spisupport;
 
-
-
-import org.apache.tamaya.ConfigurationProvider;
+import java.lang.reflect.Method;
 import org.apache.tamaya.spi.ConversionContext;
 import org.apache.tamaya.spi.PropertyConverter;
 import org.apache.tamaya.TypeLiteral;
@@ -32,6 +30,7 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+import static org.junit.Assert.assertEquals;
 
 public class PropertyConverterManagerTest {
 
@@ -43,7 +42,7 @@ public class PropertyConverterManagerTest {
         PropertyConverterManager manager = new PropertyConverterManager(true);
 
         assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class)),
-                   is(true));
+                is(true));
     }
 
     @Test
@@ -51,7 +50,7 @@ public class PropertyConverterManagerTest {
         PropertyConverterManager manager = new PropertyConverterManager(true);
 
         List<PropertyConverter<MyType>> converters = 
manager.getPropertyConverters(
-                (TypeLiteral)TypeLiteral.of(MyType.class));
+                (TypeLiteral) TypeLiteral.of(MyType.class));
 
         assertThat(converters, hasSize(1));
 
@@ -61,11 +60,11 @@ public class PropertyConverterManagerTest {
 
         assertThat(result, notNullValue());
         assertThat(result, instanceOf(MyType.class));
-        assertThat(((MyType)result).getValue(), equalTo("IN"));
+        assertThat(((MyType) result).getValue(), equalTo("IN"));
     }
 
     @Test
-    public void testDirectConverterMapping(){
+    public void testDirectConverterMapping() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<C>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class)));
         assertThat(converters, hasSize(1));
@@ -79,7 +78,7 @@ public class PropertyConverterManagerTest {
     }
 
     @Test
-    public void testDirectSuperclassConverterMapping(){
+    public void testDirectSuperclassConverterMapping() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<B>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
         assertThat(converters, hasSize(1));
@@ -91,11 +90,11 @@ public class PropertyConverterManagerTest {
 
         assertThat(result, notNullValue());
         assertThat(result, instanceOf(C.class));
-        assertThat(((C)result).getInValue(), 
equalTo("testDirectSuperclassConverterMapping"));
+        assertThat(((C) result).getInValue(), 
equalTo("testDirectSuperclassConverterMapping"));
     }
 
     @Test
-    public void testMultipleConverterLoad(){
+    public void testMultipleConverterLoad() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<B>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
         assertThat(converters, hasSize(1));
@@ -105,7 +104,7 @@ public class PropertyConverterManagerTest {
     }
 
     @Test
-    public void testTransitiveSuperclassConverterMapping(){
+    public void testTransitiveSuperclassConverterMapping() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<A>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
         assertThat(converters, hasSize(1));
@@ -115,11 +114,11 @@ public class PropertyConverterManagerTest {
 
         assertThat(result, notNullValue());
         assertThat(result, instanceOf(C.class));
-        assertThat(((C)result).getInValue(), 
equalTo("testTransitiveSuperclassConverterMapping"));
+        assertThat(((C) result).getInValue(), 
equalTo("testTransitiveSuperclassConverterMapping"));
     }
 
     @Test
-    public void testDirectInterfaceMapping(){
+    public void testDirectInterfaceMapping() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<Readable>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
         assertThat(converters, hasSize(1));
@@ -129,11 +128,11 @@ public class PropertyConverterManagerTest {
 
         assertThat(result, notNullValue());
         assertThat(result, instanceOf(C.class));
-        assertThat(((C)result).getInValue(), 
equalTo("testDirectInterfaceMapping"));
+        assertThat(((C) result).getInValue(), 
equalTo("testDirectInterfaceMapping"));
     }
 
     @Test
-    public void testTransitiveInterfaceMapping1(){
+    public void testTransitiveInterfaceMapping1() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<Runnable>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class)));
         assertThat(converters, hasSize(1));
@@ -143,11 +142,11 @@ public class PropertyConverterManagerTest {
 
         assertThat(result, notNullValue());
         assertThat(result, instanceOf(C.class));
-        assertThat(((C)result).getInValue(), 
equalTo("testTransitiveInterfaceMapping1"));
+        assertThat(((C) result).getInValue(), 
equalTo("testTransitiveInterfaceMapping1"));
     }
 
     @Test
-    public void testTransitiveInterfaceMapping2(){
+    public void testTransitiveInterfaceMapping2() {
         PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<AutoCloseable>> converters = 
List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class)));
         assertThat(converters, hasSize(1));
@@ -157,10 +156,35 @@ public class PropertyConverterManagerTest {
 
         assertThat(result, notNullValue());
         assertThat(result, instanceOf(C.class));
-        assertThat(((C)result).getInValue(), 
equalTo("testTransitiveInterfaceMapping2"));
+        assertThat(((C) result).getInValue(), 
equalTo("testTransitiveInterfaceMapping2"));
+    }
+
+    @Test
+    public void testMapBoxedType() throws Exception {
+        PropertyConverterManager manager = new PropertyConverterManager(false);
+
+        Class[] boxed = new Class[]{
+            Integer[].class, Short[].class, Byte[].class, Long[].class,
+            Boolean[].class, Character[].class, Float[].class, Double[].class
+        };
+        Class[] primitive = new Class[]{
+            int[].class, short[].class, byte[].class, long[].class,
+            boolean[].class, char[].class, float[].class, double[].class
+        };
+
+        Method method = 
PropertyConverterManager.class.getDeclaredMethod("mapBoxedType", 
TypeLiteral.class);
+        method.setAccessible(true);
+
+        for (int i = 0; i < boxed.length; i++) {
+            assertEquals(TypeLiteral.of(boxed[i]),
+                    method.invoke(manager, TypeLiteral.of(primitive[i])));
+            assertEquals(TypeLiteral.of(boxed[i].getComponentType()),
+                    method.invoke(manager, 
TypeLiteral.of(primitive[i].getComponentType())));
+        }
     }
 
     public static class MyType {
+
         private final String typeValue;
 
         private MyType(String value) {
@@ -177,4 +201,4 @@ public class PropertyConverterManagerTest {
 
     }
 
-}
\ No newline at end of file
+}

Reply via email to