diff --git a/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt b/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt index ec6988b..c145b90 100644 --- a/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt +++ b/ktest-integration/ktest-json-matchers/src/test/kotlin/run/smt/ktest/json/matcher/JsonDiffSpec.kt @@ -56,6 +56,19 @@ object JsonDiffSpec : WordSpec({ assertThat(diff, isEmpty) } + "not return mismatch for arrays containing equal objects with different field order" { + val firstJson = "json-with-array-of-objects1.json".loadAsJsonTree() + val secondJson = "json-with-array-of-objects2.json".loadAsJsonTree() + + val comparator = jsonComparator { + compareArraysUnordered() + } + + val diff = comparator.diff(firstJson, secondJson) + + assertThat(diff, isEmpty) + } + "not return mismatch for permutation-based array comparison on arrays with different sort order" { val firstJson = "json-with-array.json".loadAsJsonTree() val secondJson = "json-with-array-reversed.json".loadAsJsonTree() diff --git a/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json new file mode 100644 index 0000000..1b513d2 --- /dev/null +++ b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects1.json @@ -0,0 +1,12 @@ +{ + "myArray": [ + { + "a": 1, + "z": 1 + }, + { + "a": 2, + "z": 2 + } + ] +} diff --git a/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json new file mode 100644 index 0000000..d1d057a --- /dev/null +++ b/ktest-integration/ktest-json-matchers/src/test/resources/json-with-array-of-objects2.json @@ -0,0 +1,12 @@ +{ + "myArray": [ + { + "a": 2, + "z": 2 + }, + { + "z": 1, + "a": 1 + } + ] +}