### Question:
WordNumberValidator extends Validator { @Override public void validate(Sentence sentence) { List<TokenElement> words = sentence.getTokens(); int wordNum = 0; for (TokenElement word : words) { if (!word.getSurface().equals(",") && !word.getSurface().equals(",") && !word.getSurface().equals("?") && !word.getSurface().equals("!") && !word.getSurface().equals(":") && !word.getSurface().equals(";") && !word.getSurface().equals("\"") && !word.getSurface().equals("'")) { wordNum++; } } int maxNum = getInt("max_num"); if (wordNum > maxNum) { addLocalizedError(sentence, wordNum, maxNum); } } WordNumberValidator(); @Override void validate(Sentence sentence);  }### Answer:
@Test void testWithShortSentence() { WordNumberValidator maxWordNumberValidator = new WordNumberValidator(); Sentence str = new Sentence( "this sentence is short.", 0); List<ValidationError> errors = new ArrayList<>(); maxWordNumberValidator.setErrorList(errors); maxWordNumberValidator.validate(str); assertNotNull(errors); assertEquals(0, errors.size()); }
@Test void testWithLongSentence() { WordNumberValidator maxWordNumberValidator = new WordNumberValidator(); Sentence str = new Sentence( "this sentence is very very very very very very very very very very" + " very very very very very very very very very very very very very very long", 0); List<ValidationError> errors = new ArrayList<>(); maxWordNumberValidator.setErrorList(errors); maxWordNumberValidator.validate(str); assertNotNull(errors); assertEquals(0, errors.size()); }
@Test void testWithZeroLengthSentence() { WordNumberValidator maxWordNumberValidator = new WordNumberValidator(); Sentence str = new Sentence("", 0); List<ValidationError> errors = new ArrayList<>(); maxWordNumberValidator.setErrorList(errors); maxWordNumberValidator.validate(str); assertNotNull(errors); assertEquals(0, errors.size()); }
@Test void testSentenceWithCommas() throws RedPenException { Document document = prepareSimpleDocument("There is no real path, so first follow the line of the foot of the rocks past Kawa, then cut straight up to the next level of slabs."); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document)); assertEquals(0, errors.get(document).size()); }