12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 ProductTest.
  7. */
  8. public class ProductTest
  9. {
  10. Product product = new Product("orange",1.50,"12346",400);
  11. @Test
  12. public void testSetGetName()
  13. {
  14. //Given
  15. product.setName("Apple");
  16. //Actual
  17. String actual = product.getName();
  18. //Expected
  19. String expected = "Apple";
  20. //Test
  21. assertEquals(expected,actual);
  22. }
  23. @Test
  24. public void testSetGetPrice()
  25. {
  26. //Given
  27. product.setPrice(1.99);
  28. //Actual
  29. double actual = product.getPrice();
  30. //Expected
  31. double expected = 1.99;
  32. //Test
  33. assertEquals(expected,actual,.01);
  34. }
  35. @Test
  36. public void testSetGetID()
  37. {
  38. //Given
  39. product.setID("12345");
  40. //Actual
  41. String actual = product.getID();
  42. //Expected
  43. String expected = "12345";
  44. //Test
  45. assertEquals(expected,actual);
  46. }
  47. @Test
  48. public void testSetGetQuantity()
  49. {
  50. //Given
  51. product.setQuantity(500);
  52. //Actual
  53. int actual = product.getQuantity();
  54. //Expected
  55. int expected = 500;
  56. //Test
  57. assertEquals(expected,actual);
  58. }
  59. }