### Question:
MathTag { public String toJson() { try { return objectMapper.writeValueAsString(this); } catch (JsonProcessingException e) { logger.error("Can't serialize to JSON object: " + this, e); return ""; } } MathTag(int position, String content, MathMarkUpType markUp); @Override boolean equals(Object obj); @JsonGetter("input") String getContent(); @JsonGetter("inputhash") String getContentHash(); @Deprecated Multiset<String> getIdentifier(boolean useTeX, boolean useBlacklist); Multiset<String> getIdentifiers(BaseConfig config); @JsonIgnore String getKey(); @JsonGetter("type") MathMarkUpType getMarkUpType(); @JsonIgnore int getPosition(); @JsonIgnore String getTagContent(); @Override int hashCode(); @JsonIgnore String placeholder(); String toJson(); @Override String toString(); final static Pattern FORMULA_PATTERN; }### Answer:
@Test public void testGetJson() throws JsonProcessingException { MathTag tag = new MathTag(1, "a+b", WikiTextUtils.MathMarkUpType.LATEX); Assert.assertThat(tag.toJson(), containsString("\"inputhash\"")); Assert.assertThat(tag.toJson(), containsString("\"input\"")); Assert.assertThat(tag.toJson(), containsString("\"type\"")); }
@Test public void testGetJsonValidation() throws Exception { MathTag tag = new MathTag(1, "a+b", WikiTextUtils.MathMarkUpType.LATEX); final String real = "[" + tag.toJson() + "]"; final JsonNode jsonSchema = JsonLoader.fromResource("/formula_list_schema.json"); final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonSchema schema = factory.getJsonSchema(jsonSchema); ProcessingReport report = schema.validate(JsonLoader.fromString(real)); assertTrue(report.isSuccess()); }