InventoryTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 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 addItemTest1() {
  15. String expected = "dragon";
  16. Inventory danysStuff = new Inventory();
  17. danysStuff.addItem(new Product(25.00f, 3, "dragon"));
  18. Product dragon = danysStuff.getItem("dragon");
  19. String actual = dragon.getID();
  20. Assert.assertEquals(actual, expected);
  21. }
  22. @Test
  23. public void addItemTest2() {
  24. String expected = "dragon";
  25. Inventory danysStuff = new Inventory();
  26. danysStuff.addItem(25.00f, 3, "dragon");
  27. Product dragon = danysStuff.getItem("dragon");
  28. String actual = dragon.getID();
  29. Assert.assertEquals(actual, expected);
  30. }
  31. @Test
  32. public void addUnitsTest() {
  33. int expected = 6;
  34. Inventory danysStuff = new Inventory();
  35. danysStuff.addItem(new Product(25.00f, 3, "dragon"));
  36. danysStuff.addUnits("dragon", 3);
  37. int actual = danysStuff.getOnHandQuantity("dragon");
  38. Assert.assertEquals(actual, expected);
  39. }
  40. @Test
  41. public void removeUnitsTest() {
  42. int expected = 2;
  43. Inventory danysStuff = new Inventory();
  44. danysStuff.addItem(25.00f, 3, "dragon");
  45. danysStuff.removeUnits("dragon", 1);
  46. int actual = danysStuff.getOnHandQuantity("dragon");
  47. Assert.assertEquals(actual, expected);
  48. }
  49. @Test
  50. public void updatePriceTest() {
  51. float expected = 516.99f;
  52. Inventory danysStuff = new Inventory();
  53. danysStuff.addItem(25.00f, 3, "dragon");
  54. danysStuff.updatePrice("dragon", 516.99f);
  55. float actual = danysStuff.getPrice("dragon");
  56. Assert.assertEquals(actual, expected, 0.001f);
  57. }
  58. @Test
  59. public void inventoryValueTest() {
  60. double expected = 57.44;
  61. Inventory starkStuff = new Inventory();
  62. starkStuff.addItem(3.00f, 9, "direwolf collar");
  63. starkStuff.addItem(2.50f, 5, "direworlf treat");
  64. starkStuff.addItem(2.99f, 6, "winterfell snowglobe");
  65. double actual = starkStuff.getInventoryValue();
  66. Assert.assertEquals(actual, expected, 0.001f);
  67. }
  68. }