-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrescriptionTest.java
221 lines (183 loc) · 8.89 KB
/
PrescriptionTest.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
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Date;
public class PrescriptionTest {
private static int prescriptionCounter = 0; // static counter to track and increment the prescID
@BeforeEach
public void setUp() {
prescriptionCounter++; // increment the prescription ID for each test
}
// test valid prescription addition
@Test
public void testAddPrescription_ValidData() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter;
prescription.firstName = "John";
prescription.lastName = "Smith";
prescription.address = "123 Main Street, Suburbia, 12345, Country";
prescription.sphere = 0.0f;
prescription.cylinder = 0.0f;
prescription.axis = 90.0f;
prescription.examinationDate = new Date();
prescription.optometrist = "Dr. William Smith";
boolean result = prescription.addPrescription();
assertTrue(result, "valid prescription should return true");
}
// test prescription fails with short first name
@Test
public void testAddPrescription_InvalidFirstNameTooShort() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter;
prescription.firstName = "as"; // too short
prescription.lastName = "Smith";
prescription.address = "123 Main Street, Suburbia, 12345, Country";
prescription.sphere = 0.0f;
prescription.cylinder = 0.0f;
prescription.axis = 90.0f;
prescription.examinationDate = new Date();
prescription.optometrist = "Dr. William Smith";
boolean result = prescription.addPrescription();
assertFalse(result, "prescription with short first name should return false");
}
// test prescription fails with long last name
@Test
public void testAddPrescription_InvalidLastNameTooLong() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter;
prescription.firstName = "John";
prescription.lastName = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // too long
prescription.address = "123 Main Street, Suburbia, 12345, Country";
prescription.sphere = 0.0f;
prescription.cylinder = 0.0f;
prescription.axis = 90.0f;
prescription.examinationDate = new Date();
prescription.optometrist = "Dr. William Smith";
boolean result = prescription.addPrescription();
assertFalse(result, "prescription with long last name should return false");
}
// test prescription fails with short address
@Test
public void testAddPrescription_InvalidAddressTooShort() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter;
prescription.firstName = "John";
prescription.lastName = "Smith";
prescription.address = "Short Address"; // less than 20 characters
prescription.sphere = 0.0f;
prescription.cylinder = 0.0f;
prescription.axis = 90.0f;
prescription.examinationDate = new Date();
prescription.optometrist = "Dr. William Smith";
boolean result = prescription.addPrescription();
assertFalse(result, "prescription with short address should return false");
}
// test prescription fails with sphere value out of range
@Test
public void testAddPrescription_InvalidSphereOutOfRange() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter;
prescription.firstName = "John";
prescription.lastName = "Smith";
prescription.address = "123 Main Street, Suburbia, 12345, Country";
prescription.sphere = 25.0f; // out of range
prescription.cylinder = 0.0f;
prescription.axis = 90.0f;
prescription.examinationDate = new Date();
prescription.optometrist = "Dr. William Smith";
boolean result = prescription.addPrescription();
assertFalse(result, "prescription with sphere out of range should return false");
}
// test prescription fails with short optometrist name
@Test
public void testAddPrescription_InvalidOptometristNameTooShort() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter;
prescription.firstName = "John";
prescription.lastName = "Smith";
prescription.address = "123 Main Street, Suburbia, 12345, Country";
prescription.sphere = 0.0f;
prescription.cylinder = 0.0f;
prescription.axis = 90.0f;
prescription.examinationDate = new Date();
prescription.optometrist = "Dr."; // too short
boolean result = prescription.addPrescription();
assertFalse(result, "prescription with short optometrist name should return false");
}
// test valid remark addition
@Test
public void testAddRemark_ValidRemark() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark = "This is a valid remark with more than six words.";
String category = "client";
boolean result = prescription.addRemark(remark, category);
assertTrue(result, "valid remark should return true");
}
// test addRemark fails with null remark
@Test
public void testAddRemark_NullRemark() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark = null;
String category = "client";
boolean result = prescription.addRemark(remark, category);
assertFalse(result, "null remark should return false");
}
// test addRemark fails with remark too short
@Test
public void testAddRemark_RemarkTooShort() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark = "Too short";
String category = "client";
boolean result = prescription.addRemark(remark, category);
assertFalse(result, "remark with less than 6 words should return false");
}
// test addRemark fails with remark too long
@Test
public void testAddRemark_RemarkTooLong() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark = "This remark has way too many words and should definitely be longer than twenty words so that it fails the test case for remarks that are too long.";
String category = "client";
boolean result = prescription.addRemark(remark, category);
assertFalse(result, "remark with more than 20 words should return false");
}
// test addRemark fails when first character is not uppercase
@Test
public void testAddRemark_FirstCharacterNotUppercase() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark = "this remark starts with a lowercase letter.";
String category = "client";
boolean result = prescription.addRemark(remark, category);
assertFalse(result, "remark starting with lowercase letter should return false");
}
// test addRemark fails with invalid category
@Test
public void testAddRemark_InvalidCategory() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark = "This is a valid remark with more than six words.";
String category = "invalid";
boolean result = prescription.addRemark(remark, category);
assertFalse(result, "remark with invalid category should return false");
}
// test addRemark fails when more than 2 remarks are added
@Test
public void testAddRemark_MoreThanTwoRemarks() {
Prescription prescription = new Prescription();
prescription.prescID = prescriptionCounter; // make sure prescription ID is included
String remark1 = "This is the first valid remark.";
String remark2 = "This is the second valid remark.";
String remark3 = "This is the third valid remark.";
String category = "client";
boolean result1 = prescription.addRemark(remark1, category);
boolean result2 = prescription.addRemark(remark2, category);
boolean result3 = prescription.addRemark(remark3, category);
assertTrue(result1, "first valid remark should return true");
assertTrue(result2, "second valid remark should return true");
assertFalse(result3, "third remark should return false as maximum of 2 remarks allowed");
}
}