Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cdi2] Correctly cast the UnmanagedInstance values #2244

Merged
merged 7 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cdi2/src/main/java/io/cucumber/cdi2/Cdi2Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public boolean addClass(final Class<?> clazz) {

@Override
public <T> T getInstance(final Class<T> type) {
final Object instance = standaloneInstances.get(type);
final Unmanaged.UnmanagedInstance<?> instance = standaloneInstances.get(type);
if (instance != null) {
return type.cast(instance);
return type.cast(instance.get());
}
final Instance<T> selected = container.select(type);
if (selected.isUnsatisfied()) {
Expand Down
15 changes: 9 additions & 6 deletions cdi2/src/test/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all" version="2.0">
<!-- Exclude the class to force it to be loaded as an unmanaged dependency -->
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
<scan>
<exclude
name="io.cucumber.cdi2.CdiBellyStepDefinitions" />
</scan>
</beans>
7 changes: 6 additions & 1 deletion cdi2/src/test/resources/io/cucumber/cdi2/cukes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ Feature: Cukes

Scenario: Eat some more cukes
Given I have 6 cukes in my belly
Then there are 6 cukes in my belly
Then there are 6 cukes in my belly

Scenario: Eat some cukes multiple times
Given I have 8 cukes in my belly
And I have 8 cukes in my belly
Then there are 8 cukes in my belly