1 | package gov.hhs.fha.nhinc.subscription.repository.data.test;
|
---|
2 |
|
---|
3 | import org.junit.Test;
|
---|
4 | import static org.junit.Assert.*;
|
---|
5 | import gov.hhs.fha.nhinc.subscription.repository.data.Community;
|
---|
6 | import gov.hhs.fha.nhinc.subscription.repository.data.Patient;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Unit test for the patient class
|
---|
10 | *
|
---|
11 | * @author Neil Webb
|
---|
12 | */
|
---|
13 | public class PatientTest
|
---|
14 | {
|
---|
15 | @Test
|
---|
16 | public void testGettersAndSetters()
|
---|
17 | {
|
---|
18 | System.out.println("Begin testGettersAndSetters");
|
---|
19 | try
|
---|
20 | {
|
---|
21 | String patientId = "PatientId";
|
---|
22 | String communityId = "CommunityId";
|
---|
23 | String communityName = "CommunityName";
|
---|
24 |
|
---|
25 | // Set values using setters
|
---|
26 | Community comm = new Community();
|
---|
27 | comm.setCommunityId(communityId);
|
---|
28 | comm.setCommunityName(communityName);
|
---|
29 | Patient pat = new Patient();
|
---|
30 | pat.setPatientId(patientId);
|
---|
31 | pat.setAssigningAuthority(comm);
|
---|
32 |
|
---|
33 | // Validate getters
|
---|
34 | assertEquals("Patient id", patientId, pat.getPatientId());
|
---|
35 | assertNotNull("Assigning authority null", pat.getAssigningAuthority());
|
---|
36 | assertEquals("Community id", communityId, pat.getAssigningAuthority().getCommunityId());
|
---|
37 | assertEquals("Community name", communityName, pat.getAssigningAuthority().getCommunityName());
|
---|
38 |
|
---|
39 | }
|
---|
40 | catch (Throwable t)
|
---|
41 | {
|
---|
42 | t.printStackTrace();
|
---|
43 | fail(t.getMessage());
|
---|
44 | }
|
---|
45 | System.out.println("End testGettersAndSetters");
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Test
|
---|
49 | public void testEquals()
|
---|
50 | {
|
---|
51 | System.out.println("Begin testEquals");
|
---|
52 | try
|
---|
53 | {
|
---|
54 | // Equals - patient id and community
|
---|
55 | Community comm = new Community();
|
---|
56 | comm.setCommunityId("CommunityId");
|
---|
57 | comm.setCommunityName("CommunityName");
|
---|
58 | Patient pat1 = new Patient();
|
---|
59 | pat1.setPatientId("PatientId");
|
---|
60 | pat1.setAssigningAuthority(comm);
|
---|
61 | comm = new Community();
|
---|
62 | comm.setCommunityId("CommunityId");
|
---|
63 | comm.setCommunityName("CommunityName");
|
---|
64 | Patient pat2 = new Patient();
|
---|
65 | pat2.setPatientId("PatientId");
|
---|
66 | pat2.setAssigningAuthority(comm);
|
---|
67 | assertTrue("Equals - patient id and community", pat1.equals(pat2));
|
---|
68 |
|
---|
69 | // Equals - patient id only
|
---|
70 | pat1 = new Patient();
|
---|
71 | pat1.setPatientId("PatientId");
|
---|
72 | pat2 = new Patient();
|
---|
73 | pat2.setPatientId("PatientId");
|
---|
74 | assertTrue("Equals - patient id only", pat1.equals(pat2));
|
---|
75 |
|
---|
76 | // Not equal - both created, patient id different
|
---|
77 | comm = new Community();
|
---|
78 | comm.setCommunityId("CommunityId");
|
---|
79 | comm.setCommunityName("CommunityName");
|
---|
80 | pat1 = new Patient();
|
---|
81 | pat1.setPatientId("PatientId");
|
---|
82 | pat1.setAssigningAuthority(comm);
|
---|
83 | comm = new Community();
|
---|
84 | comm.setCommunityId("CommunityId");
|
---|
85 | comm.setCommunityName("CommunityName");
|
---|
86 | pat2 = new Patient();
|
---|
87 | pat2.setPatientId("PatientId2");
|
---|
88 | pat2.setAssigningAuthority(comm);
|
---|
89 | assertFalse("Not equal - both created, patient id different", pat1.equals(pat2));
|
---|
90 |
|
---|
91 | // Not equal - both created, community id different
|
---|
92 | comm = new Community();
|
---|
93 | comm.setCommunityId("CommunityId");
|
---|
94 | comm.setCommunityName("CommunityName");
|
---|
95 | pat1 = new Patient();
|
---|
96 | pat1.setPatientId("PatientId");
|
---|
97 | pat1.setAssigningAuthority(comm);
|
---|
98 | comm = new Community();
|
---|
99 | comm.setCommunityId("CommunityId2");
|
---|
100 | comm.setCommunityName("CommunityName");
|
---|
101 | pat2 = new Patient();
|
---|
102 | pat2.setPatientId("PatientId");
|
---|
103 | pat2.setAssigningAuthority(comm);
|
---|
104 | assertFalse("Not equal - both created, community id different", pat1.equals(pat2));
|
---|
105 |
|
---|
106 | // Not equal - patient 1 full, patient 2 null
|
---|
107 | comm = new Community();
|
---|
108 | comm.setCommunityId("CommunityId");
|
---|
109 | comm.setCommunityName("CommunityName");
|
---|
110 | pat1 = new Patient();
|
---|
111 | pat1.setPatientId("PatientId");
|
---|
112 | pat1.setAssigningAuthority(comm);
|
---|
113 | pat2 = null;
|
---|
114 | assertFalse("Not equal - patient 1 full, patient 2 null", pat1.equals(pat2));
|
---|
115 |
|
---|
116 | // Not equal - patient 1 full, only patient id on second
|
---|
117 | comm = new Community();
|
---|
118 | comm.setCommunityId("CommunityId");
|
---|
119 | comm.setCommunityName("CommunityName");
|
---|
120 | pat1 = new Patient();
|
---|
121 | pat1.setPatientId("PatientId");
|
---|
122 | pat1.setAssigningAuthority(comm);
|
---|
123 | pat2 = new Patient();
|
---|
124 | pat2.setPatientId("PatientId");
|
---|
125 | assertFalse("Not equal - patient 1 full, only patient id on second", pat1.equals(pat2));
|
---|
126 |
|
---|
127 | // Not equal - patient 1 full, only community on second
|
---|
128 | comm = new Community();
|
---|
129 | comm.setCommunityId("CommunityId");
|
---|
130 | comm.setCommunityName("CommunityName");
|
---|
131 | pat1 = new Patient();
|
---|
132 | pat1.setPatientId("PatientId");
|
---|
133 | pat1.setAssigningAuthority(comm);
|
---|
134 | comm = new Community();
|
---|
135 | comm.setCommunityId("CommunityId1");
|
---|
136 | comm.setCommunityName("CommunityName");
|
---|
137 | pat2 = new Patient();
|
---|
138 | pat2.setAssigningAuthority(comm);
|
---|
139 | assertFalse("Not equal - patient 1 full, only community on second", pat1.equals(pat2));
|
---|
140 |
|
---|
141 | // Not equal - patient 2 full, only patient id on first
|
---|
142 | pat1 = new Patient();
|
---|
143 | pat1.setPatientId("PatientId");
|
---|
144 | comm = new Community();
|
---|
145 | comm.setCommunityId("CommunityId");
|
---|
146 | comm.setCommunityName("CommunityName");
|
---|
147 | pat2 = new Patient();
|
---|
148 | pat2.setPatientId("PatientId");
|
---|
149 | pat2.setAssigningAuthority(comm);
|
---|
150 | assertFalse("Not equal - patient 2 full, only patient id on first", pat1.equals(pat2));
|
---|
151 |
|
---|
152 | // Not equal - patient 2 full, only community on first
|
---|
153 | comm = new Community();
|
---|
154 | comm.setCommunityId("CommunityId");
|
---|
155 | comm.setCommunityName("CommunityName");
|
---|
156 | pat1 = new Patient();
|
---|
157 | pat1.setAssigningAuthority(comm);
|
---|
158 | comm = new Community();
|
---|
159 | comm.setCommunityId("CommunityId");
|
---|
160 | comm.setCommunityName("CommunityName");
|
---|
161 | pat2 = new Patient();
|
---|
162 | pat2.setPatientId("PatientId");
|
---|
163 | pat2.setAssigningAuthority(comm);
|
---|
164 | assertFalse("Not equal - patient 2 full, only community on first", pat1.equals(pat2));
|
---|
165 |
|
---|
166 | }
|
---|
167 | catch (Throwable t)
|
---|
168 | {
|
---|
169 | t.printStackTrace();
|
---|
170 | fail(t.getMessage());
|
---|
171 | }
|
---|
172 | System.out.println("End testEquals");
|
---|
173 | }
|
---|
174 | }
|
---|