-
-
Save ppazos/78b85f5db9da0e525388aedc480bfce7 to your computer and use it in GitHub Desktop.
Groovy script to find out the difference between two maps. Can be useful to debug failing unit tests when the objects in comparison are big jsons.
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
def mapDiff(Map m1, Map m2, String path="") { m1.each{k,v-> | |
if(m2[k] != m1[k]) { | |
if(m1[k] in Map) { | |
mapDiff(m1[k] as Map, m2[k] as Map, "${path}${k}.") | |
} | |
else { | |
println("${path}${k} ->"); | |
println("\texpected: ${m1[k]}") | |
println("\tactual: ${m2[k]}") | |
if (m1[k] in List) { | |
print("\texpected but missing elements: ") | |
m1[k].each { | |
if(!m2[k].any{it1->return it1==it}) { | |
print(it + ", ") | |
} | |
} | |
print("\tnot expected but found: ") | |
m2[k].each { | |
if(!m1[k].any{it1->return it1==it}) { | |
print(it + ", ") | |
} | |
} | |
} | |
println("") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment