[webbeans-commits] Webbeans SVN: r261 - in ri/trunk: webbeans-ri/src/main/java/org/jboss/webbeans/bean and 3 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Nov 6 09:55:05 EST 2008
Author: pete.muir at jboss.org
Date: 2008-11-06 09:55:05 -0500 (Thu, 06 Nov 2008)
New Revision: 261
Added:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/IllegalProductException.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java
Log:
producer method create()
Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/IllegalProductException.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/IllegalProductException.java (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/IllegalProductException.java 2008-11-06 14:55:05 UTC (rev 261)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package javax.webbeans;
+
+/**
+ */
+public class IllegalProductException extends ExecutionException
+{
+
+ public IllegalProductException()
+ {
+ super();
+ }
+
+ public IllegalProductException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public IllegalProductException(String message)
+ {
+ super(message);
+ }
+
+ public IllegalProductException(Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Property changes on: ri/trunk/webbeans-api/src/main/java/javax/webbeans/IllegalProductException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-06 14:40:22 UTC (rev 260)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-06 14:55:05 UTC (rev 261)
@@ -1,5 +1,8 @@
package org.jboss.webbeans.bean;
+import javax.webbeans.Dependent;
+import javax.webbeans.IllegalProductException;
+
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
@@ -23,7 +26,12 @@
@Override
public T create()
{
- return model.getConstructor().invoke(manager, manager.getInstance(model.getDeclaringBean()));
+ T instance = model.getConstructor().invoke(manager, manager.getInstance(model.getDeclaringBean()));
+ if (instance == null && !model.getScopeType().equals(Dependent.class))
+ {
+ throw new IllegalProductException("Cannot return null from a non-dependent method");
+ }
+ return instance;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java 2008-11-06 14:40:22 UTC (rev 260)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanLifecycleTest.java 2008-11-06 14:55:05 UTC (rev 261)
@@ -5,12 +5,14 @@
import java.lang.reflect.Method;
-import javax.webbeans.DefinitionException;
+import javax.webbeans.IllegalProductException;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.beans.Spider;
import org.jboss.webbeans.test.beans.SpiderProducer;
import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.broken.BrokenSpiderProducer;
import org.testng.annotations.Test;
public class ProducerMethodBeanLifecycleTest extends AbstractTest
@@ -26,21 +28,7 @@
Tarantula tarantula = tarantulaBean.create();
assert tarantula != null;
}
-
- @Test(groups="producerMethod") @SpecAssertion(section="3.3")
- public void testNonDependentProducerMethodThatReturnsNull()
- {
- // TODO Placeholder
- assert false;
- }
- @Test(groups="producerMethod") @SpecAssertion(section="3.3")
- public void testDependentProducerMethodThatReturnsNull()
- {
- // TODO Placeholder
- assert false;
- }
-
@Test(groups="specialization") @SpecAssertion(section="3.3.3")
public void testSpecializedBeanAlwaysUsed()
{
@@ -64,15 +52,23 @@
@Test(groups="producerMethod") @SpecAssertion(section={"3.4", "5.6"})
- public void testProducerMethodReturnsNullIsDependent()
+ public void testProducerMethodReturnsNullIsDependent() throws Exception
{
- assert false;
+ SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
+ manager.addBean(spiderProducer);
+ Method method = SpiderProducer.class.getMethod("getNullSpider");
+ ProducerMethodBean<Spider> spiderBean = createProducerMethodBean(Spider.class, method, manager, spiderProducer);
+ Spider spider = spiderBean.create();
+ assert spider == null;
}
- @Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section={"3.4", "5.6"})
- public void testProducerMethodReturnsNullIsNotDependent()
+ @Test(groups="producerMethod", expectedExceptions=IllegalProductException.class) @SpecAssertion(section={"3.4", "5.6"})
+ public void testProducerMethodReturnsNullIsNotDependent() throws Exception
{
-
+ SimpleBean<BrokenSpiderProducer> spiderProducer = createSimpleWebBean(BrokenSpiderProducer.class, manager);
+ manager.addBean(spiderProducer);
+ Method method = BrokenSpiderProducer.class.getMethod("getRequestScopedSpider");
+ createProducerMethodBean(Spider.class, method, manager, spiderProducer).create();
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-11-06 14:40:22 UTC (rev 260)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-11-06 14:55:05 UTC (rev 261)
@@ -85,6 +85,9 @@
return new FunnelWeaver<Spider>();
}
-
+ @Produces public Spider getNullSpider()
+ {
+ return null;
+ }
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java 2008-11-06 14:40:22 UTC (rev 260)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java 2008-11-06 14:55:05 UTC (rev 261)
@@ -5,7 +5,10 @@
import javax.webbeans.Observes;
import javax.webbeans.Produces;
import javax.webbeans.Production;
+import javax.webbeans.RequestScoped;
+import org.jboss.webbeans.test.beans.Spider;
+
@Production
public class BrokenSpiderProducer
{
@@ -28,4 +31,9 @@
return "foo";
}
+ @Produces @RequestScoped public Spider getRequestScopedSpider()
+ {
+ return null;
+ }
+
}
More information about the weld-commits
mailing list