openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1520786 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo: GenericsInTheZooTest.java StableProducer.java
Date Sat, 07 Sep 2013 18:16:53 GMT
Author: struberg
Date: Sat Sep  7 18:16:52 2013
New Revision: 1520786

URL: http://svn.apache.org/r1520786
Log:
OWB-893 unit test for the producer case

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/StableProducer.java
      - copied, changed from r1520121, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/HorseStable.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/GenericsInTheZooTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/GenericsInTheZooTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/GenericsInTheZooTest.java?rev=1520786&r1=1520785&r2=1520786&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/GenericsInTheZooTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/GenericsInTheZooTest.java
Sat Sep  7 18:16:52 2013
@@ -34,18 +34,11 @@ public class GenericsInTheZooTest extend
     @Test
     public void testSpecificAnimalStable() throws Exception
     {
+        // create the stables via explicit subclasses;
         startContainer(Animal.class, Stable.class, Horse.class, Pig.class, HorseStable.class,
PigStable.class,
                        MySpecificAnimalStables.class);
 
-        MySpecificAnimalStables stables = getInstance(MySpecificAnimalStables.class);
-        Assert.assertNotNull(stables);
-        Assert.assertNotNull(stables.getHorseStable());
-        Assert.assertNotNull(stables.getHorseStable());
-        Assert.assertEquals("horse", stables.getHorseStable().getPet().getName());
-
-        Assert.assertNotNull(stables.getPigStable());
-        Assert.assertNotNull(stables.getPigStable());
-        Assert.assertEquals("pig", stables.getPigStable().getPet().getName());
+        verifyAnimalStables();
     }
 
     @Dependent
@@ -68,4 +61,28 @@ public class GenericsInTheZooTest extend
             return pigStable;
         }
     }
+
+    @Test
+    public void testGenericProducer() throws Exception
+    {
+        // create the stables via a single producer method
+        startContainer(Stable.class, StableProducer.class, MySpecificAnimalStables.class);
+
+        verifyAnimalStables();
+    }
+
+
+    private void verifyAnimalStables()
+    {
+        MySpecificAnimalStables stables = getInstance(MySpecificAnimalStables.class);
+        Assert.assertNotNull(stables);
+        Assert.assertNotNull(stables.getHorseStable());
+        Assert.assertNotNull(stables.getHorseStable());
+        Assert.assertEquals("horse", stables.getHorseStable().getPet().getName());
+
+        Assert.assertNotNull(stables.getPigStable());
+        Assert.assertNotNull(stables.getPigStable());
+        Assert.assertEquals("pig", stables.getPigStable().getPet().getName());
+    }
+
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/StableProducer.java
(from r1520121, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/HorseStable.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/StableProducer.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/StableProducer.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/HorseStable.java&r1=1520121&r2=1520786&rev=1520786&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/HorseStable.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/generics/zoo/StableProducer.java
Sat Sep  7 18:16:52 2013
@@ -19,15 +19,32 @@
 package org.apache.webbeans.newtests.injection.generics.zoo;
 
 import javax.annotation.PostConstruct;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 /**
  * A stable for horses, pigs, etc
  */
-public class HorseStable extends Stable<Horse>
+public class StableProducer extends Stable<Horse>
 {
-    @PostConstruct
-    public void init()
+    @Produces
+    @Dependent
+    public <PET> Stable<PET> createStable(InjectionPoint injectionPoint)
     {
-        setPet(new Horse());
+        Class petClass = (Class) ((ParameterizedType) injectionPoint.getType()).getActualTypeArguments()[0];
+
+        if (Horse.class.equals(petClass))
+        {
+            return (Stable<PET>) new HorseStable();
+        }
+        if (Pig.class.equals(petClass))
+        {
+            return (Stable<PET>) new PigStable();
+        }
+
+        return null;
     }
 }



Mime
View raw message