### Question:
VoidSectionValidator extends Validator { @Override public void validate(Section section) { if (0 == section.getLevel() || section.getLevel() >= sectionLevelLimit) { return; } Sentence header = section.getJoinedHeaderContents(); if (section.getNumberOfParagraphs() == 0) { addLocalizedError(header, header.getContent()); } else { for (Paragraph p : section.getParagraphs()) { if (p.getNumberOfSentences() == 0) { addLocalizedError(header, header.getContent()); break; } } } }  @Override void validate(Section section);  }### Answer:
@Test void testInvalid() { Document document = Document.builder() .addSection(4) .addSectionHeader("Abstract") .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document.getSection(0)); assertEquals(1, errors.size()); }
@Test void testInvalidWithVoidSentence() { Document document = Document.builder() .addSection(1) .addSectionHeader("Abstract") .addParagraph() .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document.getSection(0)); assertEquals(1, errors.size()); }
@Test void testValid() { Document document = Document.builder() .addSection(1) .addSectionHeader("Abstract") .addParagraph() .addSentence(new Sentence("he is a super man.", 1)) .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document.getSection(0)); assertEquals(0, errors.size()); }
@Test void testInvalidButSmallSection() { Document document = Document.builder() .addSection(7) .addSectionHeader("Abstract") .addParagraph() .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document.getSection(0)); assertEquals(0, errors.size()); }
@Test void testChangeLimit() throws RedPenException { Document document = Document.builder() .addSection(4) .addSectionHeader("Abstract") .addParagraph() .build(); Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("VoidSection").addProperty("limit", "3")) .build(); Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document.getSection(0)); assertEquals(0, errors.size()); }