Question: Write tests for the followingYour tests must be written using JUnit 5 . - Customer Class Constructing a Customer Getting and setting first and last

Write tests for the followingYour tests must be written using JUnit 5.
-Customer Class
Constructing a Customer
Getting and setting first and last names
Getting customer number
equals()
Checking that the customer number auto-increments with each new customer object created
toString()
public class Customer {
private static int nextNumber =1;
private int number;
private String firstName;
private String lastName;
/**
* Represents a customer with customer number (autogenerated), first and last name.
* @param firstName
* @param lastName
*/
public Customer(String firstName, String lastName){
this.number = nextNumber++;
this.firstName = firstName;
this.lastName = lastName;
}
/**
* Returns the first name
* @return the first name
*/
public String getFirstName(){
return firstName;
}
/**
* Returns the last name
* @return the last name
*/
public String getLastName(){
return lastName;
}
/**
* Sets the first name
* @param firstName
*/
public void setFirstName(String firstName){
this.firstName = firstName;
}
/**
* Sets the last name
* @param lastName
*/
public void setLastName(String lastName){
this.lastName = lastName;
}
/**
* Returns the customer number
* @return the customer number
*/
public int getNumber(){
return number;
}
@Override
public String toString(){
return "Customer [number="+ number +", name="+ firstName +""+ lastName +"]";
}
/**
* Customers are equal *only* if their customer 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;
Customer other =(Customer) obj;
if (number != other.number)
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!