Question: Write tests for the followingYour tests must be written using JUnit 5 . ~Product Class * Constructing a Product with a negative price * Getting

Write tests for the followingYour tests must be written using JUnit 5.
~Product Class
* Constructing a Product with a negative price
* Getting and setting negative prices * equals()
* todString()
public class Product { private String sku; private double unitPrice; private String description;/*** Represents a Product with a SKU number, unit price, and description.** @param sku* @param unitPrice must be non-negative* @param description*/ public Product(String sku, double unitPrice, String description){ if (unitPrice <0){ throw new IllegalArgumentException("Unit price must be non-negative.");} this.sku = sku; this.unitPrice = unitPrice; this.description = description;}/*** Returns the unit price* @return unit price*/ public double getUnitPrice(){ return unitPrice;}/*** Sets the unit price* @param unitPrice must be non-negative*/ public void setUnitPrice(double unitPrice){ if (unitPrice <0){ throw new IllegalArgumentException("Unit price must be non-negative.");} this.unitPrice = unitPrice;}/*** Returns the description* @return the description*/ public String getDescription(){ return description;}/*** Sets the description* @param description*/ public void setDescription(String description){ this.description = description;}/*** Returns the SKU number* @return the SKU number*/ public String getSku(){ return sku;} @Override public String toString(){ return "Product [sku="+ sku +", unitPrice="+ unitPrice +", description="+ description +"]";}/*** Products are equal *only* if their sku numbers are equal* @see java.lang.Object#equals(java.lang.Object)*/ @Override public boolean equals(Object obj){ if (this == obj) return true; if (obj == null) return false; if (getClass()!= obj.getClass()) return false; Product other =(Product) obj; if (sku == null){ if (other.sku != null) return false;} else if (!sku.equals(other.sku)) return false; return true;}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!