mirror of
https://github.com/didyouexpectthat/cs-320.git
synced 2025-08-20 00:43:18 -07:00
Add files via upload
This commit is contained in:
parent
4f20a69a1a
commit
c2cd95eaa1
4 changed files with 505 additions and 0 deletions
101
ContactServiceTest.java
Normal file
101
ContactServiceTest.java
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
Cody Cook
|
||||
CS-320-H7022 Software Test Automation & QA 23EW2
|
||||
2023/11/11
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ContactServiceTest {
|
||||
|
||||
/* addContact tests */
|
||||
|
||||
@Test
|
||||
public void testAddContactValid() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
contactService.addContact(contact);
|
||||
assertEquals(1, contactService.getAllContacts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddContactsValid() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact1 = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
contactService.addContact(contact1);
|
||||
Contact contact2 = new Contact("2", "Kohdee", "Kook", "8018109276", "1 North Temple Drive, 84106");
|
||||
contactService.addContact(contact2);
|
||||
assertEquals(2, contactService.getAllContacts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddContactDuplicateId() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact1 = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
Contact contact2 = new Contact("1", "Kohdee", "Kook", "8018109276", "1 North Temple Drive, 84106");
|
||||
contactService.addContact(contact1);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
contactService.addContact(contact2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddContactsDuplicateId() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact1 = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
contactService.addContact(contact1);
|
||||
Contact contact2 = new Contact("2", "Kohdee", "Kook", "8018109276", "1 North Temple Drive, 84106");
|
||||
contactService.addContact(contact2);
|
||||
Contact contact3 = new Contact("2", "Barack", "Obama", "2013110519", "White House, Washington DC");
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
contactService.addContact(contact3);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteContact() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
contactService.addContact(contact);
|
||||
assertEquals(1, contactService.getAllContacts().size());
|
||||
contactService.deleteContact("1");
|
||||
assertEquals(0, contactService.getAllContacts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteInvalidContact() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
contactService.addContact(contact);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
contactService.deleteContact("2");
|
||||
});
|
||||
}
|
||||
|
||||
/* updating contact tests */
|
||||
@Test
|
||||
public void testUpdateContact() {
|
||||
ContactService contactService = new ContactService();
|
||||
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
||||
contactService.addContact(contact);
|
||||
contactService.updateContact("1", "Kohdee", "Kook", "8018109276", "1 North Temple Drive, 84106");
|
||||
Contact contactValidator = contactService.getContactById("1");
|
||||
assertNotNull(contactValidator);
|
||||
assertEquals("1", contactValidator.getId());
|
||||
assertEquals("Kohdee", contactValidator.getFirstName());
|
||||
assertEquals("Kook", contactValidator.getLastName());
|
||||
assertEquals("8018109276", contactValidator.getPhone());
|
||||
assertEquals("1 North Temple Drive, 84106", contactValidator.getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNonExistentContact() {
|
||||
ContactService contactService = new ContactService();
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
contactService.updateContact("2", "Kohdee", "Kook", "8018109276", "1 North Temple Drive, 84106");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue