polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [27/52] [abbrv] polygene-java git commit: POLYGENE-231 arrays default values
Date Sun, 02 Apr 2017 17:48:09 GMT
POLYGENE-231 arrays default values


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/6f4e59c0
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/6f4e59c0
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/6f4e59c0

Branch: refs/heads/develop
Commit: 6f4e59c094a17e7b450a486c005f0982a823607e
Parents: 51a355e
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Mar 6 17:56:07 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sun Apr 2 19:16:23 2017 +0200

----------------------------------------------------------------------
 .../polygene/api/property/DefaultValues.java    |  5 +++
 .../runtime/defaults/UseDefaultsTest.java       | 34 +++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6f4e59c0/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java b/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java
index 00a128e..4207358 100644
--- a/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java
+++ b/core/api/src/main/java/org/apache/polygene/api/property/DefaultValues.java
@@ -20,6 +20,7 @@
 
 package org.apache.polygene.api.property;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
@@ -82,6 +83,10 @@ public final class DefaultValues
             {
                 return ( (Class) type ).getEnumConstants()[ 0 ];
             }
+            else if( typeAsClass.isArray() )
+            {
+                return Array.newInstance( typeAsClass.getComponentType(), 0 );
+            }
         }
         throw new IllegalArgumentException( "Cannot use @UseDefaults with type " + type.toString()
);
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6f4e59c0/core/runtime/src/test/java/org/apache/polygene/runtime/defaults/UseDefaultsTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/defaults/UseDefaultsTest.java
b/core/runtime/src/test/java/org/apache/polygene/runtime/defaults/UseDefaultsTest.java
index ab1feb9..a2dc6b3 100644
--- a/core/runtime/src/test/java/org/apache/polygene/runtime/defaults/UseDefaultsTest.java
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/defaults/UseDefaultsTest.java
@@ -20,6 +20,7 @@
 
 package org.apache.polygene.runtime.defaults;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -36,6 +37,7 @@ import org.junit.Test;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 
 /**
  * JAVADOC
@@ -59,7 +61,14 @@ public class UseDefaultsTest extends AbstractPolygeneTest
         assertThat( "zeroInt is zero", testComposite.defaultInt().get(), equalTo( 0 ) );
         assertThat( "nullString is null", testComposite.nullString().get(), nullValue() );
         assertThat( "defaultString is empty string", testComposite.defaultString().get(),
equalTo( "" ) );
-        assertThat( "assemblyString is empty string", testComposite.assemblyString().get(),
equalTo( "habba" ) );
+        assertThat( "assemblyString is set string", testComposite.assemblyString().get(),
equalTo( "habba" ) );
+
+        assertThat( "nullPrimitiveArray is null", testComposite.nullPrimitiveArray().get(),
nullValue() );
+        assertTrue( "emptyPrimitiveArray is empty",
+                    Arrays.equals( testComposite.emptyPrimitiveArray().get(), new int[ 0
] ) );
+        assertThat( "nullArray is null", testComposite.nullArray().get(), nullValue() );
+        assertTrue( "emptyArray is empty array",
+                    Arrays.equals( testComposite.emptyArray().get(), new Integer[ 0 ] ) );
     }
 
     @Test
@@ -75,6 +84,11 @@ public class UseDefaultsTest extends AbstractPolygeneTest
         assertThat( testComposite.initializedStringListDefultString().get(), equalTo( expectedList
) );
         Map<String, Integer> expectedMap = Collections.singletonMap( "abcd", 345 );
         assertThat( testComposite.initializedMapDefaultValue().get(), equalTo( expectedMap
) );
+
+        assertTrue( "initializedPrimitiveArray is set",
+                    Arrays.equals( testComposite.initializedPrimitiveArray().get(), new int[]
{ 23, 42 } ) );
+        assertTrue( "initializedArray is set",
+                    Arrays.equals( testComposite.initializedArray().get(), new Integer[]
{ 23, 42 } ) );
     }
 
     interface TestComposite
@@ -110,5 +124,23 @@ public class UseDefaultsTest extends AbstractPolygeneTest
 
         @UseDefaults( "{\"abcd\": 345}" )
         Property<Map<String, Integer>> initializedMapDefaultValue();
+
+        @Optional
+        Property<int[]> nullPrimitiveArray();
+
+        @UseDefaults
+        Property<int[]> emptyPrimitiveArray();
+
+        @UseDefaults( "[23, 42]" )
+        Property<int[]> initializedPrimitiveArray();
+
+        @Optional
+        Property<Integer[]> nullArray();
+
+        @UseDefaults
+        Property<Integer[]> emptyArray();
+
+        @UseDefaults( "[23, 42]" )
+        Property<Integer[]> initializedArray();
     }
 }


Mime
View raw message