@Test(expected = NullPointerException.class) public void update_shouldThrowNpeForNullIsbnArgument() { bookDao.update(null); }
@Nonnull public Optional<Book> update(@Nonnull final Book bookToUpdate) { checkNotNull(bookToUpdate, "Argument[bookToUpdate] must not be null"); Book book = books.get(bookToUpdate.getIsbn()); if (book != null) { synchronized (book) { if (books.get(bookToUpdate.getIsbn()) == null) { return Optional.absent(); } book.setAuthor(bookToUpdate.getAuthor()); book.setTitle(bookToUpdate.getTitle()); book.setPrice(bookToUpdate.getPrice()); book.setCategory(bookToUpdate.getCategory()); return Optional.of(bookToUpdate); } } return Optional.absent(); }
BookDao { @Nonnull public Optional<Book> update(@Nonnull final Book bookToUpdate) { checkNotNull(bookToUpdate, "Argument[bookToUpdate] must not be null"); Book book = books.get(bookToUpdate.getIsbn()); if (book != null) { synchronized (book) { if (books.get(bookToUpdate.getIsbn()) == null) { return Optional.absent(); } book.setAuthor(bookToUpdate.getAuthor()); book.setTitle(bookToUpdate.getTitle()); book.setPrice(bookToUpdate.getPrice()); book.setCategory(bookToUpdate.getCategory()); return Optional.of(bookToUpdate); } } return Optional.absent(); } }
BookDao { @Nonnull public Optional<Book> update(@Nonnull final Book bookToUpdate) { checkNotNull(bookToUpdate, "Argument[bookToUpdate] must not be null"); Book book = books.get(bookToUpdate.getIsbn()); if (book != null) { synchronized (book) { if (books.get(bookToUpdate.getIsbn()) == null) { return Optional.absent(); } book.setAuthor(bookToUpdate.getAuthor()); book.setTitle(bookToUpdate.getTitle()); book.setPrice(bookToUpdate.getPrice()); book.setCategory(bookToUpdate.getCategory()); return Optional.of(bookToUpdate); } } return Optional.absent(); }  }
BookDao { @Nonnull public Optional<Book> update(@Nonnull final Book bookToUpdate) { checkNotNull(bookToUpdate, "Argument[bookToUpdate] must not be null"); Book book = books.get(bookToUpdate.getIsbn()); if (book != null) { synchronized (book) { if (books.get(bookToUpdate.getIsbn()) == null) { return Optional.absent(); } book.setAuthor(bookToUpdate.getAuthor()); book.setTitle(bookToUpdate.getTitle()); book.setPrice(bookToUpdate.getPrice()); book.setCategory(bookToUpdate.getCategory()); return Optional.of(bookToUpdate); } } return Optional.absent(); }  @Nonnull Optional<Book> create(@Nonnull final Book bookToCreate); @Nonnull List<Book> readAll(); @Nonnull Optional<Book> readByIsbn(@Nonnull final String isbn); @Nonnull Optional<Book> update(@Nonnull final Book bookToUpdate); boolean delete(@Nonnull final Book bookToDelete); }
BookDao { @Nonnull public Optional<Book> update(@Nonnull final Book bookToUpdate) { checkNotNull(bookToUpdate, "Argument[bookToUpdate] must not be null"); Book book = books.get(bookToUpdate.getIsbn()); if (book != null) { synchronized (book) { if (books.get(bookToUpdate.getIsbn()) == null) { return Optional.absent(); } book.setAuthor(bookToUpdate.getAuthor()); book.setTitle(bookToUpdate.getTitle()); book.setPrice(bookToUpdate.getPrice()); book.setCategory(bookToUpdate.getCategory()); return Optional.of(bookToUpdate); } } return Optional.absent(); }  @Nonnull Optional<Book> create(@Nonnull final Book bookToCreate); @Nonnull List<Book> readAll(); @Nonnull Optional<Book> readByIsbn(@Nonnull final String isbn); @Nonnull Optional<Book> update(@Nonnull final Book bookToUpdate); boolean delete(@Nonnull final Book bookToDelete);  }