-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactTest.java
More file actions
198 lines (188 loc) · 6.4 KB
/
ContactTest.java
File metadata and controls
198 lines (188 loc) · 6.4 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
//import Test.Contact; - Was part of the Junit Test creation but showed error
class ContactTest {
// test for working contact creation
@Test
void testContactCalss() {
Contact newContact = new Contact("1001", "Tom", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
assertTrue(newContact.getFirstName().equals("Tom"));
assertTrue(newContact.getLastName().equals("Brady"));
assertTrue(newContact.getId().equals("1001"));
assertTrue(newContact.getPhone().equals("9095679789"));
assertTrue(newContact.getAddress().equals("123 9th St. San Bernardino, CA 91158"));
}
// test for too long ID
@Test
void testContactClassIdTooLong() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10000000000", "Tom", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for null ID
@Test
void testContactClassIdNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact(null, "Tom", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for too long first name
@Test
void testContactClassFirstNameTooLong() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom123456", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for null first name
@Test
void testContactClassFirstNameNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", null, "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for too long last name
@Test
void testContactClassLastNameTooLong() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom", "Brady123456", "9095679789",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for null last name
@Test
void testContactClassLastNameNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom", null, "9095679789",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for not exactly 10 characters
@Test
void testContactClassPhoneNot10() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom", "Brady", "661888611",
"123 9th St. San Bernardino, CA 91158");
});
}
// test for null phone
@Test
void testContactCalssPhoneNull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom", "Brady", null,
"123 9th St. San Bernardino, CA 91158");
});
}
// test for too long address
@Test
void testContactClassAddressTooLong() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom", "Brady", "9095679789",
"123 9th St. San Bernardino, CA 91158 123456");
});
}
// test for null address
@Test
void testContactClassAddressnull() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Contact("10001", "Tom", "Brady", "9095679789",
null);
});
}
// test fName setter method
@Test
void testContactClassSetFirstName() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
newContact.setFirstName("Jonesy");
assertTrue(newContact.getFirstName().equals("Jonesy"));
}
@Test
void testContactClassSetFirstNameTooLong() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setFirstName("JonesyTooLong");
});
}
@Test
void testContactClassSetFirstNameNull() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setFirstName(null);
});
}
// test lName setter method
@Test
void testContactClassSetLastName() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
newContact.setLastName("Jonesy");
assertTrue(newContact.getLastName().equals("Jonesy"));
}
@Test
void testContactClassSetLastNameTooLong() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setLastName("JonesyTooLong");
});
}
@Test
void testContactClassSetLastNameNull() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setLastName(null);
});
}
// test phone setter method
@Test
void testContactClassSetPhone() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
newContact.setPhone("6618886119");
assertTrue(newContact.getPhone().equals("6618886119"));
}
@Test
void testContactClassSetPhoneTooLong() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setPhone("66188861199999999");
});
}
@Test
void testContactClassSetPhoneNull() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setPhone(null);
});
}
@Test
void testContactClassSetPhoneTooShort() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setPhone("44444");
});
}
// test address setter method
@Test
void testContactClassSetAddress() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
newContact.setAddress("new address 2");
assertTrue(newContact.getAddress().equals("new address 2"));
}
@Test
void testContactClassSetAddressTooLong() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setAddress("new address too long 1324566874685");
});
}
@Test
void testContactClassSetAddressNull() {
Contact newContact = new Contact("845", "Jack", "Jones", "9095679789", "new address");
Assertions.assertThrows(IllegalArgumentException.class, () -> {
newContact.setAddress(null);
});
}
}