Question
Junit test : what am i doing wrong here? Please fix my test code +GetSet added aa.java ArrayList list = new ArrayList (); GetSet set;
Junit test : what am i doing wrong here? Please fix my test code
+GetSet added
aa.java
ArrayList list = new ArrayList<>();
GetSet set;
Scanner scan = new Scanner(System.in);
Selection selection = new Selection();
public void add(GetSet obj)
{
obj.setFirstName(selection.prompt_FirstName());
obj.setLastName(selection.prompt_LastName());
obj.setStreet(selection.prompt_Street());
obj.setCity(selection.prompt_City());
obj.setState(selection.prompt_State());
obj.setZip(selection.prompt_Zip());
obj.setPhone(selection.prompt_Telephone());
obj.setEmail(selection.prompt_Email());
set = new GetSet(obj.getFirstName(), obj.getLastName(), obj.getStreet(),
obj.getCity(), obj.getState(), obj.getZip(), obj.getPhone(), obj.getEmail());
list.add(set);
System.out.println(set.toString());
System.out.println(" Done!");
}
Selection.java
public String prompt_FirstName() {
System.out.println("First Name:");
while (!scan.hasNext("[A-Za-z]+"))
{
System.out.println("Invalid. " + "First Name: ");
scan.next();
}
String firstName = scan.next();
return firstName;
}
and other prompts are just like above.
GetSet.java
public class GetSet { private String firstName; private String lastName; private String street; private String city; private String state; private int zip; private String phone; private String email; public GetSet() { firstName = ""; lastName = ""; street = ""; city = ""; state = ""; zip = 0; phone = ""; email = ""; public GetSet(String firstName, String lastName, String street, String city, String state, int zip, String phone, String email) { this.firstName = firstName; this.lastName = lastName; this.street = street; this.city = city; this.state = state; this.zip = zip; this.phone = phone; this.email = email; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getFirstName() { return firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getLastName() { return lastName; } public void setCity(String city) { this.city = city; } public String getCity() { return city; } public void setStreet(String street) { this.street = street; } public String getStreet() { return street; } public void setState(String state) { this.state = state; } public String getState() { return state; } public void setZip(int zip) { this.zip = zip; } public int getZip() { return zip; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { return phone; } public void setEmail(String email) { this.email = email; } public String getEmail() { return email; } public String toString() { return "First Name: " + firstName + " Last Name: " + lastName + " Street: " + street + " City: " + city + " State: " + state + " Zip: " + zip + " Email: " + email + " Phone Number: " + phone +" "; } }
Here's my test case
@Test
public void testAddAddress()
{
AddressBook ab = new AddressBook();
GetSet ae = new GetSet("Demian", "Rice", "5053 Apple ave",
"New York", "NY", 10020, "212-212-2121", "drice5053@fmail.com");
assertEquals(ab.add(ae), ae.toString());
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started