-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUGTest.java
165 lines (138 loc) · 4.06 KB
/
UGTest.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
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.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;
import com.B5015845.CSC8002.Coursework.Module;
/**
* This test class is UGTest, designed to test the ability to store and retrieve UGs.
* @author Arianna Esposito
*/
public class UGTest {
Name n;
Calendar calendar;
Calendar cal;
Date dob;
Date tooYoung;
StudentType studentType;
Student ug;
Student badUG;
@Before
public void setUp()
{
n = new Name("Harry","Potter");
calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -18);
dob = calendar.getTime();
cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -5);
tooYoung = cal.getTime();
studentType = StudentType.UG;
ug = StudentFactory.getInstance(n, dob, studentType);
badUG = StudentFactory.getInstance(n, tooYoung, studentType);
}
@Test
public void testGetName()
{
assertEquals("Harry Potter",ug.getName().toString());
}
@Test
public void testGetDob()
{
assertEquals(calendar.getTime(),ug.getDob());
}
@Test
public void testGetStudentID()
{
assertTrue(ug.getStudentID() instanceof StudentID);
}
@Test
public void testToString()
{
System.out.println(ug.toString());
}
@Test
public void testGetStudentType()
{
assertEquals(StudentType.UG,ug.getStudentType());
}
@Test
public void testGetRequiredCredits()
{
assertEquals(120, ug.getRequiredCredits());
}
@Test
public void testGetPassMark()
{
assertEquals(40, ug.getPassMark());
}
@Test
public void testGetModuleList()
{
assertTrue(ug.getModuleList().isEmpty());
}
@Test
public void testAddModuleToList() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5001");
ug.addModuleToList(m);
assertTrue(ug.getModuleList().contains(m));
}
@Test
public void testHasEnoughCredits() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("TST0001"); //module with 120 credits
ug.addModuleToList(m);
assertTrue(ug.hasEnoughCredits());
}
/*
* Tests UG has not got too many credits; tests the rejection of adding a 300 credit module.
*/
@Test(expected = LimitExceededException.class)
public void testHasEnoughCreditsLimitExceededOver() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("TST0003"); //module with 300 credits
ug.addModuleToList(m);
assertTrue(ug.hasEnoughCredits());
assertTrue(ug.getModuleList().isEmpty());
}
/*
* Tests that UG is not allowed to have too few credits.
*/
@Test(expected = LimitExceededException.class)
public void testHasEnoughCreditsLimitExceededUnder() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5001"); //module with 20 credits
ug.addModuleToList(m);
assertTrue(ug.hasEnoughCredits());
}
@Test
public void testHowManyCredits() throws FileNotFoundException, IllegalArgumentException, LimitExceededException
{
Module m = Module.getInstance("CSC5001"); //20 credits
ug.addModuleToList(m);
assertEquals(m.getCredits(), ug.howManyCredits());
}
@Test
public void testIsOfAge()
{
assertTrue(ug.isOfAge());
assertTrue(!badUG.isOfAge());
}
@After
public void tearDown() {
StudentFactory.getUGs().clear();
StudentFactory.getPGTs().clear();
StudentFactory.getPGRs().clear();
}
}