ProductTest.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Created by leon on 1/10/18.
  3. */
  4. import org.junit.Assert;
  5. import org.junit.Test;
  6. public class ProductTest {
  7. @Test
  8. public void getPriceTest(){
  9. //Given
  10. Product test = new Product(5, "Melon", 10);
  11. //Then
  12. int expected = 5;
  13. int actual = test.getPrice();
  14. //Assert
  15. Assert.assertEquals(expected, actual);
  16. }
  17. @Test
  18. public void getIdTest(){
  19. //Given
  20. Product test = new Product(5, "Melon", 10);
  21. //Then
  22. String expected = "Melon";
  23. String actual = test.getId();
  24. //Assert
  25. Assert.assertEquals(expected, actual);
  26. }
  27. @Test
  28. public void getOnHandTest(){
  29. //Given
  30. Product test = new Product(5, "Melon", 10);
  31. //Then
  32. int expected = 10;
  33. int actual = test.getOnHand();
  34. //Assert
  35. Assert.assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void changePriceTest(){
  39. //Given
  40. Product test = new Product(5, "Melon", 10);
  41. test.changePrice(3);
  42. //Then
  43. int expected = 3;
  44. int actual = test.getPrice();
  45. //Assert
  46. Assert.assertEquals(expected, actual);
  47. }
  48. @Test
  49. public void addOnHandTest(){
  50. //Given
  51. Product test = new Product(5, "Melon", 10);
  52. test.addOnHand(15);
  53. //Then
  54. int expected = 25;
  55. int actual = test.getOnHand();
  56. //Assert
  57. Assert.assertEquals(expected, actual);
  58. }
  59. @Test
  60. public void totalValueTest(){
  61. Product test = new Product(5, "Melon", 10);
  62. int expected = 50;
  63. int actual = test.totalValue();
  64. Assert.assertEquals(expected, actual);
  65. }
  66. }