ProductTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. public class ProductTest
  6. {
  7. Product product;
  8. @Test
  9. public void getNameTest(){
  10. product = new Product("water", 1005, 1.00, 15);
  11. String expected = "water";
  12. String actual = product.getName();
  13. assertEquals(expected, actual);
  14. }
  15. @Test
  16. public void getIdTest(){
  17. product = new Product("water", 1005, 1.00, 15);
  18. int expected = 1005;
  19. int actual = product.getId();
  20. assertEquals(expected, actual);
  21. }
  22. @Test
  23. public void getSetPriceTest(){
  24. product = new Product("water", 1005, 1.00, 15);
  25. product.setPrice(3.55);
  26. double expected = 3.55;
  27. double actual = product.getPrice();
  28. assertEquals(expected, actual, .01);
  29. }
  30. @Test
  31. public void getQuantity(){
  32. product = new Product("water", 1005, 1.00, 15);
  33. int expected = 15;
  34. int actual = product.getQuantity();
  35. assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void changePriceTest(){
  39. product = new Product("water", 1005, 1.00, 15);
  40. double expected = 2.75;
  41. product.setPrice(2.75);
  42. double actual = product.getPrice();
  43. assertEquals(expected, actual, .01);
  44. }
  45. @Test
  46. public void addQuantityTest(){
  47. product = new Product("water", 1005, 1.00, 15);
  48. int expected = 19 ;
  49. product.addQuantity(4);
  50. int actual = product.getQuantity();
  51. assertEquals(expected, actual);
  52. }
  53. public void getValue(){
  54. product = new Product("water", 1005, 1.00, 15);
  55. double expected = 15.00;
  56. double actual = product.getValue();
  57. assertEquals(expected, actual, .01);
  58. }
  59. }