Skip to content

Commit

Permalink
Remove explicit consruction of models
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@249 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Nov 5, 2008
1 parent e25c065 commit 0412756
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 63 deletions.
Expand Up @@ -48,15 +48,6 @@ public abstract class AbstractClassBeanModel<T> extends AbstractBeanModel<T, Cla
*/
public AbstractClassBeanModel(AnnotatedClass<T> annotatedItem, AnnotatedClass<T> xmlAnnotatedItem)
{
if (annotatedItem == null)
{
throw new NullPointerException("annotatedItem must not be null. If the bean is declared just in XML, pass in an empty annotatedItem");
}

if (xmlAnnotatedItem == null)
{
throw new NullPointerException("xmlAnnotatedItem must not be null. If the bean is declared just in Java, pass in an empty xmlAnnotatedItem");
}
this.annotatedItem = annotatedItem;
this.xmlAnnotatedItem = xmlAnnotatedItem;
}
Expand Down
@@ -1,7 +1,6 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;

import java.lang.annotation.Annotation;
import java.util.HashMap;
Expand Down Expand Up @@ -80,14 +79,14 @@ public void testMultipleBindingTypes()
}

@SuppressWarnings("unchecked")
@Test @SpecAssertion(section="2.3.4")
@Test(groups="webbeansxml") @SpecAssertion(section="2.3.4")
public void testBindingTypesDeclaredInXml()
{
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
annotations.put(Asynchronous.class, new AsynchronousAnnotationLiteral());
AnnotatedClass annotatedItem = new SimpleAnnotatedClass(Antelope.class, annotations);

SimpleBeanModel<Antelope> antelope = new SimpleBeanModel<Antelope>(getEmptyAnnotatedType(Antelope.class), annotatedItem, manager);
SimpleBeanModel<Antelope> antelope = new SimpleBeanModel<Antelope>(null, annotatedItem, manager);
assert Reflections.annotationSetMatches(antelope.getBindingTypes(), Asynchronous.class);
}

Expand Down
@@ -1,7 +1,7 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void testDeploymentTypeDeclaresScopeTypeAnnotation()
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.5.3")
public void testTooManyDeploymentTypes()
{
new SimpleBeanModel<BeanWithTooManyDeploymentTypes>(new SimpleAnnotatedClass<BeanWithTooManyDeploymentTypes>(BeanWithTooManyDeploymentTypes.class), getEmptyAnnotatedType(BeanWithTooManyDeploymentTypes.class), manager);
createSimpleModel(BeanWithTooManyDeploymentTypes.class, manager);
}

@Test @SpecAssertion(section="2.5.4")
Expand All @@ -90,11 +90,11 @@ public void testXmlRespectsJavaDeploymentType()
assert tuna.getDeploymentType().equals(AnotherDeploymentType.class);
}

@Test @SpecAssertion(section="2.5.5")
@Test(groups="webbeansxml") @SpecAssertion(section="2.5.5")
public void testXmlDefaultDeploymentType()
{
AnnotatedClass<Antelope> antelopeAnnotatedItem = new SimpleAnnotatedClass<Antelope>(Antelope.class, new HashMap<Class<? extends Annotation>, Annotation>());
SimpleBeanModel<Antelope> antelope = new SimpleBeanModel<Antelope>(getEmptyAnnotatedType(Antelope.class), antelopeAnnotatedItem, manager);
SimpleBeanModel<Antelope> antelope = new SimpleBeanModel<Antelope>(null, antelopeAnnotatedItem, manager);
assert antelope.getDeploymentType().equals(Production.class);
}

Expand Down
@@ -1,7 +1,6 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;

import java.lang.annotation.Annotation;
import java.util.HashMap;
Expand Down Expand Up @@ -37,7 +36,7 @@ public void testInvalidElIdentifierUsedAsWebBeanName()
@Test @SpecAssertion(section="2.6.1")
public void testNonDefaultNamed()
{
SimpleBeanModel<Moose> moose = new SimpleBeanModel<Moose>(new SimpleAnnotatedClass<Moose>(Moose.class), getEmptyAnnotatedType(Moose.class), manager);
SimpleBeanModel<Moose> moose = createSimpleModel(Moose.class, manager);
assert moose.getName().equals("aMoose");
}

