[webbeans-commits] Webbeans SVN: r264 - in ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans: examples and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Nov 6 11:32:45 EST 2008
Author: gavin.king at jboss.com
Date: 2008-11-06 11:32:45 -0500 (Thu, 06 Nov 2008)
New Revision: 264
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Game.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Generator.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Random.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java
Log:
Added Random example
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Game.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Game.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Game.java 2008-11-06 16:32:45 UTC (rev 264)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.examples;
+
+public class Game
+{
+ private @Random int number;
+
+ public int getNumber()
+ {
+ return number;
+ }
+
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Generator.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Generator.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Generator.java 2008-11-06 16:32:45 UTC (rev 264)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.examples;
+
+import javax.webbeans.ApplicationScoped;
+import javax.webbeans.Produces;
+
+ at ApplicationScoped
+public class Generator {
+
+ private java.util.Random random = new java.util.Random( System.currentTimeMillis() );
+
+ @Produces @Random int next() {
+ return random.nextInt(100);
+ }
+
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Random.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Random.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Random.java 2008-11-06 16:32:45 UTC (rev 264)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.examples;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+public @interface Random
+{
+
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java 2008-11-06 16:32:45 UTC (rev 264)
@@ -0,0 +1,27 @@
+package org.jboss.webbeans.examples;
+
+import java.lang.reflect.Method;
+
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.AbstractTest;
+import org.jboss.webbeans.test.util.Util;
+import org.testng.annotations.Test;
+
+public class Tests extends AbstractTest
+{
+ @Test
+ public void testGameGenerator() throws Exception {
+ SimpleBean<Game> gameBean = Util.createSimpleWebBean(Game.class, manager);
+ SimpleBean<Generator> generatorBean = Util.createSimpleWebBean(Generator.class, manager);
+ Method method = Generator.class.getDeclaredMethod("next");
+ method.setAccessible(true);
+ ProducerMethodBean<Integer> nextBean = Util.createProducerMethodBean(int.class, method, manager, generatorBean);
+ manager.addBean(gameBean);
+ manager.addBean(generatorBean);
+ manager.addBean(nextBean);
+ Game game1 = manager.getInstanceByType(Game.class);
+ Game game2 = manager.getInstanceByType(Game.class);
+ assert game1.getNumber()!=game2.getNumber();
+ }
+}
More information about the weld-commits
mailing list