### Question:
SpaceBeginningOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (!isFirstInLine(sentence) && content.length() > 0 && content.charAt(0) != ' ') { addLocalizedErrorWithPosition(sentence, 0, 1); } }  @Override void validate(Sentence sentence); @Override void preValidate(Sentence sentence);  }### Answer:
@Test void testProcessSentenceWithoutEndSpace() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBeginningOfSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("this is a test.", 1)) .addSentence(new Sentence("this is a test.", 1)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(1, errors.get(documents.get(0)).size()); }
@Test void testProcessFirstSpace() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBeginningOfSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("this is a test", 1)) .addSentence(new Sentence(" this is a test", 1)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }
@Test void testProcessHeadSentenceInAParagraph() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBeginningOfSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("This is a test", 1)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }
@Test void testProcessZeroLengthSentence() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBeginningOfSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("", 0)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }
@Test void testProcessNewLineSentenceWithoutEndSpace() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBeginningOfSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("this is a test.", 1)) .addSentence(new Sentence("this is a test.", 2)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }
@Test void testProcessVoidSentence() throws RedPenException { Configuration config = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBeginningOfSentence")) .build(); List<Document> documents = new ArrayList<>(); documents.add(Document.builder() .addSection(1) .addParagraph() .addSentence(new Sentence("", 1)) .build()); RedPen redPen = new RedPen(config); Map<Document, List<ValidationError>> errors = redPen.validate(documents); assertEquals(0, errors.get(documents.get(0)).size()); }