@Test(expected = GestionAppException.class) public void decreaseStockIlegalStockTest() throws GestionAppException, DataAccessException { Book book = BookFactory.createBook(); book.setCurrentStock(10); when(this.bookDAOMock.findOne(anyString())).thenReturn(book); this.bookService.decreaseStock(book.getIsbn(), 15); }
@Test public void saveTest() throws Exception { Book book = BookFactory.createBook(); String expectedId = book.getIsbn(); when(this.bookDAOMock.save(book)).thenReturn(expectedId); String result = this.bookService.save(book); assertEquals(expectedId, result); }
@Test(expected = GestionAppException.class) public void decreaseStockCannotUpdateBookTest() throws GestionAppException, DataAccessException { Book book = BookFactory.createBook(); String isbn = book.getIsbn(); book.setCurrentStock(10); when(this.bookDAOMock.findOne(isbn)).thenReturn(book); when(this.bookDAOMock.update(book)).thenThrow(DataAccessException.class); this.bookService.decreaseStock(isbn, 2); }
@Test public void decreaseStockTest() throws GestionAppException, DataAccessException { Book book = BookFactory.createBook(); String isbn = book.getIsbn(); book.setCurrentStock(10); when(this.bookDAOMock.findOne(isbn)).thenReturn(book); when(this.bookDAOMock.update(book)).thenReturn(book); this.bookService.decreaseStock(isbn, 2); verify(this.bookDAOMock, times(1)).findOne(isbn); verify(this.bookDAOMock, times(1)).update(book); assertEquals(8, book.getCurrentStock()); }