@SuppressWarnings("unchecked")
 @Test
 @SpecAssertions({
   @SpecAssertion(section = DECORATOR_RESOLUTION, id = "b"),
   @SpecAssertion(section = PROCESS_ANNOTATED_TYPE, id = "bc"),
   @SpecAssertion(section = AFTER_BEAN_DISCOVERY, id = "dc")
 })
 public void testCustomImplementationOfDecoratorInterface() {
   assert getContextualReference(Vehicle.class).start().equals("Bus started and decorated.");
   assert getContextualReference(Vehicle.class).stop().equals("Bus stopped and decorated.");
   assert AfterBeanDiscoveryObserver.getDecorator().isGetDecoratedTypesCalled();
   assert AfterBeanDiscoveryObserver.getDecorator().isGetDelegateQualifiersCalled();
   assert AfterBeanDiscoveryObserver.getDecorator().isGetDelegateTypeCalled();
   assert !getCurrentManager()
       .resolveDecorators(new HashSet<Type>(Arrays.asList(Vehicle.class)))
       .isEmpty();
   assert !getCurrentManager()
       .resolveDecorators(new HashSet<Type>(Arrays.asList(Vehicle.class, Bus.class)))
       .isEmpty();
 }
Example #2
0
  @Test
  @SpecAssertion(section = CONTEXT, id = "nb")
  public void testGetMayNotReturnNullUnlessContextualCreateReturnsNull() {
    // The case of no creational context is already tested where a null is
    // returned. Here we just test that the contextual create can return null.
    MyContextual bean = AfterBeanDiscoveryObserver.getBean();
    bean.setShouldReturnNullInstances(true);

    CreationalContext<MySessionBean> creationalContext = new MockCreationalContext<MySessionBean>();
    assert getCurrentManager().getContext(SessionScoped.class).get(bean, creationalContext) == null;
    assert bean.isCreateCalled();
  }
Example #3
0
  @Test
  @SpecAssertions({@SpecAssertion(section = CONTEXT, id = "l")})
  public void testGetWithCreationalContextReturnsNewInstance() {
    MyContextual bean = AfterBeanDiscoveryObserver.getBean();
    bean.setShouldReturnNullInstances(false);

    CreationalContext<MySessionBean> creationalContext = new MockCreationalContext<MySessionBean>();
    MySessionBean newBean =
        getCurrentManager().getContext(SessionScoped.class).get(bean, creationalContext);
    assert newBean != null;
    assert bean.isCreateCalled();
  }