### Question:
PlainFormatter extends Formatter { @Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); for (Document document : docErrorsMap.keySet()) { List<ValidationError> errors = docErrorsMap.get(document); for (ValidationError error : errors) { writer.write(formatError(document, error)); } } try { writer.flush(); } catch (IOException e) { LOG.error("failed to flush", e); } }  @Override void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap); @Override String formatError(Document document, ValidationError error);  }### Answer:
@Test void testConvertValidationError() { List<ValidationError> errors = new ArrayList<>(); setErrorList(errors); addLocalizedError(new Sentence("This is a sentence", 0)); Document document = new cc.redpen.model.Document.DocumentBuilder(new WhiteSpaceTokenizer()) .setFileName("foobar.md").build(); List<ValidationError> validationErrors = Arrays.asList(errors.get(0)); String resultString = formatter.format(document, validationErrors); assertEquals("foobar.md:0: ValidationError[PlainFormatterTest], plain test error at line: This is a sentence\n", resultString); }
@Test void testConvertValidationErrorWithoutFileName() { List<ValidationError> errors = new ArrayList<>(); setErrorList(errors); addLocalizedError(new Sentence("This is a sentence", 0)); Document document = new cc.redpen.model.Document.DocumentBuilder(new WhiteSpaceTokenizer()).build(); List<ValidationError> validationErrors = Arrays.asList(errors.get(0)); String resultString = formatter.format(document, validationErrors); assertEquals("0: ValidationError[PlainFormatterTest], plain test error at line: This is a sentence\n", resultString); }
@Test void testConvertValidationErrorChangingErrorLevel() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SentenceLength").setLevel(ValidatorConfiguration.LEVEL.INFO)).build(); Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); Sentence sentence = new Sentence("This is a long long long long long long long long long long long long" + " long long long long long long long long long long long long long long long long long long long long sentence", 0); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(sentence); Document document = new cc.redpen.model.Document.DocumentBuilder(new WhiteSpaceTokenizer()).build(); List<ValidationError> validationErrors = Arrays.asList(errors.get(0)); String resultString = formatter.format(document, validationErrors); assertTrue(resultString.indexOf("ValidationInfo[SentenceLength]") > 0 ); }