Expand Down Expand Up @@ -90,7 +89,7 @@ public void testJavaNamedUsedWhenNoXmlSpecified()
@Test @SpecAssertion(section={"2.6.3", "3.2.7"})
public void testDefaultNamed()
{
SimpleBeanModel<Haddock> haddock = new SimpleBeanModel<Haddock>(new SimpleAnnotatedClass<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), manager);
SimpleBeanModel<Haddock> haddock = createSimpleModel(Haddock.class, manager);
assert haddock.getName() != null;
assert haddock.getName().equals("haddock");
}
Expand Down Expand Up @@ -125,14 +124,14 @@ public void testSterotypeDefaultsName()
@Test @SpecAssertion(section="2.6.4")
public void testNotNamedInJava()
{
SimpleBeanModel<SeaBass> model = new SimpleBeanModel<SeaBass>(new SimpleAnnotatedClass<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), manager);
SimpleBeanModel<SeaBass> model = createSimpleModel(SeaBass.class, manager);
assert model.getName() == null;
}

@Test @SpecAssertion(section="2.6.4")
public void testNotNamedInXml()
{
SimpleBeanModel<SeaBass> model = new SimpleBeanModel<SeaBass>(new SimpleAnnotatedClass<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), manager);
SimpleBeanModel<SeaBass> model = createSimpleModel(SeaBass.class, manager);
assert model.getName() == null;
}

Expand Down
@@ -1,6 +1,6 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
import static org.jboss.webbeans.test.util.Util.createSimpleModel;

import java.lang.reflect.Method;

Expand All @@ -10,7 +10,6 @@

import org.jboss.webbeans.contexts.AbstractContext;
import org.jboss.webbeans.contexts.RequestContext;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedMethod;
import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void testReturnsCorrectExistingBean() {

@Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.1")
public void testProducerMethodReturningNullOK() throws SecurityException, NoSuchMethodException {
SimpleBeanModel<SpiderProducer> producer = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
SimpleBeanModel<SpiderProducer> producer = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(producer);
Method nullProducer = SpiderProducer.class.getMethod("produceShelob");
ProducerMethodBeanModel<Tarantula> producerModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(nullProducer), manager);
Expand Down
@@ -1,7 +1,7 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;

import java.lang.annotation.Annotation;
import java.util.HashMap;
Expand Down Expand Up @@ -67,24 +67,24 @@ public void testScopeTypeDeclaresScopeTypeAnnotation()
@Test @SpecAssertion(section="2.4.3")
public void testScopeDeclaredInJava()
{
SimpleBeanModel<SeaBass> trout = new SimpleBeanModel<SeaBass>(new SimpleAnnotatedClass<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), manager);
SimpleBeanModel<SeaBass> trout = createSimpleModel(SeaBass.class, manager);
assert trout.getScopeType().equals(RequestScoped.class);
}

@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.4.3")
public void testTooManyScopesSpecifiedInJava()
{
new SimpleBeanModel<BeanWithTooManyScopeTypes>(new SimpleAnnotatedClass<BeanWithTooManyScopeTypes>(BeanWithTooManyScopeTypes.class), getEmptyAnnotatedType(BeanWithTooManyScopeTypes.class), manager);
createSimpleModel(BeanWithTooManyScopeTypes.class, manager);
}

@Test(expectedExceptions=DefinitionException.class)
@Test(expectedExceptions=DefinitionException.class, groups="webbeansxml")
public void testTooManyScopesSpecifiedInXml()
{
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
annotations.put(RequestScoped.class, new RequestScopedAnnotationLiteral());
annotations.put(ConversationScoped.class, new ConversationScopedAnnotationLiteral());
AnnotatedClass<Antelope> antelopeAnnotatedItem = new SimpleAnnotatedClass<Antelope>(Antelope.class, annotations);
new SimpleBeanModel<Antelope>(getEmptyAnnotatedType(Antelope.class), antelopeAnnotatedItem, manager);
new SimpleBeanModel<Antelope>(null, antelopeAnnotatedItem, manager);
}

