-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-2757 Support inspectable CC impl for CDI TCK SPI
- Loading branch information
Showing
3 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
porting-package/src/main/java/org/jboss/weld/tck/CreationalContextsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.jboss.weld.tck; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.spi.Contextual; | ||
|
||
import org.jboss.cdi.tck.spi.CreationalContexts; | ||
import org.jboss.weld.contexts.CreationalContextImpl; | ||
|
||
public class CreationalContextsImpl implements CreationalContexts { | ||
@Override | ||
public <T> Inspectable<T> create(Contextual<T> contextual) { | ||
return new InspectableCreationalContext<>(contextual); | ||
} | ||
|
||
private class InspectableCreationalContext<T> extends CreationalContextImpl<T> implements Inspectable<T> { | ||
private List<Object> beansPushed = new ArrayList<>(); | ||
private Object lastBeanPushed = null; | ||
private boolean pushCalled = false; | ||
private boolean releaseCalled = false; | ||
|
||
public InspectableCreationalContext(Contextual<T> contextual) { | ||
super(contextual); | ||
} | ||
|
||
public void push(T incompleteInstance) { | ||
pushCalled = true; | ||
lastBeanPushed = incompleteInstance; | ||
beansPushed.add(incompleteInstance); | ||
super.push(incompleteInstance); | ||
} | ||
|
||
public Object getLastBeanPushed() { | ||
return lastBeanPushed; | ||
} | ||
|
||
public boolean isPushCalled() { | ||
return pushCalled; | ||
} | ||
|
||
public boolean isReleaseCalled() { | ||
return releaseCalled; | ||
} | ||
|
||
/** | ||
* We need to override this method because internally, Weld uses this enhanced method to release CCs so long | ||
* as the CC is instance of {@link org.jboss.weld.contexts.WeldCreationalContext} which will hold true for | ||
* this impl as well. | ||
*/ | ||
public void release(Contextual<T> contextual, T instance) { | ||
releaseCalled = true; | ||
super.release(contextual, instance); | ||
} | ||
|
||
public void release() { | ||
releaseCalled = true; | ||
super.release(); | ||
} | ||
|
||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
porting-package/src/main/resources/META-INF/cdi-tck.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# CDI TCK configuration - porting package | ||
org.jboss.cdi.tck.spi.Beans=org.jboss.weld.tck.BeansImpl | ||
org.jboss.cdi.tck.spi.Contexts=org.jboss.weld.tck.ContextsImpl | ||
org.jboss.cdi.tck.spi.EL=org.jboss.weld.tck.ELImpl | ||
org.jboss.cdi.tck.spi.EL=org.jboss.weld.tck.ELImpl | ||
org.jboss.cdi.tck.spi.CreationalContexts=org.jboss.weld.tck.CreationalContextsImpl |