@Test
public void testToJson() throws IOException {

  // We lack a proper JSON parser in the vanilla JRE so short of string matching there's nothing
  // that can be done here other than to ensure the output is non-null and looks kind of sane.
  PatchExplanation patchExplanation = new PatchExplanation(ALL_EXPLANATIONS);
  try (ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      PrintWriter writer = new PrintWriter(buffer)) {
    patchExplanation.writeJson(writer);
    writer.flush();
    String asString = buffer.toString();
    Assert.assertTrue(asString.startsWith("{"));
    Assert.assertFalse(asString.isEmpty());
    for (EntryExplanation explanation : ALL_EXPLANATIONS) {
      Assert.assertTrue(asString.contains(new String(explanation.getPath().getData(), "UTF-8")));
    }
    Assert.assertTrue(asString.endsWith("}"));
  }
}