1
2
3
4 package de.powerstat.validation.values.test;
5
6
7 import static org.junit.jupiter.api.Assertions.assertAll;
8 import static org.junit.jupiter.api.Assertions.assertEquals;
9 import static org.junit.jupiter.api.Assertions.assertFalse;
10 import static org.junit.jupiter.api.Assertions.assertTrue;
11
12 import org.junit.jupiter.api.Test;
13
14 import de.powerstat.validation.values.BloodGroup;
15
16
17
18
19
20 final class BloodGroupTests
21 {
22
23
24
25 private static final String BG_ABPABP_OK = "AB+ with AB+ should be ok";
26
27
28
29
30 private static final String BG_ABNABP_OK = "AB- with AB+ should be ok";
31
32
33
34
35 private static final String BG_ABNABN_OK = "AB- with AB- should be ok";
36
37
38
39
40 private static final String BG_APAP_OK = "A+ with A+ should be ok";
41
42
43
44
45 private static final String BG_ANAN_OK = "A- with A- should be ok";
46
47
48
49
50 private static final String BG_BPBP_OK = "B+ with B+ should be ok";
51
52
53
54
55 private static final String BG_BNBN_OK = "B- with B- should be ok";
56
57
58
59
60 private static final String BG_0P0P_OK = "0+ with 0+ should be ok";
61
62
63
64
65 private static final String BG_0N0N_OK = "0- with 0- should be ok";
66
67
68
69
70 private static final String BG_ABNAP_NOT_OK = "AB- with A+ should not be ok";
71
72
73
74
75 private static final String BG_ABNBP_NOT_OK = "AB- with B+ should not be ok";
76
77
78
79
80 private static final String BG_ABN0P_NOT_OK = "AB- with 0+ should not be ok";
81
82
83
84
85 private static final String BG_APABN_NOT_OK = "A+ with AB- should not be ok";
86
87
88
89
90 private static final String BG_APBP_NOT_OK = "A+ with B+ should not be ok";
91
92
93
94
95 private static final String BG_APBN_NOT_OK = "A+ with B- should not be ok";
96
97
98
99
100 private static final String BG_ANBP_NOT_OK = "A- with B+ should not be ok";
101
102
103
104
105 private static final String BG_ANBN_NOT_OK = "A- with B- should not be ok";
106
107
108
109
110 private static final String BG_AN0P_NOT_OK = "A- with 0+ should not be ok";
111
112
113
114
115 private static final String BG_BPABN_NOT_OK = "B+ with AB- should not be ok";
116
117
118
119
120 private static final String BG_BPAP_NOT_OK = "B+ with A+ should not be ok";
121
122
123
124
125 private static final String BG_BPAN_NOT_OK = "B+ with A- should not be ok";
126
127
128
129
130 private static final String BG_BNAP_NOT_OK = "B- with A+ should not be ok";
131
132
133
134
135 private static final String BG_BNAN_NOT_OK = "B- with A- should not be ok";
136
137
138
139
140 private static final String BG_BN0P_NOT_OK = "B- with 0+ should not be ok";
141
142
143
144
145 private static final String BG_0PABN_NOT_OK = "0+ with AB- should not be ok";
146
147
148
149
150 private static final String BG_0PAN_NOT_OK = "0+ with A- should not be ok";
151
152
153
154
155 private static final String BG_0PBN_NOT_OK = "0+ with B- should not be ok";
156
157
158
159
160 private static final String ON = "ON";
161
162
163
164
165 private static final String ZERO_NEGATIVE_ACTION_NOT_AS_EXPECTED = "0- action not as expected";
166
167
168
169
170
171 BloodGroupTests()
172 {
173 super();
174 }
175
176
177
178
179
180 @Test
181 void testFactory1()
182 {
183 assertEquals(0, BloodGroup.of(ON).getAction(), ZERO_NEGATIVE_ACTION_NOT_AS_EXPECTED);
184 }
185
186
187
188
189
190 @Test
191 void testGetAction()
192 {
193 assertAll("getAction",
194 () -> assertEquals(0, BloodGroup.ON.getAction(), ZERO_NEGATIVE_ACTION_NOT_AS_EXPECTED),
195 () -> assertEquals(1, BloodGroup.OP.getAction(), "0+ action not as expected"),
196 () -> assertEquals(2, BloodGroup.AN.getAction(), "A- action not as expected"),
197 () -> assertEquals(3, BloodGroup.AP.getAction(), "A+ action not as expected"),
198 () -> assertEquals(4, BloodGroup.BN.getAction(), "B- action not as expected"),
199 () -> assertEquals(5, BloodGroup.BP.getAction(), "B+ action not as expected"),
200 () -> assertEquals(6, BloodGroup.ABN.getAction(), "AB- action not as expected"),
201 () -> assertEquals(7, BloodGroup.ABP.getAction(), "AB+ action not as expected")
202 );
203 }
204
205
206
207
208
209 @Test
210 void testStringValue()
211 {
212 final BloodGroup group = BloodGroup.ON;
213 assertEquals(ON, group.stringValue(), "stringValue not as expected");
214 }
215
216
217
218
219
220 @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
221 @Test
222 void testCouldDonateTo()
223 {
224 assertAll("couldDonateTo",
225 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.ON), BloodGroupTests.BG_0N0N_OK),
226 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.OP), "0- with 0+ should be ok"),
227 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.BN), "0- with B- should be ok"),
228 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.BP), "0- with B+ should be ok"),
229 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.AN), "0- with A- should be ok"),
230 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.AP), "0- with A+ should be ok"),
231 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.ABN), "0- with AB- should be ok"),
232 () -> assertTrue(BloodGroup.ON.couldDonateTo(BloodGroup.ABP), "0- with AB+ should be ok"),
233
234 () -> assertFalse(BloodGroup.OP.couldDonateTo(BloodGroup.ON), "0+ with 0- should not be ok"),
235 () -> assertTrue(BloodGroup.OP.couldDonateTo(BloodGroup.OP), BloodGroupTests.BG_0P0P_OK),
236 () -> assertFalse(BloodGroup.OP.couldDonateTo(BloodGroup.BN), BloodGroupTests.BG_0PBN_NOT_OK),
237 () -> assertTrue(BloodGroup.OP.couldDonateTo(BloodGroup.BP), "0+ with B+ should be ok"),
238 () -> assertFalse(BloodGroup.OP.couldDonateTo(BloodGroup.AN), BloodGroupTests.BG_0PAN_NOT_OK),
239 () -> assertTrue(BloodGroup.OP.couldDonateTo(BloodGroup.AP), "0+ with A+ should be ok"),
240 () -> assertFalse(BloodGroup.OP.couldDonateTo(BloodGroup.ABN), BloodGroupTests.BG_0PABN_NOT_OK),
241 () -> assertTrue(BloodGroup.OP.couldDonateTo(BloodGroup.ABP), "0+ with AB+ should be ok"),
242
243 () -> assertFalse(BloodGroup.BN.couldDonateTo(BloodGroup.ON), "B- with 0- should not be ok"),
244 () -> assertFalse(BloodGroup.BN.couldDonateTo(BloodGroup.OP), BloodGroupTests.BG_BN0P_NOT_OK),
245 () -> assertTrue(BloodGroup.BN.couldDonateTo(BloodGroup.BN), BloodGroupTests.BG_BNBN_OK),
246 () -> assertTrue(BloodGroup.BN.couldDonateTo(BloodGroup.BP), "B- with B+ should be ok"),
247 () -> assertFalse(BloodGroup.BN.couldDonateTo(BloodGroup.AN), BloodGroupTests.BG_BNAN_NOT_OK),
248 () -> assertFalse(BloodGroup.BN.couldDonateTo(BloodGroup.AP), BloodGroupTests.BG_BNAP_NOT_OK),
249 () -> assertTrue(BloodGroup.BN.couldDonateTo(BloodGroup.ABN), "B- with AB- should be ok"),
250 () -> assertTrue(BloodGroup.BN.couldDonateTo(BloodGroup.ABP), "B- with AB+ should be ok"),
251
252 () -> assertFalse(BloodGroup.BP.couldDonateTo(BloodGroup.ON), "B+ with 0- should not be ok"),
253 () -> assertFalse(BloodGroup.BP.couldDonateTo(BloodGroup.OP), "B+ with 0+ should not be ok"),
254 () -> assertFalse(BloodGroup.BP.couldDonateTo(BloodGroup.BN), "B+ with B- should not be ok"),
255 () -> assertTrue(BloodGroup.BP.couldDonateTo(BloodGroup.BP), BloodGroupTests.BG_BPBP_OK),
256 () -> assertFalse(BloodGroup.BP.couldDonateTo(BloodGroup.AN), BloodGroupTests.BG_BPAN_NOT_OK),
257 () -> assertFalse(BloodGroup.BP.couldDonateTo(BloodGroup.AP), BloodGroupTests.BG_BPAP_NOT_OK),
258 () -> assertFalse(BloodGroup.BP.couldDonateTo(BloodGroup.ABN), BloodGroupTests.BG_BPABN_NOT_OK),
259 () -> assertTrue(BloodGroup.BP.couldDonateTo(BloodGroup.ABP), "B+ with AB+ should be ok"),
260
261 () -> assertFalse(BloodGroup.AN.couldDonateTo(BloodGroup.ON), "A- with 0- should not be ok"),
262 () -> assertFalse(BloodGroup.AN.couldDonateTo(BloodGroup.OP), BloodGroupTests.BG_AN0P_NOT_OK),
263 () -> assertFalse(BloodGroup.AN.couldDonateTo(BloodGroup.BN), BloodGroupTests.BG_ANBN_NOT_OK),
264 () -> assertFalse(BloodGroup.AN.couldDonateTo(BloodGroup.BP), BloodGroupTests.BG_ANBP_NOT_OK),
265 () -> assertTrue(BloodGroup.AN.couldDonateTo(BloodGroup.AN), BloodGroupTests.BG_ANAN_OK),
266 () -> assertTrue(BloodGroup.AN.couldDonateTo(BloodGroup.AP), "A- with A+ should be ok"),
267 () -> assertTrue(BloodGroup.AN.couldDonateTo(BloodGroup.ABN), "A- with AB- should be ok"),
268 () -> assertTrue(BloodGroup.AN.couldDonateTo(BloodGroup.ABP), "A- with AB+ should be ok"),
269
270 () -> assertFalse(BloodGroup.AP.couldDonateTo(BloodGroup.ON), "A+ with 0- should not be ok"),
271 () -> assertFalse(BloodGroup.AP.couldDonateTo(BloodGroup.OP), "A+ with 0+ should not be ok"),
272 () -> assertFalse(BloodGroup.AP.couldDonateTo(BloodGroup.BN), BloodGroupTests.BG_APBN_NOT_OK),
273 () -> assertFalse(BloodGroup.AP.couldDonateTo(BloodGroup.BP), BloodGroupTests.BG_APBP_NOT_OK),
274 () -> assertFalse(BloodGroup.AP.couldDonateTo(BloodGroup.AN), "A+ with A- should not be ok"),
275 () -> assertTrue(BloodGroup.AP.couldDonateTo(BloodGroup.AP), BloodGroupTests.BG_APAP_OK),
276 () -> assertFalse(BloodGroup.AP.couldDonateTo(BloodGroup.ABN), BloodGroupTests.BG_APABN_NOT_OK),
277 () -> assertTrue(BloodGroup.AP.couldDonateTo(BloodGroup.ABP), "A+ with AB+ should be ok"),
278
279 () -> assertFalse(BloodGroup.ABN.couldDonateTo(BloodGroup.ON), "AB- with 0- should not be ok"),
280 () -> assertFalse(BloodGroup.ABN.couldDonateTo(BloodGroup.OP), BloodGroupTests.BG_ABN0P_NOT_OK),
281 () -> assertFalse(BloodGroup.ABN.couldDonateTo(BloodGroup.BN), "AB- with B- should not be ok"),
282 () -> assertFalse(BloodGroup.ABN.couldDonateTo(BloodGroup.BP), BloodGroupTests.BG_ABNBP_NOT_OK),
283 () -> assertFalse(BloodGroup.ABN.couldDonateTo(BloodGroup.AN), "AB- with A- should not be ok"),
284 () -> assertFalse(BloodGroup.ABN.couldDonateTo(BloodGroup.AP), BloodGroupTests.BG_ABNAP_NOT_OK),
285 () -> assertTrue(BloodGroup.ABN.couldDonateTo(BloodGroup.ABN), BloodGroupTests.BG_ABNABN_OK),
286 () -> assertTrue(BloodGroup.ABN.couldDonateTo(BloodGroup.ABP), BloodGroupTests.BG_ABNABP_OK),
287
288 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.ON), "AB+ with 0- should not be ok"),
289 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.OP), "AB+ with 0+ should not be ok"),
290 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.BN), "AB+ with B- should not be ok"),
291 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.BP), "AB+ with B+ should not be ok"),
292 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.AN), "AB+ with A- should not be ok"),
293 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.AP), "AB+ with A+ should not be ok"),
294 () -> assertFalse(BloodGroup.ABP.couldDonateTo(BloodGroup.ABN), "AB+ with AB- should not be ok"),
295 () -> assertTrue(BloodGroup.ABP.couldDonateTo(BloodGroup.ABP), BloodGroupTests.BG_ABPABP_OK)
296 );
297 }
298
299
300
301
302
303 @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
304 @Test
305 void testCouldReceiveFrom()
306 {
307 assertAll("couldReceiveFrom",
308 () -> assertTrue(BloodGroup.ON.couldReceiveFrom(BloodGroup.ON), BloodGroupTests.BG_0N0N_OK),
309 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.OP), "0- with 0+ should not be ok"),
310 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.BN), "0- with B- should not be ok"),
311 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.BP), "0- with B+ should not be ok"),
312 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.AN), "0- with A- should not be ok"),
313 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.AP), "0- with A+ should not be ok"),
314 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.ABN), "0- with AB- should not be ok"),
315 () -> assertFalse(BloodGroup.ON.couldReceiveFrom(BloodGroup.ABP), "0- with AB+ should not be ok"),
316
317 () -> assertTrue(BloodGroup.OP.couldReceiveFrom(BloodGroup.ON), "0+ with 0- should be ok"),
318 () -> assertTrue(BloodGroup.OP.couldReceiveFrom(BloodGroup.OP), BloodGroupTests.BG_0P0P_OK),
319 () -> assertFalse(BloodGroup.OP.couldReceiveFrom(BloodGroup.BN), BloodGroupTests.BG_0PBN_NOT_OK),
320 () -> assertFalse(BloodGroup.OP.couldReceiveFrom(BloodGroup.BP), "0+ with B+ should not be ok"),
321 () -> assertFalse(BloodGroup.OP.couldReceiveFrom(BloodGroup.AN), BloodGroupTests.BG_0PAN_NOT_OK),
322 () -> assertFalse(BloodGroup.OP.couldReceiveFrom(BloodGroup.AP), "0+ with A+ should not be ok"),
323 () -> assertFalse(BloodGroup.OP.couldReceiveFrom(BloodGroup.ABN), BloodGroupTests.BG_0PABN_NOT_OK),
324 () -> assertFalse(BloodGroup.OP.couldReceiveFrom(BloodGroup.ABP), "0+ with AB+ should not be ok"),
325
326 () -> assertTrue(BloodGroup.BN.couldReceiveFrom(BloodGroup.ON), "B- with 0- should be ok"),
327 () -> assertFalse(BloodGroup.BN.couldReceiveFrom(BloodGroup.OP), BloodGroupTests.BG_BN0P_NOT_OK),
328 () -> assertTrue(BloodGroup.BN.couldReceiveFrom(BloodGroup.BN), BloodGroupTests.BG_BNBN_OK),
329 () -> assertFalse(BloodGroup.BN.couldReceiveFrom(BloodGroup.BP), "B- with B+ should not be ok"),
330 () -> assertFalse(BloodGroup.BN.couldReceiveFrom(BloodGroup.AN), BloodGroupTests.BG_BNAN_NOT_OK),
331 () -> assertFalse(BloodGroup.BN.couldReceiveFrom(BloodGroup.AP), BloodGroupTests.BG_BNAP_NOT_OK),
332 () -> assertFalse(BloodGroup.BN.couldReceiveFrom(BloodGroup.ABN), "B- with AB- should not be ok"),
333 () -> assertFalse(BloodGroup.BN.couldReceiveFrom(BloodGroup.ABP), "B- with AB+ should not be ok"),
334
335 () -> assertTrue(BloodGroup.BP.couldReceiveFrom(BloodGroup.ON), "B+ with 0- should be ok"),
336 () -> assertTrue(BloodGroup.BP.couldReceiveFrom(BloodGroup.OP), "B+ with 0+ should be ok"),
337 () -> assertTrue(BloodGroup.BP.couldReceiveFrom(BloodGroup.BN), "B+ with B- should be ok"),
338 () -> assertTrue(BloodGroup.BP.couldReceiveFrom(BloodGroup.BP), BloodGroupTests.BG_BPBP_OK),
339 () -> assertFalse(BloodGroup.BP.couldReceiveFrom(BloodGroup.AN), BloodGroupTests.BG_BPAN_NOT_OK),
340 () -> assertFalse(BloodGroup.BP.couldReceiveFrom(BloodGroup.AP), BloodGroupTests.BG_BPAP_NOT_OK),
341 () -> assertFalse(BloodGroup.BP.couldReceiveFrom(BloodGroup.ABN), BloodGroupTests.BG_BPABN_NOT_OK),
342 () -> assertFalse(BloodGroup.BP.couldReceiveFrom(BloodGroup.ABP), "B+ with AB+ should not be ok"),
343
344 () -> assertTrue(BloodGroup.AN.couldReceiveFrom(BloodGroup.ON), "A- with 0- should be ok"),
345 () -> assertFalse(BloodGroup.AN.couldReceiveFrom(BloodGroup.OP), BloodGroupTests.BG_AN0P_NOT_OK),
346 () -> assertFalse(BloodGroup.AN.couldReceiveFrom(BloodGroup.BN), BloodGroupTests.BG_ANBN_NOT_OK),
347 () -> assertFalse(BloodGroup.AN.couldReceiveFrom(BloodGroup.BP), BloodGroupTests.BG_ANBP_NOT_OK),
348 () -> assertTrue(BloodGroup.AN.couldReceiveFrom(BloodGroup.AN), BloodGroupTests.BG_ANAN_OK),
349 () -> assertFalse(BloodGroup.AN.couldReceiveFrom(BloodGroup.AP), "A- with A+ should not be ok"),
350 () -> assertFalse(BloodGroup.AN.couldReceiveFrom(BloodGroup.ABN), "A- with AB- should not be ok"),
351 () -> assertFalse(BloodGroup.AN.couldReceiveFrom(BloodGroup.ABP), "A- with AB+ should not be ok"),
352
353 () -> assertTrue(BloodGroup.AP.couldReceiveFrom(BloodGroup.ON), "A+ with 0- should be ok"),
354 () -> assertTrue(BloodGroup.AP.couldReceiveFrom(BloodGroup.OP), "A+ with 0+ should be ok"),
355 () -> assertFalse(BloodGroup.AP.couldReceiveFrom(BloodGroup.BN), BloodGroupTests.BG_APBN_NOT_OK),
356 () -> assertFalse(BloodGroup.AP.couldReceiveFrom(BloodGroup.BP), BloodGroupTests.BG_APBP_NOT_OK),
357 () -> assertTrue(BloodGroup.AP.couldReceiveFrom(BloodGroup.AN), "A+ with A- should be ok"),
358 () -> assertTrue(BloodGroup.AP.couldReceiveFrom(BloodGroup.AP), BloodGroupTests.BG_APAP_OK),
359 () -> assertFalse(BloodGroup.AP.couldReceiveFrom(BloodGroup.ABN), BloodGroupTests.BG_APABN_NOT_OK),
360 () -> assertFalse(BloodGroup.AP.couldReceiveFrom(BloodGroup.ABP), "A+ with AB+ should not be ok"),
361
362 () -> assertTrue(BloodGroup.ABN.couldReceiveFrom(BloodGroup.ON), "AB- with 0- should be ok"),
363 () -> assertFalse(BloodGroup.ABN.couldReceiveFrom(BloodGroup.OP), BloodGroupTests.BG_ABN0P_NOT_OK),
364 () -> assertTrue(BloodGroup.ABN.couldReceiveFrom(BloodGroup.BN), "AB- with B- should be ok"),
365 () -> assertFalse(BloodGroup.ABN.couldReceiveFrom(BloodGroup.BP), BloodGroupTests.BG_ABNBP_NOT_OK),
366 () -> assertTrue(BloodGroup.ABN.couldReceiveFrom(BloodGroup.AN), "AB- with A- should be ok"),
367 () -> assertFalse(BloodGroup.ABN.couldReceiveFrom(BloodGroup.AP), BloodGroupTests.BG_ABNAP_NOT_OK),
368 () -> assertTrue(BloodGroup.ABN.couldReceiveFrom(BloodGroup.ABN), BloodGroupTests.BG_ABNABN_OK),
369 () -> assertFalse(BloodGroup.ABN.couldReceiveFrom(BloodGroup.ABP), "AB- with AB+ should not be ok"),
370
371 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.ON), "AB+ with 0- should be ok"),
372 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.OP), "AB+ with 0+ should be ok"),
373 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.BN), "AB+ with B- should be ok"),
374 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.BP), "AB+ with B+ should be ok"),
375 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.AN), "AB+ with A- should be ok"),
376 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.AP), "AB+ with A+ should be ok"),
377 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.ABN), "AB+ with AB- should be ok"),
378 () -> assertTrue(BloodGroup.ABP.couldReceiveFrom(BloodGroup.ABP), BloodGroupTests.BG_ABPABP_OK)
379 );
380 }
381
382 }