-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentTest.java
292 lines (251 loc) · 9 KB
/
StudentTest.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment1;
import java.time.LocalDate;
import java.time.Month;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author JWright
*/
public class StudentTest {
Student validStudent1;
public StudentTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
validStudent1 = new Student("Fred","Flintstone","13 Cobble Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(2000, Month.SEPTEMBER, 3),"COPA", 1234,
LocalDate.of(2016, Month.JANUARY, 10));
}
@After
public void tearDown() {
}
/**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayValidInput() {
LocalDate expResult = LocalDate.of(2000, Month.DECEMBER, 10);
validStudent1.setBirthday(expResult);
LocalDate result = validStudent1.getBirthday();
assertEquals(expResult, result);
}
/**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayInvalidInput() {
LocalDate invalidBirthday = LocalDate.of(1000, Month.DECEMBER, 10);
try{
validStudent1.setBirthday(invalidBirthday);
fail("The invalid date did not throw an exception");
}
catch (IllegalArgumentException e)
{
LocalDate expResult = LocalDate.of(2000, Month.SEPTEMBER, 03);
LocalDate result = validStudent1.getBirthday();
assertEquals(expResult, result);
}
}
/**
* Test of getYearEnrolled method, of class Student.
*/
@Test
public void testGetYearEnrolled() {
int expResult = 2016;
int result = validStudent1.getYearEnrolled();
assertEquals(expResult, result);
}
/**
* Test of inGoodStanding method, of class Student.
*/
@Test
public void testInGoodStanding() {
boolean expResult = true;
boolean result = validStudent1.inGoodStanding();
assertEquals(expResult, result);
}
/**
* Test of suspendStudent method, of class Student.
*/
@Test
public void testSuspendStudent() {
validStudent1.suspendStudent();
boolean expResult = false;
boolean result = validStudent1.inGoodStanding();
assertEquals(expResult, result);
}
/**
* Test of reinstateStudent method, of class Student.
*/
@Test
public void testReinstateStudent() {
validStudent1.suspendStudent();
validStudent1.reinstateStudent();
boolean expResult = true;
boolean result = validStudent1.inGoodStanding();
assertEquals(expResult, result);
}
/**
* Test of changeAddress method, of class Student.
*/
@Test
public void testChangeAddress() {
String street = "55 Granite Ridge Road";
String city = "Bedrock";
String province = "Dendi";
String postalCode = "B3B2T2";
validStudent1.changeAddress(street, city, province, postalCode);
String expResult = "55 Granite Ridge Road, Bedrock, Dendi, B3B2T2";
String result = validStudent1.getFullAddress();
assertEquals(expResult, result);
}
/**
* Test of changeAddress method, of class Student.
*/
@Test
public void testChangeAddressInvalidPostalCode() {
String street = "55 Granite Ridge Road";
String city = "Bedrock";
String province = "Dendi";
String postalCode = "b3b2t2";
validStudent1.changeAddress(street, city, province, postalCode);
String expResult = "55 Granite Ridge Road, Bedrock, Dendi, B3B2T2";
String result = validStudent1.getFullAddress();
assertEquals(expResult, result);
}
/**
* Test of getAddress method, of class Student.
*/
@Test
public void testGetAddress() {
String expResult = "13 Cobble Way, Bedrock, Dendi, A2A0T3";
String result = validStudent1.getFullAddress();
assertEquals(expResult, result);
}
/**
* Test of toString method, of class Student.
*/
@Test
public void testToString() {
String expResult = "Fred Flintstone, student number is 1234";
String result = validStudent1.toString();
assertEquals(expResult, result);
}
/**
* Test of getYearsAtCollege method, of class Student.
*/
@Test
public void testGetYearsAtCollege() {
int expResult = 1;
int result = validStudent1.getYearsAtCollege();
assertEquals(expResult, result);
}
/**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayValid() {
LocalDate newBirthday = LocalDate.of(2000, Month.APRIL, 1);
validStudent1.setBirthday(newBirthday);
assertEquals(newBirthday, validStudent1.getBirthday());
}
/**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayInvalid() {
LocalDate newBirthday = LocalDate.of(2016, Month.APRIL, 1);
try
{
validStudent1.setBirthday(newBirthday);
fail("The setBirthday method should have ensured that the student is at least 14");
}
catch (IllegalArgumentException e)
{
System.out.printf("The setBirthday with too young of an input, exception = \"%s\"%n", e.getMessage());
}
}
/**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayInvalid2() {
LocalDate newBirthday = LocalDate.of(1897, Month.APRIL, 1);
try
{
validStudent1.setBirthday(newBirthday);
fail("The setBirthday method should have ensured that the student is older than 90");
}
catch (IllegalArgumentException e)
{
System.out.printf("The setBirthday with a birthday too old, exception = \"%s\"%n", e.getMessage());
}
}
/**
* Test of creating a Student that is not a valid age (too old)
*/
@Test
public void testSetBirthdayInvalid3() {
try
{
Student invalidStudent = new Student("Fred","Flintstone","13 Cobble Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(1900, Month.SEPTEMBER, 3),"COPA", 1234,
LocalDate.of(2016, Month.MARCH, 10));
fail("The student constructor should have failed because this one is older than 90");
}
catch (IllegalArgumentException e)
{
System.out.printf("The constructor caught that the student was too old, exception = \"%s\"%n", e.getMessage());
}
}
/**
* Test of creating a Student that is not a valid age (too young)
*/
@Test
public void testSetBirthdayInvalid4() {
try
{
Student invalidStudent = new Student("Fred","Flintstone","13 Cobble Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(2014, Month.SEPTEMBER, 3),"COPA", 1234,
LocalDate.of(2016, Month.MARCH, 10));
fail("The student constructor should have failed because this one is too young");
}
catch (IllegalArgumentException e)
{
System.out.printf("The constructor caught that the student was too young, exception = \"%s\"%n", e.getMessage());
}
}
/**
* Test of creating a Student with an invalid student number
*/
@Test
public void testSetBirthdayInvalid5() {
try
{
Student invalidStudent = new Student("Fred","Flintstone","13 Cobble Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(2000, Month.SEPTEMBER, 3),"COPA", 0,
LocalDate.of(2016, Month.MARCH, 10));
fail("The student constructor should have failed because of an invalid student number");
}
catch (IllegalArgumentException e)
{
System.out.printf("The constructor caught that the student had an invalid student number, exception = \"%s\"%n", e.getMessage());
}
}
}