Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.io . PrintWriter; import java.util.ArrayList; / * * * * @author AV * / public class TestCustomerData { / * * * All tests

import java.io.PrintWriter;
import java.util.ArrayList;
/**
*
* @author AV
*/
public class TestCustomerData {
/**
* All tests for PesronData class
*
* @return total score for AggregationClass part of assignment
*/
public static boolean tests(PrintWriter out){
out.println("\r
----CustomerData Class TEST SETS -------------------------------------------------------\r
");
boolean t1= testSet01CustomerDataClass(out);
boolean t2= testSet02CustomerDataClass(out);
return t1 && t2;
}
/**
* Set of unit tests for no-argument constructor, constructor, accessors
*
* @param outputStream stream to direct output into
* @return number of points earned for this unit. 0 is returned if even one of
* the tests failed
*/
public static boolean testSet01CustomerDataClass(PrintWriter outputStream){
int count =0;
int expectedCount =7;
CustomerData p1= new CustomerData();
// Test #1
if (p1.getFirstName().equals("") && p1.getLastName().equals("") && p1.getPhone().equals("")
&& p1.getAddress().equals("") && p1.getMailingList()== false && p1.getCustomerNumber()==0
&& p1.getTransactions().size()==0){
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for no-argument constructor, and accessor methods",
"PASSED");
count++;
} else {
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for no-argument constructor, and accessor methods",
"FAILED");
}
// Test #2-- constructor tests
ArrayList list = new ArrayList();
list.add(1L);
list.add(2L);
list.add(3L);
CustomerData p2= new CustomerData("Tom", "Sumerson", "2233456 Ave NE, Sometown, 98765","765-123-45-67",15,
false, list);
if (p2.toString().equals("First name: Tom; Last name: Sumerson; Address: 2233456 Ave NE, Sometown, 98765; Phone: 765-123-45-67; Customer number: 15; Mailing list: false; Transactions: [1,2,3]")){
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for constructor with parameters", "PASSED");
count++;
} else {
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for constructor with parameters", "FAILED");
}
// Test #3-- Deep copy of the ArrayList field
list.add(4L); // p2 must be unchanged by this
if (p2.toString().equals("First name: Tom; Last name: Sumerson; Address: 2233456 Ave NE, Sometown, 98765; Phone: 765-123-45-67; Customer number: 15; Mailing list: false; Transactions: [1,2,3]")){
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for deep copy of the ArrayList field", "PASSED");
count++;
} else {
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for deep copy of the ArrayList field", "FAILED");
}
// Test #4-- getters test
if(p2.getFirstName().equals("Tom")
&& p2.getLastName().equals("Sumerson")
&& p2.getPhone().equals("765-123-45-67")
&& p2.getAddress().equals("2233456 Ave NE, Sometown, 98765")
&& p2.getCustomerNumber()==15
&& p2.getMailingList()== false
&& p2.getTransactions().toString().equals("[1,2,3]"))
{
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for accessors", "PASSED");
count++;
} else {
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for accessors", "FAILED");
}
// Test #5-- getTransactions() deep copy test
ArrayList list3= p2.getTransactions();
list3.add(100L);
if(p2.toString().equals("First name: Tom; Last name: Sumerson; Address: 2233456 Ave NE, Sometown, 98765; Phone: 765-123-45-67; Customer number: 15; Mailing list: false; Transactions: [1,2,3]"))
{
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for getTransactions() deep copy", "PASSED");
count++;
} else {
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for getTransactions() deep copy", "FAILED");
}
ArrayList list1= new ArrayList();
list1.add(1L);
list1.add(2L);
list1.add(3L);
p2= new CustomerData("Tom", "Sumerson", "2233456 Ave NE, Sometown, 98765","765-123-45-67",15, false, list1);
// Test #6-- Mutators
p2.setCustomerNumber(25);
p2.setMailingList(true);
ArrayList list2= new ArrayList();
list2.add(11L);
list2.add(222L);
list2.add(3333L);
p2.setTransactions(list2);
if (p2.toString().equals("First name: Tom; Last name: Sumerson; Address: 2233456 Ave NE, Sometown, 98765; Phone: 765-123-45-67; Customer number: 25; Mailing list: true; Transactions: [11,222,3333]")){
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for all mutator methods", "PASSED");
count++;
} else
outputStream.printf("%-80s%-10s\r
", "Test Set 01: Test for all mutator methods", "FAILED");
// Test #7-- Deep copy of the ArrayList field when changed by mutator
list2.add(44L);
if (p2.toString().equals("First name: Tom; Last name: Sumerson; Address: 2233456 Ave NE, Someto

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

unemployed people

Answered: 1 week ago