-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactServiceTest.java
More file actions
65 lines (51 loc) · 2.31 KB
/
ContactServiceTest.java
File metadata and controls
65 lines (51 loc) · 2.31 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
package contact;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class ContactServiceTest {
private ContactService contactService;
@Before
public void setUp() {
contactService = new ContactService();
}
@Test
public void addContactTest() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contactService.addContact(contact);
assertEquals(contact, contactService.getContact("1"));
}
@Test(expected = IllegalArgumentException.class)
public void addDuplicateContactTest() {
ContactClass contact1 = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
ContactClass contact2 = new ContactClass("1", "Shan", "Sheehan", "1234567890", "San Diego, CA");
contactService.addContact(contact1);
contactService.addContact(contact2);
}
@Test
public void deleteContactTest() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contactService.addContact(contact);
contactService.deleteContact("1");
try {
contactService.getContact("1");
fail("Expected IllegalArgumentException to be thrown");
} catch (IllegalArgumentException e) {
assertEquals("Contact with ID 1 does not exist.", e.getMessage());
}
}
@Test
public void updateContactTest() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contactService.addContact(contact);
contactService.updateContact("1", "Shan", "Sheehan", "1234567890", "San Diego, CA");
ContactClass updatedContact = contactService.getContact("1");
assertEquals("Shan", updatedContact.getFirstName());
assertEquals("Sheehan", updatedContact.getLastName());
assertEquals("1234567890", updatedContact.getPhoneNumber());
assertEquals("San Diego, CA", updatedContact.getAddress());
}
@Test(expected = IllegalArgumentException.class)
public void updateNonexistentContactTest() {
contactService.updateContact("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
}
}