### Question:
Json implements Formatted { @Override public Text formatted() { return new FormattedText( new TextOf("{%n \"definitions\": [%s]%n}"), this.definitions() ); } Json(final @NonNull Glossary glossary); @Override Text formatted();  }### Answer:
@Test public void formattedCanRepresentAGlossaryWithoutDefinitions() throws Exception { Assertions.assertThat( new Json(new NoDefinitions()).formatted().asString() ).isEqualTo( new TextOf( "{" + JsonTest.ENDLINE + " \"definitions\": []" + JsonTest.ENDLINE + "}" ).asString() ); }
@Test public void formattedAlsoRepresentsEachIndividualDefinition() throws Exception { Assertions.assertThat( new Json( new WithDefinitions( new Definition("Something", "Not everything"), new Definition("Everything", "All somethings") ) ).formatted().asString() ).isEqualTo( new TextOf( "{" + JsonTest.ENDLINE + " \"definitions\": [{" + JsonTest.ENDLINE + " \"term\": \"Something\"," + JsonTest.ENDLINE + " \"description\": \"Not everything\"" + JsonTest.ENDLINE + " }, {" + JsonTest.ENDLINE + " \"term\": \"Everything\"," + JsonTest.ENDLINE + " \"description\": \"All somethings\"" + JsonTest.ENDLINE + " }]" + JsonTest.ENDLINE + "}" ).asString() ); }