### Question:
ContractionValidator extends Validator { @Override public void validate(Sentence sentence) { for (TokenElement token : sentence.getTokens()) { String surface = token.getSurface().toLowerCase(); if (foundNonContractionNum >= foundContractionNum && contractions.contains(surface)) { addLocalizedErrorFromToken(sentence, token); } } }  @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence); @Override void preValidate(Sentence sentence);  }### Answer:
@Test void testContraction() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("Contraction")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("he is a super man.", 1)) .addSentence(new Sentence("he is not a bat man.", 2)) .addSentence(new Sentence("he's also a business man.", 3)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Test void testNoContraction() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("Contraction")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("he is a super man.", 1)) .addSentence(new Sentence("he is not a bat man.", 2)) .addSentence(new Sentence("he is a business man.", 3)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }
@Test void testUpperCaseContraction() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("Contraction")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("He is a super man.", 1)) .addSentence(new Sentence("He is not a bat man.", 2)) .addSentence(new Sentence("He's also a business man.", 3)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Test void testManyContractions() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("Contraction")) .build(); List<Document> documents = new ArrayList<>(); documents.add( Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("he's a super man.", 1)) .addSentence(new Sentence("he's not a bat man.", 2)) .addSentence(new Sentence("he is a business man.", 3)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }