-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBusinessTest.java
More file actions
143 lines (113 loc) · 5.87 KB
/
BusinessTest.java
File metadata and controls
143 lines (113 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.doing.more.java.example;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class BusinessTest {
Business testBusiness;
EmployeeBean bob, jose, sven, ingabrit, noFirstName, noLastName;
CustomerBean sarah, joe, alma, hannah, customerNoFirstName, customerNoLastName;
@Before
public void setUp() throws Exception {
testBusiness = new Business();
//each employee has a firs and last name, an age, a phone number, and an employee id number
bob = new EmployeeBean("Bob", "Jones", 23, "(208)555-1818", "132-841Z-Qz0a4");
jose = new EmployeeBean("Jose", "Gomez", 19, "(208)888-1900", "132-841Z-Qz0a4");
sven = new EmployeeBean("Sven", "Anderson", 19, "(208)888-1598", "132-841Z-Qz0a4");
ingabrit = new EmployeeBean("Ingabrit", "Anderson", 19, "(208)888-1599", "132-841Z-Qz0a4");
noFirstName = new EmployeeBean(null, "Anderson", 19, "(208)888-1599", "132-841Z-Qz0a4");
noLastName = new EmployeeBean("Joe", null, 19, "(208)888-1599", "132-841Z-Qz0a4");
sarah = new CustomerBean("Sarah", "Azikiwe", 23, "(208)555-1818");
joe = new CustomerBean("Joe", "Adams", 19, "(208)888-1900");
alma = new CustomerBean("Alma", "Hernandez", 19, "(208)888-1598");
hannah = new CustomerBean("Hannah", "Gustavson", 19, "(208)888-1599");
customerNoFirstName = new CustomerBean(null, "Anderson", 19, "(208)888-1599");
customerNoLastName = new CustomerBean("Joe", null, 19, "(208)888-1599");
}
@Test
public void testAddEmployee() {
testBusiness.addEmployee(bob);
int numEmployees = testBusiness.employees.size();
assertEquals(1, numEmployees);
testBusiness.addEmployee(jose);
testBusiness.addEmployee(sven);
testBusiness.addEmployee(ingabrit);
numEmployees = testBusiness.employees.size();
assertEquals(4, numEmployees);
testBusiness.addEmployee(null);
numEmployees = testBusiness.employees.size();
assertEquals(4, numEmployees);
testBusiness.addEmployee(noLastName);
numEmployees = testBusiness.employees.size();
assertEquals(4, numEmployees);
testBusiness.addEmployee(noFirstName);
numEmployees = testBusiness.employees.size();
assertEquals(4, numEmployees);
testBusiness.employees.clear();
}
@Test
public void testGetEmployee() {
testBusiness.employees.put("Jones, Bob", bob);
testBusiness.employees.put("Gomez, Jose", jose);
testBusiness.employees.put("Anderson, Sven", sven);
testBusiness.employees.put("Anderson, Ingabrit", ingabrit);
EmployeeBean bobFromMap = testBusiness.getEmployee("Jones, Bob");
assertEquals(bob, bobFromMap);
EmployeeBean joseFromMap = testBusiness.getEmployee("Gomez, Jose");
assertEquals(jose, joseFromMap);
EmployeeBean svenFromMap = testBusiness.getEmployee("Anderson, Sven");
assertEquals(sven, svenFromMap);
EmployeeBean ingabritFromMap = testBusiness.getEmployee("Anderson, Ingabrit");
assertEquals(ingabrit, ingabritFromMap);
EmployeeBean notEmployee = testBusiness.getEmployee("Body, No");
assertNull(notEmployee);
testBusiness.employees.clear();
}
@Test
public void testAddCustomer() {
testBusiness.addCustomerToPhoneBook(sarah);
int numEmployees = testBusiness.customerPhoneBook.size();
assertEquals(1, numEmployees);
testBusiness.addCustomerToPhoneBook(joe);
testBusiness.addCustomerToPhoneBook(alma);
testBusiness.addCustomerToPhoneBook(hannah);
numEmployees = testBusiness.customerPhoneBook.size();
assertEquals(4, numEmployees);
testBusiness.addCustomerToPhoneBook(null);
numEmployees = testBusiness.customerPhoneBook.size();
assertEquals(4, numEmployees);
testBusiness.addCustomerToPhoneBook(customerNoLastName);
numEmployees = testBusiness.customerPhoneBook.size();
assertEquals(4, numEmployees);
testBusiness.addCustomerToPhoneBook(customerNoFirstName);
numEmployees = testBusiness.customerPhoneBook.size();
assertEquals(4, numEmployees);
testBusiness.customerPhoneBook.clear();
}
@Test
public void testGetCustomerPhoneNumber() {
testBusiness.customerPhoneBook.put("Azikiwe, Sarah", sarah.getPhoneNumber());
testBusiness.customerPhoneBook.put("Adams, Joe", joe.getPhoneNumber());
testBusiness.customerPhoneBook.put("Hernandez, Alma", alma.getPhoneNumber());
testBusiness.customerPhoneBook.put("Gustavson, Hannah", hannah.getPhoneNumber());
String sarahPhone = testBusiness.getCustomerPhoneNumber("Azikiwe, Sarah");
assertEquals("(208)555-1818", sarahPhone);
String joePhone = testBusiness.getCustomerPhoneNumber("Adams, Joe");
assertEquals("(208)888-1900", joePhone);
String nullPhone = testBusiness.getCustomerPhoneNumber(null);
assertNull(nullPhone);
String notCustomer = testBusiness.getCustomerPhoneNumber("Body, No");
assertNull(notCustomer);
testBusiness.customerPhoneBook.clear();
}
@Test
public void testGetAllCustomerPhoneNumbers() {
testBusiness.customerPhoneBook.put("Azikiwe, Sarah", sarah.getPhoneNumber());
testBusiness.customerPhoneBook.put("Adams, Joe", joe.getPhoneNumber());
testBusiness.customerPhoneBook.put("Hernandez, Alma", alma.getPhoneNumber());
testBusiness.customerPhoneBook.put("Gustavson, Hannah", hannah.getPhoneNumber());
String phoneBook = testBusiness.getAllCustomerPhoneNumbers();
String expected = "Adams, Joe - (208)888-1900; Azikiwe, Sarah - (208)555-1818; Gustavson, Hannah - (208)888-1599; Hernandez, Alma - (208)888-1598; ";
assertEquals(expected, phoneBook);
testBusiness.customerPhoneBook.clear();
}
}