### Question:
ListLevelValidator extends Validator { @Override public void validate(Section section) { for (ListBlock listBlock : section.getListBlocks()) { for (ListElement listElement : listBlock.getListElements()) { final int maxLevel = getInt("max_level"); if (listElement.getLevel() > maxLevel) { addLocalizedError(listElement.getSentence(0), maxLevel); } } } } ListLevelValidator(); @Override void validate(Section section);  }### Answer:
@Test void testValid() throws Exception { Section section = new Section(0, "header"); section.appendListBlock(); section.appendListElement(1, Arrays.asList(new Sentence("item1", 1))); section.appendListElement(2, Arrays.asList(new Sentence("item2", 1))); section.appendListElement(3, Arrays.asList(new Sentence("item3", 1))); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(section); assertEquals(0, errors.size()); }
@Test void testInvalid() throws Exception { Section section = new Section(0, "header"); section.appendListBlock(); section.appendListElement(1, Arrays.asList(new Sentence("item1", 1))); section.appendListElement(2, Arrays.asList(new Sentence("item2", 1))); section.appendListElement(3, Arrays.asList(new Sentence("item3", 1))); section.appendListElement(4, Arrays.asList(new Sentence("item4", 1))); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(section); assertEquals(1, errors.size()); }