ProductTest.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class ProductTest{
  12. @Test
  13. public void testEmptyConstructor(){
  14. Product product = new Product();
  15. }
  16. @Test
  17. public void testConstructorWithIdpriceQuantity(){
  18. String id = "5349h8te";
  19. double price = 55.55;
  20. int quantity = 3;
  21. Product newProduct = new Product(id, price, quantity);
  22. }
  23. @Test
  24. public void testGetSetPrice(){
  25. Product product = new Product();
  26. double price = 88.67;
  27. product.setPrice(price);
  28. double actualPrice = product.getPrice();
  29. assertEquals(price, actualPrice, 0.01);
  30. }
  31. @Test
  32. public void testGetProductId(){
  33. Product product = new Product();
  34. String id = "867_XX";
  35. product.setId(id);
  36. String actualId = product.getId();
  37. assertEquals(id, actualId);
  38. }
  39. @Test
  40. public void testGetQuantityNumber(){
  41. Product product = new Product();
  42. int quantity = 12;
  43. product.setQuantityOfItem(quantity);
  44. int actualQuantity = product.getQuantityOfItem();
  45. assertEquals(quantity, actualQuantity);
  46. }
  47. }