### Question:
SuccessiveWordValidator extends Validator { @Override public void validate(Sentence sentence) { String prevSurface = ""; for (TokenElement token : sentence.getTokens()) { String currentSurface = token.getSurface(); if (prevSurface.equalsIgnoreCase(currentSurface) && currentSurface.length() > 0 && !isPartOfNumber(sentence, token)) { addLocalizedErrorFromToken(sentence, token); } prevSurface = currentSurface; } }  @Override void validate(Sentence sentence);  }### Answer:
@Test void detectSuccessiveWord() throws RedPenException { Document document = prepareSimpleDocument("the item is is a good."); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document)); assertEquals(1, errors.get(document).size()); assertEquals("Found word \"is\" repeated twice in succession.", errors.get(document).get(0).getMessage()); }
@Test void detectSuccessiveWordWithDifferentCase() throws RedPenException { Document document = prepareSimpleDocument("Welcome welcome to Estonia."); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document)); assertEquals(1, errors.get(document).size()); assertEquals("Found word \"welcome\" repeated twice in succession.", errors.get(document).get(0).getMessage()); }
@Test void detectJapaneseSuccessiveWord() throws RedPenException { config = getConfiguration("ja"); Document document = prepareSimpleDocument("私はは嬉しい."); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document)); assertEquals(1, errors.get(document).size()); assertEquals("Found word \"は\" repeated twice in succession.", errors.get(document).get(0).getMessage()); }
@Test void nonSuccessiveDoubledWord() throws RedPenException { Document document = prepareSimpleDocument("the item is a item good."); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document)); assertEquals(0, errors.get(document).size()); }
@Test void ignoreNumbers() throws Exception { Document document = prepareSimpleDocument("Amount is $123,456,789.45"); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document)); assertEquals(0, errors.get(document).size()); }