### Question:
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); }  List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter);  }### Answer:
@Test public void givenMapWithConstraints_shouldValidate() { Book book = new Book(); book.addAuthorChapter("Alex","Chapter 1"); book.addAuthorChapter("John","Chapter 2"); book.addAuthorChapter("May","Chapter 3"); Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book); assertThat(constraintViolations.size()).isEqualTo(0); }
@Test public void givenMapWithConstraints_shouldNotValidate() { Book book = new Book(); book.addAuthorChapter(" "," "); Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book); assertThat(constraintViolations.size()).isEqualTo(2); }