import org.junit.*; /**************************************************** * MyStudentTest - to test the class Product * * @author Resendiz * @version January 2021 ****************************************************/ public class MyProductTest { /****************************************************** * Test overloaded constructor - with input parameters *****************************************************/ @Test public void testOverloadedConstructor() { Product p = new Product("SKU987", 4.50, 50); Assert.assertEquals("Product code should be ","SKU987", p.getCode()); Assert.assertEquals("Price should be set to $4.50", 4.50, p.getPrice(), 0.1); Assert.assertEquals("Count should be set to 50", 50, p.getCount()); } /****************************************************** * Test setCode *****************************************************/ @Test public void testSetCode() { Product p = new Product("SKU987", 4.50, 50); p.setCode("SKU123"); Assert.assertEquals("Product code should be ","SKU123", p.getCode()); } /****************************************************** * Test setPrice *****************************************************/ @Test public void testSetPrice() { Product p = new Product("SKU987", 4.50, 50); p.setPrice(9.50); Assert.assertEquals("Price should be set to $9.50", 9.50, p.getPrice(), 0.1); } /****************************************************** * Test setCount *****************************************************/ @Test public void testSetCount() { Product p = new Product("SKU987", 4.50, 50); p.setCount(25); Assert.assertEquals("Count should be set to 25", 25, p.getCount()); } /****************************************************** * Test addInventory *****************************************************/ @Test public void testAddInventory() { Product p = new Product("SKU987", 4.50, 50); p.addInventory(25); Assert.assertEquals("Count should be set to 75", 75, p.getCount()); } /****************************************************** * Test sellInventory *****************************************************/ @Test public void testSellInventory() { Product p = new Product("SKU987", 4.50, 50); p.sellInventory(25); Assert.assertEquals("Count should be set to 25", 25, p.getCount()); } }