-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPGTTest.java
163 lines (138 loc) · 4.1 KB
/
PGTTest.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
package com.B5015845.CSC8002.Coursework.Testing;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException;
import java.util.Calendar;
import java.util.Date;
import javax.naming.LimitExceededException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.B5015845.CSC8002.Coursework.Module;
import com.B5015845.CSC8002.Coursework.Name;
import com.B5015845.CSC8002.Coursework.Student;
import com.B5015845.CSC8002.Coursework.StudentFactory;
import com.B5015845.CSC8002.Coursework.StudentID;
import com.B5015845.CSC8002.Coursework.StudentType;
/**
* This test class is PGTTest, designed to test the ability to store and retrieve PGTs.
* @author Arianna Esposito
*/
public class PGTTest {
Name n;
Calendar calendar;
Calendar cal;
Date dob;
Date tooYoung;
StudentType studentType;
Student pgt ;
Student badPGT;
@Before
public void setUp()
{
n = new Name("Hermione","Granger");
calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -20);
dob = calendar.getTime();
cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -5);
tooYoung = cal.getTime();
studentType = StudentType.PGT;
pgt = StudentFactory.getInstance(n, dob, studentType);
badPGT = StudentFactory.getInstance(n, tooYoung, studentType);
}
@Test
public void testGetName()
{
assertEquals("Hermione Granger",pgt.getName().toString());
}
@Test
public void testGetDob()
{
assertEquals(calendar.getTime(),pgt.getDob());
}
@Test
public void testGetStudentID()
{
assertTrue(pgt.getStudentID() instanceof StudentID);
}
@Test
public void testToString()
{
System.out.println(pgt.toString());
}
@Test
public void testGetStudentType()
{
assertEquals(StudentType.PGT,pgt.getStudentType());
}
@Test
public void testGetRequiredCredits()
{
assertEquals(180, pgt.getRequiredCredits());
}
@Test
public void testGetPassMark()
{
assertEquals(50, pgt.getPassMark());
}
@Test
public void testGetModuleList()
{
assertTrue(pgt.getModuleList().isEmpty());
}
@Test
public void testAddModuleToList() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5001");
pgt.addModuleToList(m);
assertTrue(pgt.getModuleList().contains(m));
}
@Test
public void testHasEnoughCredits() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("TST0002"); //module with 180 credits
pgt.addModuleToList(m);
assertTrue(pgt.hasEnoughCredits());
}
/*
* Tests PGT does not add module with too many credits to sustain; tests their rejection of this module into their list.
*/
@Test(expected = LimitExceededException.class)
public void testHasEnoughCreditsLimitExceededOver() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("TST0003"); //module with 300 credits
pgt.addModuleToList(m);
assertTrue(pgt.hasEnoughCredits());
assertTrue(pgt.getModuleList().isEmpty());
}
/*
* Tests that PGT cannot have too few credits.
*/
@Test(expected = LimitExceededException.class)
public void testHasEnoughCreditsLimitExceededUnder() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5003"); //module with 20 credits
pgt.addModuleToList(m);
assertTrue(pgt.hasEnoughCredits());
}
@Test
public void testHowManyCredits() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5009"); //20 credits
pgt.addModuleToList(m);
assertEquals(m.getCredits(), pgt.howManyCredits());
}
@Test
public void testIsOfAge()
{
assertTrue(pgt.isOfAge());
assertTrue(!badPGT.isOfAge());
}
@After
public void tearDown() {
StudentFactory.getUGs().clear();
StudentFactory.getPGTs().clear();
StudentFactory.getPGRs().clear();
}
}