cucumber/cucumber-jvm — pull request #740 by mchenryc (2014-06-26 04:11:59+00:00)
Title: Disregard order of JSON properties in PrettyPrint unit tests

JSONPrettyFormatterTest should not rely on the order of JSON fields. Changes were made in Java 8 which change the output order of the fields, though the JSON is still valid.

This allows cucumber-core to build in Java 8.

In this change, rather than expecting exact character matching, or writing a parser that considers white-space, I have:

1. Validate the output and equality with expected output using Gson, which correctly ignores property order.
1. Split expected/actual into lines, stripping trailing commas (to hide order within objects), sort, and compare.

While not 100% infallible (two properties at different depth with the same value *could* have coincidentally swapped indentations, and still pass both comparisons), failure is extremely unlikely, and would still be valid JSON regardless.

Note this uses the Gson classes shadowed into the gherkin packages - I'm not sure how stable that is expected to be, but if it is an issue, Gson could be included as a test dependency of core without external visibility.