-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactServiceTest.java
More file actions
81 lines (75 loc) · 3.4 KB
/
ContactServiceTest.java
File metadata and controls
81 lines (75 loc) · 3.4 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
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ContactServiceTest {
//creates a contact and test values
// Generates contacts with a unique ID using the ContactService addContact method
@Test
void testContactServiceClass() {
ContactService.addContact("Tom", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
//System.out.println(ContactService.contactList.get(0).getId()); used for debugging
assertTrue(ContactService.contactList.get(0).getId().equals("1000000002"));
assertTrue(ContactService.contactList.get(0).getFirstName().equals("Tom"));
assertTrue(ContactService.contactList.get(0).getLastName().equals("Brady"));
assertTrue(ContactService.contactList.get(0).getPhone().equals("9095679789"));
assertTrue(ContactService.contactList.get(0).getAddress().equals("123 9th St. San Bernardino, CA 91158"));
}
// confirm deletion of a contact
@Test
void testContactServiceDelete() {
ContactService.addContact("Tom", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
int size = ContactService.contactList.size();
//System.out.println(ContactService.contactList.get(size - 1).getId());
ContactService.deleteContact("1000000003");
//ContactService.searchContact("1000000003");
//System.out.println(ContactService.contactList.get(1).getId());
assertTrue(ContactService.searchContact("1000000003") == 2);
}
// update first name test
@Test
void testContactServiceUpdateFirstName() {
ContactService.addContact("Grace", "Brady", "9095679789", "Christmas Ave.");
int size = ContactService.contactList.size();
System.out.println(ContactService.contactList.get(size - 1).getId());
System.out.println(ContactService.contactList.get(size - 1).getFirstName());
ContactService.updateFirstName("1000000003", "Grace");
System.out.println(ContactService.contactList.get(size - 1).getFirstName());
assertTrue(ContactService.contactList.get(size - 1).getFirstName().equals("Grace"));
}
// using 1000000003 to test the rest
// test confirming update to last name
@Test
void testContactServiceUpdateLastName() {
int size = ContactService.contactList.size();
ContactService.updateLastName("1000000003", "Daniels");
assertTrue(ContactService.contactList.get(size - 1).getLastName().equals("Daniels"));
}
// test confirming update to phone number
@Test
void testContactServiceUpdatePhone() {
int target = 0;
target = ContactService.findIndex("1000000003");
ContactService.updatePhoneNum("1000000003", "8884446161");
assertTrue(ContactService.contactList.get(target).getPhone().equals("8884446161"));
}
// test confirming update to address
@Test
void testContactServiceUpdateAddress() {
int target = 0;
target = ContactService.findIndex("1000000003");
ContactService.updateAddress("1000000003", "456 9th St. Acton, CA 91542");
assertTrue(ContactService.contactList.get(target).getAddress().equals("456 9th St. Acton, CA 91542"));
}
// test to confirm unique ID
@Test
void testContactServiceUniqueId() {
Contact newContact = new Contact("49594", "Sanchez", "Daniels", "9095679789", "Original Contact Address");
ContactService.addContact(newContact);
Contact duplicateId = new Contact("49594", "Sanchez", "Daniels", "9095679789", "Duplicate Contact Address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ContactService.addContact(duplicateId);
});
}
}