@Test void testFormatDocumentsAndErrors() throws RedPenException, JSONException { JSONFormatter formatter = new JSONFormatter(); List<ValidationError> errors = new ArrayList<>(); setErrorList(errors); addLocalizedError(new Sentence("testing JSONFormatter", 1)); Document document = Document.builder().setFileName("docName").build(); Map<Document, List<ValidationError>> documentListMap = new HashMap<>(); documentListMap.put(document, errors); String result = formatter.format(documentListMap); assertEquals("[{\"document\":\"docName\",\"errors\":[{\"sentence\":\"testing JSONFormatter\",\"level\":\"Error\",\"validator\":\"JSONFormatterTest\",\"lineNum\":1,\"sentenceStartColumnNum\":0,\"message\":\"json test error\"}]}]", result); JSONArray jsonArray = new JSONArray(result); assertTrue(jsonArray.length() == 1); JSONObject jsonObject = jsonArray.getJSONObject(0); String docName = jsonObject.getString("document"); assertEquals("docName", docName); JSONArray jsonErrors = jsonObject.getJSONArray("errors"); assertNotNull(jsonErrors); assertEquals(1, jsonErrors.length()); assertEquals("testing JSONFormatter", jsonErrors.getJSONObject(0).getString("sentence")); assertEquals("json test error", jsonErrors.getJSONObject(0).getString("message")); assertEquals(1, jsonErrors.getJSONObject(0).getInt("lineNum")); }
@Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); } }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }  }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }  @Override void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap); @Override String format(Document document, List<ValidationError> errors); @Override String formatError(Document document, ValidationError error); }
JSONFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString()); writer.flush(); }  @Override void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap); @Override String format(Document document, List<ValidationError> errors); @Override String formatError(Document document, ValidationError error);  }