@Test(expected=MovieRentalException.class) public void testRemoveFromStock() throws Exception { testStock.addToStock(mockMovie); testStock.addToStock(mockMovie); testStock.addToStock(mockMovie); testStock.addToStock(mockMovie); testStock.removeFromStock(mockMovie); assertEquals(testStock.getInStock(mockMovie.getTitle()), 3); testStock.removeFromStock(mockMovie); assertEquals(testStock.getInStock(mockMovie.getTitle()), 2); testStock.removeFromStock(mockMovie); assertEquals(testStock.getInStock(mockMovie.getTitle()), 1); testStock.removeFromStock(mockMovie); assertEquals(testStock.getInStock(mockMovie.getTitle()), 0); testStock.removeFromStock(mockMovie.getTitle()); }
public int removeFromStock(Movie movie) { String title = movie.getTitle(); Integer i = stock.get(title); int inStock = (i == null) ? 0 : i; if (inStock <= 0) { throw new MovieRentalException("no video in stock"); } stock.put(title, --inStock); notifyListeners(movie, inStock); return inStock; }
Stock { public int removeFromStock(Movie movie) { String title = movie.getTitle(); Integer i = stock.get(title); int inStock = (i == null) ? 0 : i; if (inStock <= 0) { throw new MovieRentalException("no video in stock"); } stock.put(title, --inStock); notifyListeners(movie, inStock); return inStock; } }
Stock { public int removeFromStock(Movie movie) { String title = movie.getTitle(); Integer i = stock.get(title); int inStock = (i == null) ? 0 : i; if (inStock <= 0) { throw new MovieRentalException("no video in stock"); } stock.put(title, --inStock); notifyListeners(movie, inStock); return inStock; }  }
Stock { public int removeFromStock(Movie movie) { String title = movie.getTitle(); Integer i = stock.get(title); int inStock = (i == null) ? 0 : i; if (inStock <= 0) { throw new MovieRentalException("no video in stock"); } stock.put(title, --inStock); notifyListeners(movie, inStock); return inStock; }  int addToStock(Movie movie); int removeFromStock(Movie movie); int getInStock(String title); void removeFromStock(String title); void addLowStockListener(LowStockListener l); void removeLowStockListener(LowStockListener l); }
Stock { public int removeFromStock(Movie movie) { String title = movie.getTitle(); Integer i = stock.get(title); int inStock = (i == null) ? 0 : i; if (inStock <= 0) { throw new MovieRentalException("no video in stock"); } stock.put(title, --inStock); notifyListeners(movie, inStock); return inStock; }  int addToStock(Movie movie); int removeFromStock(Movie movie); int getInStock(String title); void removeFromStock(String title); void addLowStockListener(LowStockListener l); void removeLowStockListener(LowStockListener l);  }