Question: package junit _ testing _ Jtorres 1 2 6 ; public class Product { / / class fields / / we will do data hiding.
package junittestingJtorres;
public class Product
class fields
we will do data hiding. so all will start with private keywords
private String prodName;
private double prodPrice;
private int prodQty;
public ProductString prodName, double prodPriceconstructor
this.prodName prodName;
this.prodPrice prodPrice;
public Productno args constructor
public static void mainString args
Product p new Product;
psetProdPrice;
System.out.printlnpgetProdPrice;
public String getProdName
return prodName;
public void setProdNameString prodName
this.prodName prodName;
public double getProdPrice
return prodPrice;
public void setProdPricedouble prodPrice
ifprodPrice
this.prodPrice ;
else
this.prodPrice prodPrice;
public int getProdQty
return prodQty;
public void setProdQtyint prodQty
this.prodQty prodQty;
public String toString
return this.getProdNamethis.getProdPrice;
package junittestingJtorres;
import static org.junit.Assert.;
import org.junit.Test;
public class ProductTest
@Test
public void testPriceVar
Product prod new Product Dr Pepper", ;
double expected ;
double actual prod.getProdPrice;
assertEqualsexpected actual, ;
@Test
public void testPriceVarForLessThanZero
Product prod new Product Dr Pepper", ;
double expected ;
double actual prod.getProdPrice;
assertEqualsexpected actual, ;
The next code is the Junit tester code that is recieving the fail for less than zero testpackage junittestingJtorres;
import static org.junit.Assert.;
import org.junit.Test;
public class ProductTest
@Test
public void testPriceVar
Product prod new Product Dr Pepper", ;
double expected ;
double actual prod.getProdPrice;
assertEqualsexpected actual, ;
@Test
public void testPriceVarForLessThanZero
Product prod new Product Dr Pepper", ;
double expected ;
double actual prod.getProdPrice;
assertEqualsexpected actual, ;
Last are the actual instructions from the assignment e Make sure there are no syntax errors then press the green Run button at the top of Eclipse. We see that one of our test passed and one failed. And in the Failure trace, we see the expected and the actual results.
f Fix the setProdPricedouble method of the Product class so it handles values less than zero as described by our rules. Think about if you are not setting the value to check, so You need need to figure out where to add the change.Tips: Constructor
g Make sure there are no syntax errors then press the green Run button at the top of Eclipse. Did both test pass this time?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
