ObjectWriterFactory { public static ObjectWriter getDefaultJsonObjectWriter() { return DEFAULT_JSON_OBJECT_WRITER; }  static ObjectWriter getDefaultJsonObjectWriter();  }
@Test public void shouldReturnNonNullDefaultObjectWriter() { final ObjectWriter actual = getDefaultJsonObjectWriter(); assertThat(actual).isNotNull(); }
@Test public void shouldReturnObjectWriterWithPrettyPrintingEnabled() { final Map<String, String> objectToSerialize = new HashMap<>(); objectToSerialize.put("field1", "value1"); objectToSerialize.put("field2", "value2"); String actual; try { actual = getDefaultJsonObjectWriter().writeValueAsString(objectToSerialize); } catch (JsonProcessingException e) { fail(e.getMessage()); actual = ""; } assertThat(actual) .withFailMessage("Should be pretty printed and therefore contain line breaks") .contains(System.lineSeparator()); }
@Test public void shouldReturnObjectWriterThatWritesDurationAsISO8601() { final Duration objectToSerialize = Duration.ofSeconds(30); String actual; try { actual = getDefaultJsonObjectWriter().writeValueAsString(objectToSerialize); } catch (JsonProcessingException e) { fail(e.getMessage()); actual = ""; } assertThat(actual) .describedAs("Serialized form of Duration") .isEqualTo("\"" + Duration.ofSeconds(30).toString() + "\""); }
@Test public void shouldReturnObjectWriterThatWritesDataSizesInMB() { final DataSize objectToSerialize = DataSize.ofMegabytes(512); String actual; try { actual = getDefaultJsonObjectWriter().writeValueAsString(objectToSerialize); } catch (JsonProcessingException e) { fail(e.getMessage()); actual = ""; } assertThat(actual).describedAs("Serialized form of DataSize").isEqualTo("\"512MB\""); }