-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: PactVerificationExtension will fail when used with other extensi…
…ons in a static context #1666
- Loading branch information
1 parent
3010a10
commit 5bc8bc6
Showing
2 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
63 changes: 63 additions & 0 deletions
63
...er/junit5/src/test/java/au/com/dius/pact/provider/junit5/WithRegisteredExtensionTest.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,63 @@ | ||
package au.com.dius.pact.provider.junit5; | ||
|
||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.State; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder; | ||
import org.junit.jupiter.api.extension.Extension; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
@Provider("myAwesomeService") | ||
@PactFolder("pacts") | ||
public class WithRegisteredExtensionTest { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(WithRegisteredExtensionTest.class); | ||
|
||
@RegisterExtension | ||
static final TestDependencyResolver resolverExt = new TestDependencyResolver(/*...*/); | ||
|
||
private final TestDependency dependency; | ||
|
||
public WithRegisteredExtensionTest(TestDependency dependency) { | ||
this.dependency = dependency; | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
void test() { | ||
assertThat(dependency, is(notNullValue())); | ||
} | ||
|
||
@State("state 2") | ||
void state2() { | ||
} | ||
|
||
@State("default") | ||
void stateDefault() { | ||
} | ||
|
||
static class TestDependencyResolver implements Extension, ParameterResolver { | ||
@Override | ||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return parameterContext.getParameter().getType().isAssignableFrom(TestDependency.class); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return new TestDependency(); | ||
} | ||
} | ||
|
||
static class TestDependency { | ||
} | ||
} |