14
14
package org .openmrs ;
15
15
16
16
import java .util .Date ;
17
+ import java .util .UUID ;
17
18
18
19
import org .junit .Assert ;
19
20
import org .junit .Before ;
20
21
import org .junit .Test ;
22
+ import org .openmrs .test .Verifies ;
21
23
22
24
public class PatientStateTest {
23
25
@@ -31,6 +33,10 @@ public class PatientStateTest {
31
33
32
34
private Date leftOutOfRange ;
33
35
36
+ private String uuid2 ;
37
+
38
+ private String uuid1 ;
39
+
34
40
@ Before
35
41
public void before () {
36
42
inRange = new Date ();
@@ -259,4 +265,51 @@ public void compareTo_shouldReturnNegativeIfThisStartDateNull() throws Exception
259
265
Assert .assertTrue (result < 0 );
260
266
}
261
267
268
+ /**
269
+ * @see PatientState#compareTo(PatientState)
270
+ */
271
+ @ Test
272
+ @ Verifies (value = "pass if two states have the same start date, end date and uuid" , method = "compareTo(PatientState)" )
273
+ public void compareTo_shouldPassIfTwoStatesHaveTheSameStartDateEndDateAndUuid () throws Exception {
274
+
275
+ PatientState patientState = new PatientState ();
276
+ patientState .setStartDate (leftRange );
277
+ patientState .setEndDate (rightRange );
278
+ patientState .setUuid (uuid1 );
279
+ patientState .setVoided (false );
280
+
281
+ PatientState patientState2 = new PatientState ();
282
+ patientState2 .setStartDate (leftRange );
283
+ patientState2 .setEndDate (rightRange );
284
+ patientState2 .setUuid (uuid1 );
285
+ patientState2 .setVoided (false );
286
+
287
+ Assert .assertTrue (patientState .compareTo (patientState2 ) == 0 );
288
+ }
289
+
290
+ /**
291
+ * @see PatientState#compareTo(PatientState)
292
+ */
293
+ @ Test
294
+ @ Verifies (value = "return positive or negative if two states have the same start date and end date but different uuids" , method = "compareTo(PatientState)" )
295
+ public void compareTo_shouldReturnPositiveOrNegativeIfTwoStatesHaveTheSameStartDatesEndDatesAndUuids () throws Exception {
296
+ uuid1 = UUID .randomUUID ().toString ();
297
+ uuid2 = UUID .randomUUID ().toString ();
298
+
299
+ PatientState patientState = new PatientState ();
300
+ patientState .setStartDate (leftRange );
301
+ patientState .setEndDate (rightRange );
302
+ patientState .setUuid (uuid1 );
303
+ patientState .setVoided (false );
304
+
305
+ PatientState patientState2 = new PatientState ();
306
+ patientState2 .setStartDate (leftRange );
307
+ patientState2 .setEndDate (rightRange );
308
+ patientState2 .setUuid (uuid2 );
309
+ patientState2 .setVoided (false );
310
+
311
+ int result = (patientState .compareTo (patientState2 ));
312
+
313
+ Assert .assertTrue (result <= -1 || result >= 1 );
314
+ }
262
315
}
0 commit comments