mirror of
https://github.com/didyouexpectthat/cs-320.git
synced 2024-11-20 20:00:08 -08:00
230 lines
7.7 KiB
Java
230 lines
7.7 KiB
Java
/*
|
|
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 ContactTest {
|
|
|
|
/* Constructor Tests */
|
|
|
|
@Test
|
|
public void testConstructorValid() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertNotNull(contact);
|
|
assertEquals("1", contact.getId());
|
|
assertEquals("Cody", contact.getFirstName());
|
|
assertEquals("Cook", contact.getLastName());
|
|
assertEquals("4086342295", contact.getPhone());
|
|
assertEquals("315 Celebration Dr, 95035", contact.getAddress());
|
|
}
|
|
|
|
public void testSetIdTooLong() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("12345678901", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
public void testSetIdNull() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact(null, "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
public void testSetIdBlank() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorFirstNameTooLong() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Kohdeeohdee", "Cook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorFirstNameNull() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", null, "Cook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorFirstNameBlank() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "", "Cook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorLastNameTooLong() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "KookKookKook", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorLastNameNull() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", null, "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorLastNameBlank() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "", "4086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorPhoneTooShort() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "Cook", "408634229", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorPhoneTooLong() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "Cook", "14086342295", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorPhoneNull() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "Cook", null, "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorPhoneBlank() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "Cook", "", "315 Celebration Dr, 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorAddressTooLong() {
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, Milpitas, CA 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorAddressNull() {
|
|
assertThrows(IllegalArgumentException.class, () -> new Contact("1", "Cody", "Cook", "4086342295", null));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructorAddressBlank() {
|
|
assertThrows(IllegalArgumentException.class, () -> new Contact("1", "Cody", "Cook", "4086342295", ""));
|
|
}
|
|
|
|
/* firstName tests */
|
|
|
|
@Test
|
|
public void testSetFirstNameValid() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
contact.setFirstName("Kohdee");
|
|
assertEquals("Kohdee", contact.getFirstName());
|
|
}
|
|
|
|
@Test
|
|
public void testSetFirstNameTooLong() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setFirstName("Kohdeeohdee"));
|
|
}
|
|
|
|
public void testSetFirstNameNull() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setFirstName(null));
|
|
|
|
}
|
|
|
|
public void testSetFirstNameBlank() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setFirstName(""));
|
|
}
|
|
|
|
/* lastName tests */
|
|
|
|
@Test
|
|
public void testSetLastNameValid() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
contact.setLastName("Kook");
|
|
assertEquals("Kook", contact.getLastName());
|
|
}
|
|
|
|
@Test
|
|
public void testSetLastNameTooLong() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setLastName("Kookkookkook"));
|
|
}
|
|
|
|
@Test
|
|
public void testSetLastNameNull() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setLastName(null));
|
|
}
|
|
|
|
@Test
|
|
public void testSetLastNameBlank() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setLastName(null));
|
|
}
|
|
|
|
/* phone tests */
|
|
@Test
|
|
public void testSetPhoneValid() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
contact.setPhone("8018109276");
|
|
assertEquals("8018109276", contact.getPhone());
|
|
}
|
|
|
|
@Test
|
|
public void testSetPhoneTooLong() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setPhone("14086342295"));
|
|
}
|
|
|
|
@Test
|
|
public void testSetPhoneTooShort() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setPhone("6342295"));
|
|
}
|
|
|
|
@Test
|
|
public void testSetPhoneNull() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setPhone(null));
|
|
}
|
|
|
|
@Test
|
|
public void testSetPhoneBlank() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setPhone(""));
|
|
}
|
|
|
|
/* address tests */
|
|
|
|
@Test
|
|
public void testSetAddressValid() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
contact.setAddress("315 Celebration Drive, 95035");
|
|
assertEquals("315 Celebration Drive, 95035", contact.getAddress());
|
|
}
|
|
|
|
@Test
|
|
public void testSetAddressTooLong() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class,
|
|
() -> contact.setAddress("315 Celerbation Drive, Milpias, California 95035"));
|
|
}
|
|
|
|
@Test
|
|
public void testSetAddressNull() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setAddress(null));
|
|
}
|
|
|
|
@Test
|
|
public void testSetAddressBlank() {
|
|
Contact contact = new Contact("1", "Cody", "Cook", "4086342295", "315 Celebration Dr, 95035");
|
|
assertThrows(IllegalArgumentException.class, () -> contact.setAddress(""));
|
|
}
|
|
|
|
}
|