Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A22F9200C59 for ; Sun, 2 Apr 2017 19:45:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A0FCA160BB7; Sun, 2 Apr 2017 17:45:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F1952160BB9 for ; Sun, 2 Apr 2017 19:45:43 +0200 (CEST) Received: (qmail 14265 invoked by uid 500); 2 Apr 2017 17:45:43 -0000 Mailing-List: contact commits-help@polygene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@polygene.apache.org Delivered-To: mailing list commits@polygene.apache.org Received: (qmail 13439 invoked by uid 99); 2 Apr 2017 17:45:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Apr 2017 17:45:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8F48FE1859; Sun, 2 Apr 2017 17:45:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: paulmerlin@apache.org To: commits@polygene.apache.org Date: Sun, 02 Apr 2017 17:46:13 -0000 Message-Id: In-Reply-To: <0088a29e2e0d476a907e84190e3d8c97@git.apache.org> References: <0088a29e2e0d476a907e84190e3d8c97@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [33/51] [abbrv] polygene-java git commit: POLYGENE-231 arrays default values archived-at: Sun, 02 Apr 2017 17:45:44 -0000 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/serialization-3.0 Commit: 6f4e59c094a17e7b450a486c005f0982a823607e Parents: 51a355e Author: Paul Merlin Authored: Mon Mar 6 17:56:07 2017 +0100 Committer: Paul Merlin 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 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> initializedMapDefaultValue(); + + @Optional + Property nullPrimitiveArray(); + + @UseDefaults + Property emptyPrimitiveArray(); + + @UseDefaults( "[23, 42]" ) + Property initializedPrimitiveArray(); + + @Optional + Property nullArray(); + + @UseDefaults + Property emptyArray(); + + @UseDefaults( "[23, 42]" ) + Property initializedArray(); } }