### Question:
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence);  }### Answer:
@Test void testInvalidEndOfSentence() { List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Sentence("He said \"that is right\".", 0)); assertEquals(1, errors.size()); }
@Test void testValidEndOfSentence() { List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Sentence("He said \"that is right.\"", 0)); assertEquals(0, errors.size()); }
@Test void testInValidEndOfSentenceWithQuestionMark() { List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Sentence("He said \"Is it right\"?", 0)); assertEquals(1, errors.size()); }
@Test void testVoid() { List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Sentence("", 0)); assertEquals(0, errors.size()); }
@Test void testJapaneseInvalidEndOfSentence() throws RedPenException { Configuration config = Configuration.builder("ja") .addValidatorConfig(new ValidatorConfiguration("EndOfSentence")) .build(); List<Document> documents = new ArrayList<>();documents.add( Document.builder(new NeologdJapaneseTokenizer()) .addSection(1) .addParagraph() .addSentence(new Sentence("彼は言った，“今日は誕生日”。", 1)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Test void testErrorPosition() throws RedPenException { String sampleText = "He said \"that is right\"."; Configuration configuration = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("EndOfSentence")) .build(); DocumentParser parser = DocumentParser.MARKDOWN; List<Document> documents = new ArrayList<>(); Document document = parser.parse(sampleText, new SentenceExtractor(configuration.getSymbolTable()), configuration.getTokenizer()); documents.add(document); RedPen redPen = new RedPen(configuration); List<ValidationError> errors = redPen.validate(documents).get(documents.get(0)); assertEquals(1, errors.size()); assertEquals("EndOfSentence", errors.get(0).getValidatorName()); assertEquals(new LineOffset(1, 22), errors.get(0).getStartPosition().get()); assertEquals(new LineOffset(1, 23), errors.get(0).getEndPosition().get()); }