### Question:
JsonReformatter { public static String reformat(String json) { try { return reformat0(json); } catch (IOException e) { throw new RuntimeException(e); } } private  JsonReformatter(); static String reformat(String json);  }### Answer:
@Test public void splitsUpDotsIfTheyAreCommonBetweenKeysInSameObject() { String before = "{\"foo.one\":1, \"foo.two\":2}"; String after = JsonReformatter.reformat(before); String actual = removeWhiteSpace(after); assertThat(actual, is("{\"foo\":{\"one\":1,\"two\":2}}")); }
@Test public void splitsUpDotsIfTheyAreCommonBetweenKeysInSameObjectWhenThereIsAnotherRootValue() { String before = "{\"foo.one\":1, \"foo.two\":2, \"bar\":3}"; String after = JsonReformatter.reformat(before); String actual = removeWhiteSpace(after); assertThat(actual, is("{\"bar\":3,\"foo\":{\"one\":1,\"two\":2}}")); }
@Test public void doesNotSplitUpDotsIfTheyAreNotCommonBetweenKeysInSameObject() { String before = "{\"foo.one\":1, \"bar.two\":2}"; String after = JsonReformatter.reformat(before); String actual = removeWhiteSpace(after); assertThat(actual, is("{\"bar.two\":2,\"foo.one\":1}")); }
@Test public void doesNotSplitUpDotsIfTheyAreNotCommonBetweenKeysInSameObjectWhenThereIsAnotherRootValue() { String before = "{\"foo.one\":1, \"bar.two\":2, \"baz\":3}"; String after = JsonReformatter.reformat(before); String actual = removeWhiteSpace(after); assertThat(actual, is("{\"bar.two\":2,\"baz\":3,\"foo.one\":1}")); }
@Test public void createsMetricsJsonCorrectly() throws JsonProcessingException { MetricRegistry registry = new MetricRegistry(); registry.counter("styx.origins.status.200").inc(); registry.counter("styx.origins.status.500").inc(2); registry.counter("styx.error").inc(3); registry.counter("foo.bar").inc(4); registry.register("styx.mygauge", (Gauge<Integer>) () -> 123); String before = new ObjectMapper() .registerModule(new MetricsModule(SECONDS, MILLISECONDS, false)) .writeValueAsString(registry); String after = JsonReformatter.reformat(before); assertThat(after, matchesRegex(quote("{\n" + " \"counters\":{\n" + " \"foo.bar.count\":4,\n" + " \"styx\":{\n" + " \"error.count\":3,\n" + " \"origins.status\":{\n" + " \"200.count\":1,\n" + " \"500.count\":2\n" + " }\n" + " }\n" + " },\n" + " \"gauges.styx.mygauge.value\":123,\n" + " \"histograms\":{\n" + "\n" + " },\n" + " \"meters\":{\n" + "\n" + " },\n" + " \"timers\":{\n" + "\n" + " },\n" + " \"version\":\"") + "\\d+\\.\\d+\\.\\d+" + quote("\"\n" + "}"))); }