-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not inject String.class without explicit binging (#5)
Do not inject String without explicit binding to fix parametrized tests.
- Loading branch information
1 parent
449d119
commit 89fa6cb
Showing
8 changed files
with
156 additions
and
22 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
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
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
99 changes: 99 additions & 0 deletions
99
...test/java/name/falgout/jeffrey/testing/junit/guice/ParametrizedTestCompatibilityTest.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,99 @@ | ||
package name.falgout.jeffrey.testing.junit.guice; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.name.Named; | ||
import com.google.inject.name.Names; | ||
import name.falgout.jeffrey.testing.junit.testing.ExpectFailure; | ||
import name.falgout.jeffrey.testing.junit.testing.ExpectFailure.Cause; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
|
||
public class ParametrizedTestCompatibilityTest { | ||
static final class TestModule extends AbstractModule { | ||
static final String STRING = "testModuleString"; | ||
|
||
@Override | ||
protected void configure() { | ||
bind(String.class).toInstance(STRING); | ||
bind(String.class).annotatedWith(Names.named("named")).toInstance(STRING); | ||
bind(String.class).annotatedWith(SomeBindingAnnotation.class).toInstance(STRING); | ||
bind(String.class).annotatedWith(SomeQualifyingAnnotation.class).toInstance(STRING); | ||
} | ||
} | ||
|
||
@Nested | ||
class PositiveCases { | ||
|
||
@ExtendWith(GuiceExtension.class) | ||
@ParameterizedTest | ||
@ValueSource(strings = "valueSourceString") | ||
void parametrizedTestWithStringsShouldWorkWithGuiceExtension(String value) { | ||
assertEquals("valueSourceString", value); | ||
} | ||
|
||
@ExtendWith(GuiceExtension.class) | ||
@ParameterizedTest | ||
@ValueSource(classes = Integer.class) | ||
void parametrizedTestWithoutStringsShouldWorkWithGuiceExtension(Class<Object> clazz) { | ||
assertSame(Integer.class, clazz); | ||
} | ||
} | ||
|
||
@Nested | ||
class NegativeCases { | ||
@ExpectFailure( | ||
@Cause( | ||
type = ParameterResolutionException.class, | ||
message = "Discovered multiple competing ParameterResolvers" | ||
) | ||
) | ||
@IncludeModule(TestModule.class) | ||
@ParameterizedTest | ||
@ValueSource(strings = "valueSourceString") | ||
void explicitBindingStringShouldConflictWithValueSource(String value) { | ||
} | ||
|
||
@ExpectFailure( | ||
@Cause( | ||
type = ParameterResolutionException.class, | ||
message = "Discovered multiple competing ParameterResolvers" | ||
) | ||
) | ||
@IncludeModule(TestModule.class) | ||
@ParameterizedTest | ||
@ValueSource(strings = "valueSourceString") | ||
void explicitBindingStringShouldConflictWithValueSource2(@SomeBindingAnnotation String value) { | ||
} | ||
|
||
@ExpectFailure( | ||
@Cause( | ||
type = ParameterResolutionException.class, | ||
message = "Discovered multiple competing ParameterResolvers" | ||
) | ||
) | ||
@IncludeModule(TestModule.class) | ||
@ParameterizedTest | ||
@ValueSource(strings = "valueSourceString") | ||
void explicitBindingStringShouldConflictWithValueSource3(@SomeQualifyingAnnotation String value) { | ||
} | ||
|
||
@ExpectFailure( | ||
@Cause( | ||
type = ParameterResolutionException.class, | ||
message = "Discovered multiple competing ParameterResolvers" | ||
) | ||
) | ||
@IncludeModule(TestModule.class) | ||
@ParameterizedTest | ||
@ValueSource(strings = "valueSourceString") | ||
void explicitBindingStringShouldConflictWithValueSource4(@Named("named") String value) { | ||
} | ||
} | ||
} |
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