### Question:
CommaNumberValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); int commaCount = 0; int position = 0; while ((position = content.indexOf(this.comma)) != -1) { commaCount++; content = content.substring(position + 1, content.length()); } if (getMaxNum() < commaCount) { addLocalizedError(sentence, commaCount, getMaxNum()); } } CommaNumberValidator(); @Override void validate(Sentence sentence);  }### Answer:
@Test void testWithSentenceContainingManyCommas() throws RedPenException { Validator commaNumberValidator = ValidatorFactory.getInstance("CommaNumber"); String content = "is it true, not true, but it should be ture, right, or not right."; Sentence str = new Sentence(content, 0); List<ValidationError> errors = new ArrayList<>(); commaNumberValidator.setErrorList(errors); commaNumberValidator.validate(str); assertNotNull(errors); assertEquals(1, errors.size()); assertEquals(content, errors.get(0).getSentence().getContent()); }
@Test void testWithtSentenceWithoutComma() throws RedPenException { Validator commaNumberValidator = ValidatorFactory.getInstance("CommaNumber"); String content = "is it true."; Sentence str = new Sentence(content, 0); List<ValidationError> errors = new ArrayList<>(); commaNumberValidator.setErrorList(errors); commaNumberValidator.validate(str); assertNotNull(errors); assertEquals(0, errors.size()); }
@Test void testWithtZeroLengthSentence() throws RedPenException { Validator commaNumberValidator = ValidatorFactory.getInstance("CommaNumber"); String content = ""; Sentence str = new Sentence(content, 0); List<ValidationError> errors = new ArrayList<>(); commaNumberValidator.setErrorList(errors); commaNumberValidator.validate(str); assertNotNull(errors); assertEquals(0, errors.size()); }
@Test void testJapaneseCornerCase() throws RedPenException { Configuration config = Configuration.builder("ja") .addValidatorConfig(new ValidatorConfiguration("CommaNumber")) .build(); Validator validator = ValidatorFactory.getInstance(config.getValidatorConfigs().get(0), config); List<ValidationError> errors = new ArrayList<>(); validator.setErrorList(errors); validator.validate(new Sentence("しかし、この仕組みで背中を押した結果、挑戦できない人は、ゴールに到達するためのタスクに挑戦するようになりました。", 0)); assertEquals(0, errors.size()); }