Skip to content

Commit

Permalink
replace usages of MockCreationalContext with the CreationalContexts SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek authored and manovotn committed Sep 21, 2023
1 parent 770c00e commit cdb3e80
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import static org.jboss.cdi.tck.cdi.Sections.CONTEXT;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.context.spi.Context;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.Bean;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.util.MockCreationalContext;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand All @@ -51,19 +49,18 @@ public static WebArchive createTestArchive() {
@Test
@SpecAssertion(section = CONTEXT, id = "r")
public void testDestroyForSameCreationalContextOnly() {
// Check that the mock cc is called (via cc.release()) when we request a context destroyed
// Check that the cc is called (via cc.release()) when we request a context destroyed
// Note that this is an indirect effect
Context requestContext = getCurrentManager().getContext(RequestScoped.class);

Bean<AnotherRequestBean> requestBean = getBeans(AnotherRequestBean.class).iterator().next();

MockCreationalContext.reset();
CreationalContext<AnotherRequestBean> creationalContext = new MockCreationalContext<AnotherRequestBean>();
CreationalContexts.Inspectable<AnotherRequestBean> creationalContext = createInspectableCreationalContext(requestBean);
AnotherRequestBean instance = requestContext.get(requestBean, creationalContext);
instance.ping();

destroyContext(requestContext);
assert MockCreationalContext.isReleaseCalled();
assert creationalContext.isReleaseCalled();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static WebArchive createTestArchive() {
@Test(groups = CDI_FULL)
@SpecAssertion(section = CONTEXT, id = "r")
public void testDestroyForSameCreationalContextOnly() {
// Check that the mock cc is called (via cc.release()) when we request a context destroyed
// Check that the cc is called (via cc.release()) when we request a context destroyed
// Note that this is an indirect effect
Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
Context requestContext = getCurrentManager().getContext(RequestScoped.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.context.spi.Context;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.Bean;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.TestGroups;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.util.MockCreationalContext;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand All @@ -34,19 +33,18 @@ public static WebArchive createTestArchive() {
@Test(groups = TestGroups.CDI_FULL)
@SpecAssertion(section = CONTEXT, id = "r")
public void testDestroyForSameCreationalContextOnly() {
// Check that the mock cc is called (via cc.release()) when we request a context destroyed
// Check that the cc is called (via cc.release()) when we request a context destroyed
// Note that this is an indirect effect
Context sessionContext = getCurrentManager().getContext(SessionScoped.class);

Bean<AnotherSessionBean> sessionBean = getBeans(AnotherSessionBean.class).iterator().next();

MockCreationalContext.reset();
CreationalContext<AnotherSessionBean> creationalContext = new MockCreationalContext<AnotherSessionBean>();
CreationalContexts.Inspectable<AnotherSessionBean> creationalContext = createInspectableCreationalContext(sessionBean);
AnotherSessionBean instance = sessionContext.get(sessionBean, creationalContext);
instance.ping();

destroyContext(sessionContext);
assert MockCreationalContext.isReleaseCalled();
assert creationalContext.isReleaseCalled();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.jboss.cdi.tck.cdi.Sections.MANAGED_BEAN_LIFECYCLE;
import static org.jboss.cdi.tck.cdi.Sections.MEMBER_LEVEL_INHERITANCE;
import static org.jboss.cdi.tck.cdi.Sections.METHOD_CONSTRUCTOR_PARAMETER_QUALIFIERS;
import static org.jboss.cdi.tck.cdi.Sections.PASSIVATION_CAPABLE_DEPENDENCY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
Expand All @@ -50,8 +49,8 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.util.DependentInstance;
import org.jboss.cdi.tck.util.MockCreationalContext;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
Expand Down Expand Up @@ -87,12 +86,11 @@ public void testQualifierTypeAnnotatedConstructor() {
@Test
@SpecAssertions({ @SpecAssertion(section = CREATIONAL_CONTEXT, id = "d"), @SpecAssertion(section = CREATIONAL_CONTEXT, id = "g") })
public void testCreateReturnsSameBeanPushed() {
final CreationalContext<ShoeFactory> creationalContext = new MockCreationalContext<ShoeFactory>();
final Contextual<ShoeFactory> bean = getBeans(ShoeFactory.class).iterator().next();
MockCreationalContext.reset();
final CreationalContexts.Inspectable<ShoeFactory> creationalContext = createInspectableCreationalContext(bean);
ShoeFactory instance = getCurrentManager().getContext(Dependent.class).get(bean, creationalContext);
if (MockCreationalContext.isPushCalled()) {
assert instance == MockCreationalContext.getLastBeanPushed();
if (creationalContext.isPushCalled()) {
assert instance == creationalContext.getLastBeanPushed();
}
}

Expand Down

0 comments on commit cdb3e80

Please sign in to comment.