-
-
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: Use context.testMethod instead of context.requiredTestMethod #1643
- Loading branch information
1 parent
0423fda
commit 4a5ff59
Showing
2 changed files
with
53 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
49 changes: 49 additions & 0 deletions
49
consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/SimplePactTest.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,49 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MessagePactBuilder; | ||
import au.com.dius.pact.consumer.dsl.LambdaDsl; | ||
import au.com.dius.pact.core.model.PactSpecVersion; | ||
import au.com.dius.pact.core.model.annotations.Pact; | ||
import au.com.dius.pact.core.model.messaging.Message; | ||
import au.com.dius.pact.core.model.messaging.MessagePact; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.*; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@ExtendWith({PactConsumerTestExt.class, SamplePactTest.MyStringResolverExtension.class}) | ||
@PactTestFor(providerName = "some-provider", providerType = ProviderType.ASYNCH, pactVersion = PactSpecVersion.V3) | ||
class SamplePactTest { | ||
|
||
@BeforeAll | ||
static void setup(String injectedString) { | ||
System.out.println(injectedString); | ||
} | ||
|
||
@Pact(consumer = "some-consumer") | ||
public MessagePact someMessage(MessagePactBuilder builder) { | ||
return builder | ||
.expectsToReceive("message") | ||
.withContent(LambdaDsl.newJsonBody(object -> object.stringType("test", "Test")).build()).toPact(); | ||
} | ||
|
||
@Test | ||
@PactTestFor(pactMethod = "someMessage") | ||
void consume(List<Message> messages) { | ||
System.out.println(messages); | ||
} | ||
|
||
static class MyStringResolverExtension implements Extension, ParameterResolver { | ||
@Override | ||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return Objects.equals(parameterContext.getParameter().getType(), String.class); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return "injectedString"; | ||
} | ||
} | ||
} |