@Test @SpecAssertion(section="2.4.4")
Expand Down Expand Up @@ -121,7 +121,7 @@ public void testScopeDeclaredInXmlOverridesJava()
@Test @SpecAssertion(section="2.4.5")
public void testDefaultScope()
{
SimpleBeanModel<Order> order = new SimpleBeanModel<Order>(new SimpleAnnotatedClass<Order>(Order.class), getEmptyAnnotatedType(Order.class), manager);
SimpleBeanModel<Order> order = createSimpleModel(Order.class, manager);
assert order.getScopeType().equals(Dependent.class);
}

Expand Down
@@ -1,7 +1,7 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;

import java.lang.annotation.Annotation;
import java.util.HashMap;
Expand All @@ -16,7 +16,6 @@
import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
import org.jboss.webbeans.injectable.InjectableParameter;
import org.jboss.webbeans.injectable.SimpleConstructor;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.annotations.HeavyDuty;
import org.jboss.webbeans.test.annotations.Motorized;
Expand Down Expand Up @@ -48,26 +47,26 @@ public class SimpleBeanModelTest extends AbstractTest
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.2")
public void testAbstractClassDeclaredInJavaIsNotAllowed()
{
new SimpleBeanModel<Cow>(new SimpleAnnotatedClass<Cow>(Cow.class), getEmptyAnnotatedType(Cow.class), manager);
createSimpleModel(Cow.class, manager);
}

@Test(groups="innerClass") @SpecAssertion(section="3.2")
public void testStaticInnerClassDeclaredInJavaAllowed()
{
new SimpleBeanModel<StaticInnerBean>(new SimpleAnnotatedClass<StaticInnerBean>(StaticInnerBean.class), getEmptyAnnotatedType(StaticInnerBean.class), manager);
createSimpleModel(StaticInnerBean.class, manager);
}

@Test(expectedExceptions=DefinitionException.class, groups="innerClass") @SpecAssertion(section="3.2")
public void testNonStaticInnerClassDeclaredInJavaNotAllowed()
{
new SimpleBeanModel<InnerBean>(new SimpleAnnotatedClass<InnerBean>(InnerBean.class), getEmptyAnnotatedType(InnerBean.class), manager);
createSimpleModel(InnerBean.class, manager);
}

@SuppressWarnings("unchecked")
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.2")
public void testParameterizedClassDeclaredInJavaIsNotAllowed()
{
new SimpleBeanModel<ParameterizedBean>(new SimpleAnnotatedClass<ParameterizedBean>(ParameterizedBean.class), getEmptyAnnotatedType(ParameterizedBean.class), manager);
createSimpleModel(ParameterizedBean.class, manager);
}

@Test(expectedExceptions=DefinitionException.class, groups={"interceptors", "decorators"}) @SpecAssertion(section="3.2")
Expand Down Expand Up @@ -113,22 +112,22 @@ public void testBeanDeclaredInXmlIgnoresObserverMethodDeclaredInJava()
assert false;
}

@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.2.4")
@Test(expectedExceptions=DefinitionException.class, groups="webbeansxml") @SpecAssertion(section="3.2.4")
public void testAbstractClassDeclaredInXmlIsNotAllowed()
{
new SimpleBeanModel<Cow>(new SimpleAnnotatedClass<Cow>(Cow.class), getEmptyAnnotatedType(Cow.class), manager);

}

