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 |
|
---|
7 | /**
|
---|
8 | * Unit test for the Community data class
|
---|
9 | *
|
---|
10 | * @author Neil Webb
|
---|
11 | */
|
---|
12 | public class CommunityTest
|
---|
13 | {
|
---|
14 | @Test
|
---|
15 | public void testGettersAndSetters()
|
---|
16 | {
|
---|
17 | System.out.println("Begin testGettersAndSetters");
|
---|
18 | try
|
---|
19 | {
|
---|
20 | String communityId = "CommunityId";
|
---|
21 | String communityName = "CommunityName";
|
---|
22 |
|
---|
23 | Community comm = new Community();
|
---|
24 |
|
---|
25 | // Set values using setters
|
---|
26 | comm.setCommunityId(communityId);
|
---|
27 | comm.setCommunityName(communityName);
|
---|
28 |
|
---|
29 | // Validate getters
|
---|
30 | assertEquals("Community id", communityId, comm.getCommunityId());
|
---|
31 | assertEquals("Community name", communityName, comm.getCommunityName());
|
---|
32 |
|
---|
33 | }
|
---|
34 | catch (Throwable t)
|
---|
35 | {
|
---|
36 | t.printStackTrace();
|
---|
37 | fail(t.getMessage());
|
---|
38 | }
|
---|
39 | System.out.println("End testGettersAndSetters");
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Test
|
---|
43 | public void testEquals()
|
---|
44 | {
|
---|
45 | System.out.println("Begin testEquals");
|
---|
46 | try
|
---|
47 | {
|
---|
48 | // Equals - both values populated
|
---|
49 | Community c1 = new Community();
|
---|
50 | c1.setCommunityId("CommunityId1");
|
---|
51 | c1.setCommunityName("CommunityName1");
|
---|
52 | Community c2 = new Community();
|
---|
53 | c2.setCommunityId("CommunityId1");
|
---|
54 | c2.setCommunityName("CommunityName1");
|
---|
55 | assertTrue("Equals - both values populated", c1.equals(c2));
|
---|
56 |
|
---|
57 | // Equals - only id
|
---|
58 | c1 = new Community();
|
---|
59 | c1.setCommunityId("CommunityId1");
|
---|
60 | c2 = new Community();
|
---|
61 | c2.setCommunityId("CommunityId1");
|
---|
62 | assertTrue("Equals - only id", c1.equals(c2));
|
---|
63 |
|
---|
64 | // Equals - only name
|
---|
65 | c1 = new Community();
|
---|
66 | c1.setCommunityName("CommunityName1");
|
---|
67 | c2 = new Community();
|
---|
68 | c2.setCommunityName("CommunityName1");
|
---|
69 | assertTrue("Equals - only name", c1.equals(c2));
|
---|
70 |
|
---|
71 | // Equals - all null
|
---|
72 | c1 = new Community();
|
---|
73 | c2 = new Community();
|
---|
74 | assertTrue("Equals - all null", c1.equals(c2));
|
---|
75 |
|
---|
76 |
|
---|
77 | // Not equals - Only first id
|
---|
78 | c1 = new Community();
|
---|
79 | c1.setCommunityId("CommunityId1");
|
---|
80 | c2 = new Community();
|
---|
81 | assertFalse("Not equals - Only first id", c1.equals(c2));
|
---|
82 |
|
---|
83 | // Not equals - Only second id
|
---|
84 | c1 = new Community();
|
---|
85 | c2 = new Community();
|
---|
86 | c2.setCommunityId("CommunityId2");
|
---|
87 | assertFalse("Not equals - Only second id", c1.equals(c2));
|
---|
88 |
|
---|
89 | // Not equals - Only first name
|
---|
90 | c1 = new Community();
|
---|
91 | c1.setCommunityName("CommunityName1");
|
---|
92 | c2 = new Community();
|
---|
93 | assertFalse("Not equals - Only first name", c1.equals(c2));
|
---|
94 |
|
---|
95 | // Not equals - Only second name
|
---|
96 | c1 = new Community();
|
---|
97 | c2 = new Community();
|
---|
98 | c2.setCommunityName("CommunityName2");
|
---|
99 | assertFalse("Not equals - Only second name", c1.equals(c2));
|
---|
100 |
|
---|
101 | // Not equals - Only first id and name
|
---|
102 | c1 = new Community();
|
---|
103 | c1.setCommunityId("CommunityId1");
|
---|
104 | c1.setCommunityName("CommunityName1");
|
---|
105 | c2 = new Community();
|
---|
106 | assertFalse("", c1.equals(c2));
|
---|
107 |
|
---|
108 | // Not equals - Only second id and name
|
---|
109 | c1 = new Community();
|
---|
110 | c2 = new Community();
|
---|
111 | c2.setCommunityId("CommunityId2");
|
---|
112 | c2.setCommunityName("CommunityName2");
|
---|
113 | assertFalse("Not equals - Only second id and name", c1.equals(c2));
|
---|
114 |
|
---|
115 | // Not equals - First id and name, only second id
|
---|
116 | c1 = new Community();
|
---|
117 | c1.setCommunityId("CommunityId1");
|
---|
118 | c1.setCommunityName("CommunityName1");
|
---|
119 | c2 = new Community();
|
---|
120 | c2.setCommunityId("CommunityId1");
|
---|
121 | assertFalse("Not equals - First id and name, only second id", c1.equals(c2));
|
---|
122 |
|
---|
123 | // Not equals - First id and name, only second name
|
---|
124 | c1 = new Community();
|
---|
125 | c1.setCommunityId("CommunityId1");
|
---|
126 | c1.setCommunityName("CommunityName1");
|
---|
127 | c2 = new Community();
|
---|
128 | c2.setCommunityName("CommunityName1");
|
---|
129 | assertFalse("Not equals - First id and name, only second name", c1.equals(c2));
|
---|
130 |
|
---|
131 | // Not equals - Second id and name, only first id
|
---|
132 | c1 = new Community();
|
---|
133 | c1.setCommunityId("CommunityId1");
|
---|
134 | c2 = new Community();
|
---|
135 | c2.setCommunityId("CommunityId1");
|
---|
136 | c2.setCommunityName("CommunityName1");
|
---|
137 | assertFalse("Not equals - Second id and name, only first id", c1.equals(c2));
|
---|
138 |
|
---|
139 | // Not equals - Second id and name, only first name
|
---|
140 | c1 = new Community();
|
---|
141 | c1.setCommunityName("CommunityName1");
|
---|
142 | c2 = new Community();
|
---|
143 | c2.setCommunityId("CommunityId1");
|
---|
144 | c2.setCommunityName("CommunityName1");
|
---|
145 | assertFalse("Not equals - Second id and name, only first name", c1.equals(c2));
|
---|
146 |
|
---|
147 | // Not equals - Only id, no match
|
---|
148 | c1 = new Community();
|
---|
149 | c1.setCommunityId("CommunityId1");
|
---|
150 | c2 = new Community();
|
---|
151 | c2.setCommunityId("CommunityId2");
|
---|
152 | assertFalse("Not equals - Only id, no match", c1.equals(c2));
|
---|
153 |
|
---|
154 | // Not equals - Only name, no match
|
---|
155 | c1 = new Community();
|
---|
156 | c1.setCommunityName("CommunityName1");
|
---|
157 | c2 = new Community();
|
---|
158 | c2.setCommunityName("CommunityName2");
|
---|
159 | assertFalse("Not equals - Only name, no match", c1.equals(c2));
|
---|
160 |
|
---|
161 | // Not equals - Both populated, both different
|
---|
162 | c1 = new Community();
|
---|
163 | c1.setCommunityId("CommunityId1");
|
---|
164 | c1.setCommunityName("CommunityName1");
|
---|
165 | c2 = new Community();
|
---|
166 | c2.setCommunityId("CommunityId2");
|
---|
167 | c2.setCommunityName("CommunityName2");
|
---|
168 | assertFalse("Not equals - Both populated, both different", c1.equals(c2));
|
---|
169 |
|
---|
170 | // Not equals - Both populated, id different
|
---|
171 | c1 = new Community();
|
---|
172 | c1.setCommunityId("CommunityId1");
|
---|
173 | c1.setCommunityName("CommunityName1");
|
---|
174 | c2 = new Community();
|
---|
175 | c2.setCommunityId("CommunityId2");
|
---|
176 | c2.setCommunityName("CommunityName1");
|
---|
177 | assertFalse("Not equals - Both populated, id different", c1.equals(c2));
|
---|
178 |
|
---|
179 | // Not equals - Both populated, name different
|
---|
180 | c1 = new Community();
|
---|
181 | c1.setCommunityId("CommunityId1");
|
---|
182 | c1.setCommunityName("CommunityName1");
|
---|
183 | c2 = new Community();
|
---|
184 | c2.setCommunityId("CommunityId1");
|
---|
185 | c2.setCommunityName("CommunityName2");
|
---|
186 | assertFalse("Not equals - Both populated, name different", c1.equals(c2));
|
---|
187 |
|
---|
188 | }
|
---|
189 | catch (Throwable t)
|
---|
190 | {
|
---|
191 | t.printStackTrace();
|
---|
192 | fail(t.getMessage());
|
---|
193 | }
|
---|
194 | System.out.println("End testEquals");
|
---|
195 | }
|
---|
196 | }
|
---|