-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentManagementSystemTest.java
169 lines (148 loc) · 5.27 KB
/
StudentManagementSystemTest.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
package com.B5015845.CSC8002.Coursework.Testing;
import static org.junit.Assert.*;
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.StudentID;
import com.B5015845.CSC8002.Coursework.StudentType;
import com.B5015845.CSC8002.Coursework.Supervisor;
import com.B5015845.CSC8002.Coursework.Management.StudentManagementSystem;
import com.B5015845.CSC8002.Coursework.Module;
import com.B5015845.CSC8002.Coursework.Name;
import com.B5015845.CSC8002.Coursework.ResearchStudent;
import com.B5015845.CSC8002.Coursework.Student;
import com.B5015845.CSC8002.Coursework.StudentFactory;
/**
* This test class is StudentManagementSystemTest, designed to test the ability of the methods in the Student Management System.
* @author Arianna Esposito
*/
public class StudentManagementSystemTest {
Name n;
Name n2;
Name n3;
Name n4;
Date dob;
Date dob2;
StudentType UGType;
StudentType PGTType;
StudentType PGRType;
Student ug;
Student ug2;
Student pgt;
ResearchStudent pgr;
@Before
public void setUp()
{
n = new Name("Frodo","Baggins");
n2 = new Name("Samwise","Gamgee");
n3 = new Name("Pippin","Took");
n4 = new Name("Merry","Brandybuck");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -30);
dob = calendar.getTime();
Calendar cal = Calendar.getInstance();
dob2 = cal.getTime();
UGType = StudentType.UG;
PGTType = StudentType.PGT;
PGRType = StudentType.PGR;
ug = StudentFactory.getInstance(n, dob, UGType);
ug2 = StudentFactory.getInstance(n2, dob2, UGType);
pgt = StudentFactory.getInstance(n3, dob, PGTType);
pgr = (ResearchStudent) StudentFactory.getInstance(n4, dob, PGRType);
}
@Test
public void testNoOfStudents()
{
assertEquals(2, StudentFactory.getUGs().size());
assertEquals(1, StudentFactory.getPGTs().size());
assertEquals(1, StudentFactory.getPGRs().size());
}
@Test
public void testRegisterStudent()
{
Student ug3 = StudentFactory.getInstance(n4, dob, UGType);
StudentManagementSystem.registerStudent(ug3);
assertTrue(StudentFactory.getUGs().containsKey(ug3.getStudentID()));
}
@Test
public void testAmendStudentDataModules() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5002");
StudentManagementSystem.amendStudentData(ug.getStudentID(), m);
assertTrue(ug.getModuleList().contains(m));
}
/*
* Tests that PGR students can't add modules to module list
*/
@Test(expected = LimitExceededException.class)
public void testAmendStudentDataModulesLimitExceededPGR() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5002");
StudentManagementSystem.amendStudentData(pgr.getStudentID(), m);
}
@Test
public void testAmendStudentDataSupervisors() throws FileNotFoundException, IllegalArgumentException
{
Supervisor s = Supervisor.getInstance("Peter Peterson");
StudentManagementSystem.amendStudentData(pgr.getStudentID(), s);
assertEquals(s, pgr.getSupervisorName());
}
/*
* Tests that supervisors can't be added to students who aren't PGR
*/
@Test(expected=IllegalArgumentException.class)
public void testAmendStudentDataSupervisorsIllegalArgument() throws IllegalArgumentException, FileNotFoundException
{
Supervisor s = Supervisor.getInstance("Peter Peterson");
StudentManagementSystem.amendStudentData(ug.getStudentID(), s);
}
@Test
public void testTerminateStudent()
{
Student ug3 = StudentFactory.getInstance(n4, dob, UGType);
StudentManagementSystem.terminateStudent(ug3.getStudentType(), ug3.getStudentID());
assertTrue(!StudentFactory.getUGs().containsKey(ug3.getStudentID()));
}
/*
* Tests that non-existent students can't be removed from the system
*/
@Test(expected=IllegalArgumentException.class) //throwing AssertionError
public void testTerminateStudentIllegalArgumentStudentID() throws IllegalArgumentException
{
StudentID sid = StudentID.getInstance();
StudentManagementSystem.terminateStudent(UGType, sid);
}
/*
* Tests that the student type of a student must be UG, PGT or PGR for termination
*/
@Test(expected=IllegalArgumentException.class)
public void testTerminateStudentIllegalArgumentStudentType() throws IllegalArgumentException
{
StudentType test = StudentType.doNOTUse;
Student s = StudentFactory.getInstance(n4, dob, test);
StudentManagementSystem.terminateStudent(test, s.getStudentID());
}
@Test
public void testGetSmartCard()
{
assertEquals(ug.getSmartCard(), StudentManagementSystem.getSmartCard(ug));
}
/*
* Tests that is student is not the correct age, a smart card will not be issued
*/
@Test(expected = IllegalArgumentException.class)
public void testGetSmartCardIllegalArgumentAge() throws IllegalArgumentException
{
StudentManagementSystem.getSmartCard(ug2);
}
@After
public void tearDown() {
StudentFactory.getUGs().clear();
StudentFactory.getPGTs().clear();
StudentFactory.getPGRs().clear();
}
}