@Test(groups="innerClass") @SpecAssertion(section="3.2.4")
@Test(groups={"innerClass", "webbeansxml"}) @SpecAssertion(section="3.2.4")
public void testStaticInnerClassDeclaredInXmlAllowed()
{
new SimpleBeanModel<StaticInnerBean>(new SimpleAnnotatedClass<StaticInnerBean>(StaticInnerBean.class), getEmptyAnnotatedType(StaticInnerBean.class), manager);
assert false;
}

@Test(expectedExceptions=DefinitionException.class, groups="innerClass") @SpecAssertion(section="3.2.4")
@Test(expectedExceptions=DefinitionException.class, groups={"innerClass", "webbeansxml"}) @SpecAssertion(section="3.2.4")
public void testNonStaticInnerClassDeclaredInXmlNotAllowed()
{
new SimpleBeanModel<InnerBean>(new SimpleAnnotatedClass<InnerBean>(InnerBean.class), getEmptyAnnotatedType(InnerBean.class), manager);
assert false;
}

@Test(expectedExceptions=DefinitionException.class, groups="webbeansxml") @SpecAssertion(section="3.2.4")
Expand All @@ -152,7 +151,7 @@ public void testClassHasDecoratorInJavaMustHaveDecoratorInXml()
@Test @SpecAssertion(section="3.2.5.1")
public void testInitializerAnnotatedConstructor()
{
SimpleConstructor<Sheep> constructor = new SimpleBeanModel<Sheep>(new SimpleAnnotatedClass<Sheep>(Sheep.class), getEmptyAnnotatedType(Sheep.class), manager).getConstructor();
SimpleConstructor<Sheep> constructor = createSimpleModel(Sheep.class, manager).getConstructor();
assert constructor.getAnnotatedItem().getDelegate().getDeclaringClass().equals(Sheep.class);
assert constructor.getAnnotatedItem().getDelegate().getParameterTypes().length == 2;
assert constructor.getAnnotatedItem().getDelegate().getParameterTypes()[0].equals(String.class);
Expand All @@ -175,7 +174,7 @@ public void testInitializerAnnotatedConstructor()
@Test @SpecAssertion(section="3.2.5.1")
public void testImplicitConstructorUsed()
{
SimpleConstructor<Order> constructor = new SimpleBeanModel<Order>(new SimpleAnnotatedClass<Order>(Order.class), getEmptyAnnotatedType(Order.class), manager).getConstructor();
SimpleConstructor<Order> constructor = createSimpleModel(Order.class, manager).getConstructor();
assert constructor.getAnnotatedItem().getDelegate().getDeclaringClass().equals(Order.class);
assert constructor.getAnnotatedItem().getDelegate().getParameterTypes().length == 0;
assert constructor.getParameters().size() == 0;
Expand All @@ -184,7 +183,7 @@ public void testImplicitConstructorUsed()
@Test @SpecAssertion(section="3.2.5.1")
public void testEmptyConstructorUsed()
{
SimpleConstructor<Donkey> constructor = new SimpleBeanModel<Donkey>(new SimpleAnnotatedClass<Donkey>(Donkey.class), getEmptyAnnotatedType(Donkey.class), manager).getConstructor();
SimpleConstructor<Donkey> constructor = createSimpleModel(Donkey.class, manager).getConstructor();
assert constructor.getAnnotatedItem().getDelegate().getDeclaringClass().equals(Donkey.class);
assert constructor.getAnnotatedItem().getDelegate().getParameterTypes().length == 0;
assert constructor.getParameters().size() == 0;
Expand All @@ -193,7 +192,7 @@ public void testEmptyConstructorUsed()
@Test @SpecAssertion(section="3.2.5.1")
public void testInitializerAnnotatedConstructorUsedOverEmptyConstuctor()
{
SimpleConstructor<Turkey> constructor = new SimpleBeanModel<Turkey>(new SimpleAnnotatedClass<Turkey>(Turkey.class), getEmptyAnnotatedType(Turkey.class), manager).getConstructor();
SimpleConstructor<Turkey> constructor = createSimpleModel(Turkey.class, manager).getConstructor();
assert constructor.getParameters().size() == 2;
Map<Class<?>, Set<? extends Annotation>> map = new HashMap<Class<?>, Set<? extends Annotation>>();
for (InjectableParameter<Object> parameter : constructor.getParameters())
Expand Down Expand Up @@ -225,17 +224,13 @@ public void testConstructorHasObservesParameter()
@Test(groups="webbeansxml") @SpecAssertion(section="3.2.5.2")
public void testImplicitConstructorDeclaredInXmlUsed()
{
SimpleConstructor<Order> constructor = new SimpleBeanModel<Order>(new SimpleAnnotatedClass<Order>(Order.class), getEmptyAnnotatedType(Order.class), manager).getConstructor();
assert constructor.getAnnotatedItem().getDelegate().getDeclaringClass().equals(Order.class);
assert constructor.getAnnotatedItem().getDelegate().getParameterTypes().length == 0;
assert constructor.getParameters().size() == 0;
assert false;
}

@Test(groups="webbeansxml") @SpecAssertion(section="3.2.5.2")
public void testEmptyConstructorDeclaredInXmlUsed()
{
SimpleConstructor<Donkey> constructor = new SimpleBeanModel<Donkey>(new SimpleAnnotatedClass<Donkey>(Donkey.class), getEmptyAnnotatedType(Donkey.class), manager).getConstructor(); assert constructor.getAnnotatedItem().getDelegate().getDeclaringClass().equals(Order.class);
SimpleConstructor<Donkey> constructor = createSimpleModel(Donkey.class, manager).getConstructor();
assert constructor.getAnnotatedItem().getDelegate().getParameterTypes().length == 0;
assert constructor.getParameters().size() == 0;
assert false;
Expand All @@ -256,7 +251,7 @@ public void testConstructorDeclaredInXmlIgnoresBindingTypesDeclaredInJava()
@Test @SpecAssertion(section="3.2.5.3")
public void testBindingTypeAnnotatedConstructor()
{
SimpleConstructor<Duck> constructor = new SimpleBeanModel<Duck>(new SimpleAnnotatedClass<Duck>(Duck.class), getEmptyAnnotatedType(Duck.class), manager).getConstructor();
SimpleConstructor<Duck> constructor = createSimpleModel(Duck.class, manager).getConstructor();
assert constructor.getAnnotatedItem().getDelegate().getDeclaringClass().equals(Duck.class);
assert constructor.getParameters().size() == 2;
Map<Class<?>, Set<? extends Annotation>> map = new HashMap<Class<?>, Set<? extends Annotation>>();
Expand All @@ -275,7 +270,7 @@ public void testBindingTypeAnnotatedConstructor()
@Test(groups="specialization") @SpecAssertion(section="3.2.6")
public void testSpecializedClassInheritsBindingTypes()
{
SimpleBeanModel<Tractor> bean = new SimpleBeanModel<Tractor>(new SimpleAnnotatedClass<Tractor>(Tractor.class), getEmptyAnnotatedType(Tractor.class), manager);
SimpleBeanModel<Tractor> bean = createSimpleModel(Tractor.class, manager);
assert bean.getBindingTypes().size()==2;
assert bean.getBindingTypes().contains( new AnnotationLiteral<Motorized>() {} );
assert bean.getBindingTypes().contains( new AnnotationLiteral<HeavyDuty>() {} );
Expand All @@ -284,7 +279,7 @@ public void testSpecializedClassInheritsBindingTypes()
@Test(groups="specialization") @SpecAssertion(section="3.2.6")
public void testSpecializedClassInheritsName()
{
SimpleBeanModel<Tractor> bean = new SimpleBeanModel<Tractor>(new SimpleAnnotatedClass<Tractor>(Tractor.class), getEmptyAnnotatedType(Tractor.class), manager);
SimpleBeanModel<Tractor> bean = createSimpleModel(Tractor.class, manager);
assert bean.getName()!=null;
assert bean.getName().equals("plough");
}
Expand Down

0 comments on commit 0412756

Please sign in to comment.