Skip to content

Instantly share code, notes, and snippets.

Last active December 21, 2022 08:47
What would you like to do?
JUnit5 style Pact Consumer
public class PactConsumerJUnit5Test {
@Pact(provider = "UserServiceJUnit5", consumer = "UserConsumer")
public V4Pact getAllUsers(PactBuilder builder) {
String expectedUsers = """
"id": 1,
"name": "Jane Doe"
"id": 2,
"name": "John Doe"
return builder
.given("A running user service")
.uponReceiving("A request for a user list")
.headers(Map.of("Content-Type", "application/json"))
@PactTestFor(providerName = "UserServiceJUnit5", pactMethod = "getAllUsers")
void getAllUsers(MockServer mockServer) {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri(mockServer.getUrl()).build();
User[] response = restTemplate.getForObject("/users", User[].class);
new User(1, "Jane Doe"),
new User(2, "John Doe")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment