-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not greedily inject @ParameterizedTest; instead treat is as explic…
…it param. injection
- Loading branch information
Showing
6 changed files
with
81 additions
and
1 deletion.
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
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
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
15 changes: 15 additions & 0 deletions
15
junit5/src/test/java/org/jboss/weld/junit5/explicitInjection/parameterizedTest/Foo.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,15 @@ | ||
package org.jboss.weld.junit5.explicitInjection.parameterizedTest; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
public class Foo { | ||
|
||
@Produces | ||
String s = "fooString"; | ||
|
||
String ping() { | ||
return Foo.class.getSimpleName(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ld/junit5/explicitInjection/parameterizedTest/ParameterizedTestExplicitInjectionTest.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,46 @@ | ||
package org.jboss.weld.junit5.explicitInjection.parameterizedTest; | ||
|
||
import java.util.Set; | ||
|
||
import jakarta.enterprise.inject.Default; | ||
|
||
import org.jboss.weld.junit5.WeldJunit5Extension; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
@ExtendWith(WeldJunit5Extension.class) | ||
public class ParameterizedTestExplicitInjectionTest { | ||
|
||
public static final Set<String> strings = Set.of("one", "two", "three"); | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "one", "two", "three" }) | ||
public void noWeldInjection(String param) { | ||
// String param is not resolved by Weld | ||
Assertions.assertTrue(strings.contains(param)); | ||
} | ||
|
||
// NOTE: swapping parameters in the below tests leads to a failure! Parameterized test attempts to claim the first | ||
// parameter as its own and cast to given type; there is nothing we can do about that | ||
@ParameterizedTest | ||
@ValueSource(strings = { "one", "two", "three" }) | ||
public void parameterizedTestWithWeldInjection(String param, @Default Foo foo) { | ||
// String param is not resolved by Weld | ||
Assertions.assertTrue(strings.contains(param)); | ||
// Foo has explicit qualifier and Weld therefore still tried to resolve it | ||
Assertions.assertNotNull(foo); | ||
Assertions.assertEquals(Foo.class.getSimpleName(), foo.ping()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "one", "two", "three" }) | ||
public void parameterizedTestWithTwoStringParams(String param, @Default String anotherString) { | ||
// String param is not resolved by Weld | ||
Assertions.assertTrue(strings.contains(param)); | ||
// Foo has explicit qualifier and Weld therefore still tried to resolve it | ||
Assertions.assertNotNull(anotherString); | ||
Assertions.assertEquals("fooString", anotherString); | ||
} | ||
} |
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