@Test public void create_shouldReturnOptionalPresentForNonExistingIsbn() { Optional<Book> optional = bookDao.create(book); assertTrue(optional.isPresent()); assertSame(book, optional.get()); Book createdBook = ((Map<String, Book>) getField(BOOKS_FIELD, bookDao)).get(book.getIsbn()); assertNotSame(book, createdBook); assertReflectionEquals(book, createdBook); }
@Nonnull public Optional<Book> create(@Nonnull final Book bookToCreate) { checkNotNull(bookToCreate, "Argument[bookToCreate] must not be null"); Book book = new BookBuilder(bookToCreate.getIsbn()).build(bookToCreate); if (books.putIfAbsent(book.getIsbn(), book) == null) { return Optional.of(bookToCreate); } return Optional.absent(); }
BookDao { @Nonnull public Optional<Book> create(@Nonnull final Book bookToCreate) { checkNotNull(bookToCreate, "Argument[bookToCreate] must not be null"); Book book = new BookBuilder(bookToCreate.getIsbn()).build(bookToCreate); if (books.putIfAbsent(book.getIsbn(), book) == null) { return Optional.of(bookToCreate); } return Optional.absent(); } }
BookDao { @Nonnull public Optional<Book> create(@Nonnull final Book bookToCreate) { checkNotNull(bookToCreate, "Argument[bookToCreate] must not be null"); Book book = new BookBuilder(bookToCreate.getIsbn()).build(bookToCreate); if (books.putIfAbsent(book.getIsbn(), book) == null) { return Optional.of(bookToCreate); } return Optional.absent(); }  }
BookDao { @Nonnull public Optional<Book> create(@Nonnull final Book bookToCreate) { checkNotNull(bookToCreate, "Argument[bookToCreate] must not be null"); Book book = new BookBuilder(bookToCreate.getIsbn()).build(bookToCreate); if (books.putIfAbsent(book.getIsbn(), book) == null) { return Optional.of(bookToCreate); } 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> create(@Nonnull final Book bookToCreate) { checkNotNull(bookToCreate, "Argument[bookToCreate] must not be null"); Book book = new BookBuilder(bookToCreate.getIsbn()).build(bookToCreate); if (books.putIfAbsent(book.getIsbn(), book) == null) { return Optional.of(bookToCreate); } 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);  }