@Test public void readByIsbn_shouldReturnOptionalAbsentForNonExistingIsbn() { Optional<Book> optional = bookDao.readByIsbn(ISBN); assertFalse(optional.isPresent()); }
@Nonnull public Optional<Book> readByIsbn(@Nonnull final String isbn) { checkNotNull(isbn, "Argument[isbn] must not be null"); Book book = books.get(isbn); if (book != null) { synchronized (book) { if (books.get(isbn) == null) { return Optional.absent(); } return Optional.of(new BookBuilder(book.getIsbn()).build(book)); } } return Optional.absent(); }
BookDao { @Nonnull public Optional<Book> readByIsbn(@Nonnull final String isbn) { checkNotNull(isbn, "Argument[isbn] must not be null"); Book book = books.get(isbn); if (book != null) { synchronized (book) { if (books.get(isbn) == null) { return Optional.absent(); } return Optional.of(new BookBuilder(book.getIsbn()).build(book)); } } return Optional.absent(); } }
BookDao { @Nonnull public Optional<Book> readByIsbn(@Nonnull final String isbn) { checkNotNull(isbn, "Argument[isbn] must not be null"); Book book = books.get(isbn); if (book != null) { synchronized (book) { if (books.get(isbn) == null) { return Optional.absent(); } return Optional.of(new BookBuilder(book.getIsbn()).build(book)); } } return Optional.absent(); }  }
BookDao { @Nonnull public Optional<Book> readByIsbn(@Nonnull final String isbn) { checkNotNull(isbn, "Argument[isbn] must not be null"); Book book = books.get(isbn); if (book != null) { synchronized (book) { if (books.get(isbn) == null) { return Optional.absent(); } return Optional.of(new BookBuilder(book.getIsbn()).build(book)); } } 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> readByIsbn(@Nonnull final String isbn) { checkNotNull(isbn, "Argument[isbn] must not be null"); Book book = books.get(isbn); if (book != null) { synchronized (book) { if (books.get(isbn) == null) { return Optional.absent(); } return Optional.of(new BookBuilder(book.getIsbn()).build(book)); } } 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);  }