Skip to content

Commit ec77d2d

Browse files
author
Ronald Holshausen
authoredFeb 16, 2020
Merge branch 'master' into verbose-pact-sources
2 parents 6ef40a5 + 3d4bc07 commit ec77d2d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed
 

‎consumer/pact-jvm-consumer-junit/src/test/groovy/au/com/dius/pact/consumer/MessagePactBuilderSpec.groovy

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package au.com.dius.pact.consumer
33
import au.com.dius.pact.consumer.dsl.Matchers
44
import au.com.dius.pact.consumer.dsl.PactDslJsonBody
55
import au.com.dius.pact.core.model.messaging.Message
6+
import au.com.dius.pact.core.model.ProviderState
67
import groovy.json.JsonSlurper
78
import spock.lang.Issue
89
import spock.lang.Specification
@@ -117,4 +118,33 @@ class MessagePactBuilderSpec extends Specification {
117118
messageMetadata == [contentType: 'application/json', otherValue: 10L]
118119
}
119120

121+
def 'provider state can accept key/value pairs'() {
122+
given:
123+
def description = 'some state description'
124+
def params = ['stateKey': 'stateValue']
125+
def expectedProviderState = new ProviderState(description, params)
126+
127+
when:
128+
def pact = MessagePactBuilder
129+
.consumer('MessagePactBuilderSpec')
130+
.given(description, params)
131+
132+
then:
133+
pact.providerStates.last() == expectedProviderState
134+
}
135+
136+
def 'provider state can accept ProviderState object'() {
137+
given:
138+
def description = 'some state description'
139+
def params = ['stateKey': 'stateValue']
140+
def expectedProviderState = new ProviderState(description, params)
141+
142+
when:
143+
def pact = MessagePactBuilder
144+
.consumer('MessagePactBuilderSpec')
145+
.given(expectedProviderState)
146+
147+
then:
148+
pact.providerStates.last() == expectedProviderState
149+
}
120150
}

‎consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/MessagePactBuilder.kt

+24-1
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,37 @@ class MessagePactBuilder(
5050
/**
5151
* Sets the provider state.
5252
*
53-
* @param providerState state of the provider
53+
* @param providerState description of the provider state
5454
* @return this builder.
5555
*/
5656
fun given(providerState: String): MessagePactBuilder {
5757
this.providerStates.add(ProviderState(providerState))
5858
return this
5959
}
6060

61+
/**
62+
* Sets the provider state.
63+
*
64+
* @param providerState description of the provider state
65+
* @param params key/value pairs to describe state
66+
* @return this builder.
67+
*/
68+
fun given(providerState: String, params: Map<String, Any>): MessagePactBuilder {
69+
this.providerStates.add(ProviderState(providerState, params))
70+
return this
71+
}
72+
73+
/**
74+
* Sets the provider state.
75+
*
76+
* @param providerState state of the provider
77+
* @return this builder.
78+
*/
79+
fun given(providerState: ProviderState): MessagePactBuilder {
80+
this.providerStates.add(providerState)
81+
return this
82+
}
83+
6184
/**
6285
* Adds a message expectation in the pact.
6386
*

0 commit comments

Comments
 (0)
Please sign in to comment.