-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartCardTest.java
149 lines (125 loc) · 3.67 KB
/
SmartCardTest.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
package com.B5015845.CSC8002.Coursework.Testing;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Calendar;
import java.util.Date;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.B5015845.CSC8002.Coursework.Name;
import com.B5015845.CSC8002.Coursework.SmartCard;
import com.B5015845.CSC8002.Coursework.SmartCardNumber;
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 SmartCardTest, designed to test the ability to store and retrieve smart cards.
* @author Arianna Esposito
*/
public class SmartCardTest {
Name n;
Calendar calendar;
Date dob;
SmartCardNumber scn;
Calendar cal;
Date issueDate;
StudentID sid;
StudentType st;
StudentType badST;
Student s;
Student badStudent;
SmartCard sc;
@Before
public void setUp()
{
n = new Name("James","Blunt");
calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -20);
dob = calendar.getTime();
scn = SmartCardNumber.getInstance(n);
cal = Calendar.getInstance();
issueDate = cal.getTime();
sid = StudentID.getInstance();
st = StudentType.UG;
s = StudentFactory.getInstance(n, dob, st);
sc = new SmartCard(n, dob, sid, s.getStudentType());
}
@Test
public void testGetInstance()
{
assertTrue(sc instanceof SmartCard);
}
@Test
public void testGetStudentName()
{
assertEquals("James Blunt",sc.getStudentName().toString());
}
@Test
public void testGetDob()
{
assertEquals(dob.toString(),sc.getDob().toString());
}
/*
* Smart card number has random 2 digit which cannot be tested. Therefore, tests individual components that can be compared
* (initials and year) and tests 2 digit is in fact a two digit number.
*/
@Test
public void testGetSmartCardNumber()
{
assertEquals("JB", scn.getStudentName().getInitials());
assertEquals(2020, scn.getYear());
assertTrue(scn.getRandomNumbers() > 00 && scn.getRandomNumbers() < 99 );
}
@Test
public void testGetStudentID()
{
assertEquals(sid.toString(),sc.getStudentID().toString());
}
@Test
public void testGetIssueDate()
{
Calendar c = Calendar.getInstance();
Date testIssue = c.getTime();
assertEquals(testIssue.toString(),sc.getIssueDate().toString());
}
/*
* s is an undergraduate student. Tests that expiry date is 4 years from today
*/
@Test
public void testSetExpiryDate()
{
Calendar addCal = Calendar.getInstance();
addCal.add(Calendar.YEAR, 4);
Date expiryDate = addCal.getTime();
assertEquals(expiryDate.toString(), s.getSmartCard().getExpiryDate().toString());
}
/*
* Tests that illegal argument exception is thrown when an non-existent student type is inputted
*/
@Test(expected = IllegalArgumentException.class)
public void testSetExpiryDateIllegalArgumentException() throws IllegalArgumentException
{
badST = StudentType.doNOTUse;
badStudent = StudentFactory.getInstance(n, dob, badST);
}
@Test
public void testGetExpiryDate()
{
Calendar addCal = Calendar.getInstance();
addCal.add(Calendar.YEAR, 4);
Date expiryDate = addCal.getTime();
assertEquals(expiryDate.toString(), sc.getExpiryDate().toString());
}
@Test
public void testToString()
{
System.out.println(sc.toString());
}
@After
public void tearDown() {
StudentFactory.getUGs().clear();
StudentFactory.getPGTs().clear();
StudentFactory.getPGRs().clear();
}
}