### Question:
SuccessiveSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { if (isSame(sentence, prevSentence)) { addLocalizedError(sentence, prevSentence.getContent(), sentence.getContent()); } prevSentence = sentence; } SuccessiveSentenceValidator(); @Override void validate(Sentence sentence);  }### Answer:
@Test void testIdenticalSentences() throws Exception { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SuccessiveSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("This is a pen.", 1)) .addSentence(new Sentence("This is a pen.", 2)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Test void testSimilarButNotSame() throws Exception { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SuccessiveSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("This is a pen.", 1)) .addSentence(new Sentence("That is another pen.", 2)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }
@Test void testChangeProperty() throws Exception { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SuccessiveSentence").addProperty("dist", 10)) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("This is a pen.", 1)) .addSentence(new Sentence("That is another pen.", 2)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Test void testIdenticalButDifferentLetterCases() throws Exception { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SuccessiveSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("THIS IS A PEN.", 1)) .addSentence(new Sentence("This is a pen.", 2)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }