### Question:
GappedSectionValidator extends Validator { @Override public void validate(Document document) { int seen = 0; for (Section s: document) { final int current = s.getLevel(); if (seen > 0) { if (current <= seen) { seen = current; } else { if (current == seen + 1) { seen = current; } else { addLocalizedError(s.getJoinedHeaderContents(), s.getJoinedHeaderContents().getContent(), current, seen + 1); } } } else { seen = current; } } }  @Override void validate(Document document);  }### Answer:
@Test void testInvalid() { Document document = Document.builder() .addSection(1) .addSectionHeader("Chapter 1") .addSection(3) .addSectionHeader("Section 1.1.1") .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document); assertEquals(1, errors.size()); }
@Test void testValid() { Document document = Document.builder() .addSection(1) .addSectionHeader("Chapter 1") .addSection(2) .addSectionHeader("Section 1.1") .addSection(3) .addSectionHeader("Section 1.1.1") .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document); assertEquals(0, errors.size()); }
@Test void testFailureCase() { Document document = Document.builder() .addSection(2) .addSectionHeader("Section 1.1") .addSection(3) .addSectionHeader("Section 1.1.1") .build(); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(document); assertEquals(0, errors.size()); }