-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactServiceTest.java
51 lines (42 loc) · 1.76 KB
/
ContactServiceTest.java
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
package test;
import javamilestone.ContactService;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ContactServiceTest {
@Test
public void testAddContact() {
ContactService service = new ContactService();
service.addContact("1", "Mikayla", "David", "1234567890", "123 Main St");
assertNotNull(service.getContact("1"));
}
@Test
public void testDeleteContact() {
ContactService service = new ContactService();
service.addContact("1", "Mikayla", "David", "1234567890", "123 Main St");
service.deleteContact("1");
assertNull(service.getContact("1"));
}
@Test
public void testUpdateContact() {
ContactService service = new ContactService();
service.addContact("1", "Mikayla", "David", "1234567890", "123 Main St");
service.updateContact("1", "Mikayla", "Smith", "0987654321", "321 Main St");
assertNotNull(service.getContact("1"));
}
@Test
public void testAddDuplicateContact() {
ContactService service = new ContactService();
service.addContact("1", "Mikayla", "David", "1234567890", "123 Main St");
assertThrows(IllegalArgumentException.class, () -> service.addContact("1", "John", "Doe", "0987654321", "321 Main St"));
}
@Test
public void testDeleteNonExistentContact() {
ContactService service = new ContactService();
assertThrows(IllegalArgumentException.class, () -> service.deleteContact("1"));
}
@Test
public void testUpdateNonExistentContact() {
ContactService service = new ContactService();
assertThrows(IllegalArgumentException.class, () -> service.updateContact("1", "Mikayla", "Smith", "0987654321", "321 Main St"));
}
}