diff --git a/core/model/src/main/kotlin/au/com/dius/pact/core/model/ProviderState.kt b/core/model/src/main/kotlin/au/com/dius/pact/core/model/ProviderState.kt index f1e85cfd8..407c64b13 100644 --- a/core/model/src/main/kotlin/au/com/dius/pact/core/model/ProviderState.kt +++ b/core/model/src/main/kotlin/au/com/dius/pact/core/model/ProviderState.kt @@ -38,8 +38,8 @@ data class ProviderState @JvmOverloads constructor(val name: String?, val params fun uniqueKey(): Int { val builder = HashCodeBuilder().append(name) - for (param in params) { - builder.append(param.key) + for (param in params.keys.sorted()) { + builder.append(param) } return builder.toHashCode() } diff --git a/core/model/src/test/groovy/au/com/dius/pact/core/model/ProviderStateSpec.groovy b/core/model/src/test/groovy/au/com/dius/pact/core/model/ProviderStateSpec.groovy index 6a8acb35a..2408a231c 100644 --- a/core/model/src/test/groovy/au/com/dius/pact/core/model/ProviderStateSpec.groovy +++ b/core/model/src/test/groovy/au/com/dius/pact/core/model/ProviderStateSpec.groovy @@ -1,5 +1,6 @@ package au.com.dius.pact.core.model +import spock.lang.Issue import spock.lang.Specification import spock.lang.Unroll @@ -41,4 +42,21 @@ class ProviderStateSpec extends Specification { state1.uniqueKey() != state3.uniqueKey() state1.uniqueKey() != state4.uniqueKey() } + + @Issue("#1717") + def 'uniqueKey should be deterministic'() { + given: + def state = new ProviderState('a user profile exists', [ + email_address: 'test@email.com', + family_name: 'Test' + ]) + def state2 = new ProviderState('a user profile exists', [ + family_name: 'Test', + email_address: 'test@email.com' + ]) + + expect: + state.uniqueKey() == state.uniqueKey() + state.uniqueKey() == state2.uniqueKey() + } }