InventoryTest.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class InventoryTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class InventoryTest
  12. {
  13. @Test
  14. public void testAdd(){
  15. //Given
  16. Inventory inventory = new Inventory();
  17. Product product = new Product(1, "Herbal Tea", 1.60, 1);
  18. //When
  19. inventory.add(product);
  20. //Then
  21. int actualSize = inventory.size();
  22. int expectedSize = 1;
  23. assertEquals(expectedSize, actualSize);
  24. }
  25. @Test
  26. public void testGetProductByID() {
  27. Inventory inventory = new Inventory();
  28. int productID = 85;
  29. Product expectedProduct = new Product(productID, "Coffee", 4.60, 1);
  30. inventory.add(expectedProduct);
  31. Product actualProduct = inventory.getProductByID(productID);
  32. assertEquals(expectedProduct, actualProduct);
  33. }
  34. @Test
  35. public void testSumQuantity(){
  36. Inventory myInventory = new Inventory();
  37. Product product = new Product(86, "Herbal Tea", 1.6, 2);
  38. Product product2 = new Product(87, "Black Tea", 2.0, 2);
  39. Product product3 = new Product(88, "Green Tea", 3.5, 6);
  40. myInventory.add(product);
  41. myInventory.add(product2);
  42. myInventory.add(product3);
  43. int expectedQuantity = 10;
  44. int actualQuantity = myInventory.getSumQuantity();
  45. assertEquals(expectedQuantity, actualQuantity);
  46. }
  47. }