-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontactClassTest.java
More file actions
65 lines (53 loc) · 2.6 KB
/
contactClassTest.java
File metadata and controls
65 lines (53 loc) · 2.6 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.Test;
import org.junit.jupiter.api.Assertions;
public class contactClassTest {
@Test
public void testSetFirstName() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contact.setFirstName("Londelle");
Assertions.assertEquals("Londelle", contact.getFirstName());
}
@Test
public void testSetInvalidFirstName() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
Assertions.assertThrows(IllegalArgumentException.class, () -> contact.setFirstName("LondelleLondelleLondelle"));
Assertions.assertEquals("Londelle", contact.getFirstName()); // Make sure the value is not changed
}
@Test
public void testSetLastName() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contact.setLastName("Sheehan");
Assertions.assertEquals("Sheehan", contact.getLastName());
}
@Test
public void testSetInvalidLastName() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
Assertions.assertThrows(IllegalArgumentException.class, () -> contact.setLastName("SheehanSheehanSheehan"));
Assertions.assertEquals("Sheehan", contact.getLastName()); // Make sure the value is not changed
}
@Test
public void testSetPhoneNumber() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contact.setPhoneNumber("1234567890");
Assertions.assertEquals("1234567890", contact.getPhoneNumber());
}
@Test
public void testSetInvalidPhoneNumber() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
Assertions.assertThrows(IllegalArgumentException.class, () -> contact.setPhoneNumber("123456789012345"));
Assertions.assertEquals("1234567890", contact.getPhoneNumber()); // Make sure the value is not changed
}
@Test
public void testSetAddress() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
contact.setAddress("San Diego, CA");
Assertions.assertEquals("San Diego, CA", contact.getAddress());
}
@Test
public void testSetInvalidAddress() {
ContactClass contact = new ContactClass("1", "Londelle", "Sheehan", "1234567890", "San Diego, CA");
Assertions.assertThrows(IllegalArgumentException.class, () -> contact.setAddress("San Diego, CA San Diego, CA San Diego, CA San Diego, CA San Diego, CA San Diego, CA"));
Assertions.assertEquals("San Diego, CA", contact.getAddress()); // Make sure the value is not changed
}
}