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
~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 nonnegative @param description public ProductString sku, double unitPrice, String description if unitPrice throw new IllegalArgumentExceptionUnit price must be nonnegative."; 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 nonnegative public void setUnitPricedouble unitPrice if unitPrice throw new IllegalArgumentExceptionUnit price must be nonnegative."; this.unitPrice unitPrice; Returns the description @return the description public String getDescription return description; Sets the description @param description public void setDescriptionString 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#equalsjavalang.Object @Override public boolean equalsObject 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 othersku null return false; else if sku.equalsothersku return false; return true;
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
