@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(); }
@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(); }