felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1774998 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/inject/Annotations.java test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java
Date Mon, 19 Dec 2016 07:01:49 GMT
Author: cziegeler
Date: Mon Dec 19 07:01:49 2016
New Revision: 1774998

URL: http://svn.apache.org/viewvc?rev=1774998&view=rev
Log:
FELIX-5404 : Annotation configurations default values are not considered. Apply patch from
Julian Sedding

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java?rev=1774998&r1=1774997&r2=1774998&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java Mon Dec
19 07:01:49 2016
@@ -56,6 +56,13 @@ public class Annotations
                 complexFields.put(key, method);
                 continue;
             }
+
+            if ( raw == null && method.getDefaultValue() != null )
+            {
+                m.put( name, method.getDefaultValue());
+                continue;
+            }
+
             try
             {
                 if (returnType.isArray())

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java?rev=1774998&r1=1774997&r2=1774998&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java Mon
Dec 19 07:01:49 2016
@@ -136,6 +136,7 @@ public class AnnotationTest extends Test
         values.put("lon", "12345678");
         values.put("shor", 3l);
         values.put("string", 3);
+        values.put("array", new String[]{"foo", "bar"});
         return values;
     }
 
@@ -172,6 +173,7 @@ public class AnnotationTest extends Test
         long lon() default Long.MIN_VALUE;
         short shor() default -8;
         String string() default "default";
+        String[] array() default {};
     }
     
     public void testA2AllValues() throws Exception
@@ -193,6 +195,29 @@ public class AnnotationTest extends Test
         assertEquals(12345678l,  a.lon());
         assertEquals((short)3, a.shor());
         assertEquals("3", a.string());
+        assertArrayEquals(new String[]{"foo", "bar"}, a.array());
+    }
+
+    public void testA2DefaultValues() throws Exception
+    {
+        Map<String, Object> values = Collections.emptyMap();
+
+        Object o = Annotations.toObject( A2.class, values, mockBundle(), false);
+        assertTrue("expected an A2", o instanceof A2);
+
+        A2 a = (A2) o;
+        assertEquals(true, a.bool());
+        assertEquals((byte)5, a.byt());
+        assertEquals('a', a.cha());
+        assertEquals(Integer.class, a.clas());
+        assertEquals(E1.b, a.e1());
+        assertEquals(-2.0, a.doubl());
+        assertEquals(-4f, a.floa());
+        assertEquals(-5, a.integer());
+        assertEquals(Long.MIN_VALUE,  a.lon());
+        assertEquals((short)-8, a.shor());
+        assertEquals("default", a.string());
+        assertArrayEquals(new String[0], a.array());
     }
     
     public @interface A1Arrays {



Mime
View raw message