1 | package gov.hhs.fha.nhinc.subscription.repository.data.test;
|
---|
2 |
|
---|
3 | import gov.hhs.fha.nhinc.subscription.repository.data.Criterion;
|
---|
4 | import org.junit.Test;
|
---|
5 | import static org.junit.Assert.*;
|
---|
6 | import gov.hhs.fha.nhinc.subscription.repository.data.Criterion;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Unit test for criterion class
|
---|
10 | *
|
---|
11 | * @author Neil Webb
|
---|
12 | */
|
---|
13 | public class CriterionTest
|
---|
14 | {
|
---|
15 | @Test
|
---|
16 | public void testGettersAndSetters()
|
---|
17 | {
|
---|
18 | System.out.println("Begin testGettersAndSetters");
|
---|
19 | try
|
---|
20 | {
|
---|
21 | String key = "CriterionKey";
|
---|
22 | String value = "CriterionValue";
|
---|
23 | Criterion crit = new Criterion();
|
---|
24 | crit.setKey(key);
|
---|
25 | crit.setValue(value);
|
---|
26 |
|
---|
27 | assertEquals("Key", key, crit.getKey());
|
---|
28 | assertEquals("Value", value, crit.getValue());
|
---|
29 | }
|
---|
30 | catch (Throwable t)
|
---|
31 | {
|
---|
32 | t.printStackTrace();
|
---|
33 | fail(t.getMessage());
|
---|
34 | }
|
---|
35 | System.out.println("End testGettersAndSetters");
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void testEquals()
|
---|
40 | {
|
---|
41 | System.out.println("Begin testEquals");
|
---|
42 | try
|
---|
43 | {
|
---|
44 | // Equals - both
|
---|
45 | Criterion crit1 = new Criterion();
|
---|
46 | crit1.setKey("Key1");
|
---|
47 | crit1.setValue("Value1");
|
---|
48 | Criterion crit2 = new Criterion();
|
---|
49 | crit2.setKey("Key1");
|
---|
50 | crit2.setValue("Value1");
|
---|
51 | assertTrue("Equals - both", crit1.equals(crit2));
|
---|
52 |
|
---|
53 | // Equals - only key
|
---|
54 | crit1 = new Criterion();
|
---|
55 | crit1.setKey("Key1");
|
---|
56 | crit2 = new Criterion();
|
---|
57 | crit2.setKey("Key1");
|
---|
58 | assertTrue("Equals - only key", crit1.equals(crit2));
|
---|
59 |
|
---|
60 | // Equals - only value
|
---|
61 | crit1 = new Criterion();
|
---|
62 | crit1.setValue("Value1");
|
---|
63 | crit2 = new Criterion();
|
---|
64 | crit2.setValue("Value1");
|
---|
65 | assertTrue("Equals - only value", crit1.equals(crit2));
|
---|
66 |
|
---|
67 | // Not equal - both populated, key different
|
---|
68 | crit1 = new Criterion();
|
---|
69 | crit1.setKey("Key1");
|
---|
70 | crit1.setValue("Value1");
|
---|
71 | crit2 = new Criterion();
|
---|
72 | crit2.setKey("Key2");
|
---|
73 | crit2.setValue("Value1");
|
---|
74 | assertFalse("Not equal - both populated, key different", crit1.equals(crit2));
|
---|
75 |
|
---|
76 | // Not equal - both populated, value different
|
---|
77 | crit1 = new Criterion();
|
---|
78 | crit1.setKey("Key1");
|
---|
79 | crit1.setValue("Value1");
|
---|
80 | crit2 = new Criterion();
|
---|
81 | crit2.setKey("Key1");
|
---|
82 | crit2.setValue("Value2");
|
---|
83 | assertFalse("Not equal - both populated, value different", crit1.equals(crit2));
|
---|
84 |
|
---|
85 | // Not equal - c1 full, c2 key only
|
---|
86 | crit1 = new Criterion();
|
---|
87 | crit1.setKey("Key1");
|
---|
88 | crit1.setValue("Value1");
|
---|
89 | crit2 = new Criterion();
|
---|
90 | crit2.setKey("Key1");
|
---|
91 | assertFalse("Not equal - c1 full, c2 key only", crit1.equals(crit2));
|
---|
92 |
|
---|
93 | // Not equal - c1 full, c2 value only
|
---|
94 | crit1 = new Criterion();
|
---|
95 | crit1.setKey("Key1");
|
---|
96 | crit1.setValue("Value1");
|
---|
97 | crit2 = new Criterion();
|
---|
98 | crit2.setValue("Value1");
|
---|
99 | assertFalse("Not equal - c1 full, c2 value only", crit1.equals(crit2));
|
---|
100 |
|
---|
101 | // Not equal - c2 full, c1 key only
|
---|
102 | crit1 = new Criterion();
|
---|
103 | crit1.setKey("Key1");
|
---|
104 | crit2 = new Criterion();
|
---|
105 | crit2.setKey("Key1");
|
---|
106 | crit2.setValue("Value1");
|
---|
107 | assertFalse("Not equal - c2 full, c1 key only", crit1.equals(crit2));
|
---|
108 |
|
---|
109 | // Not equal - c2 full, c1 value only
|
---|
110 | crit1 = new Criterion();
|
---|
111 | crit1.setValue("Value1");
|
---|
112 | crit2 = new Criterion();
|
---|
113 | crit2.setKey("Key1");
|
---|
114 | crit2.setValue("Value1");
|
---|
115 | assertFalse("Not equal - c2 full, c1 value only", crit1.equals(crit2));
|
---|
116 |
|
---|
117 | // Not equal - c1 full, c2 null
|
---|
118 | crit1 = new Criterion();
|
---|
119 | crit1.setKey("Key1");
|
---|
120 | crit1.setValue("Value1");
|
---|
121 | crit2 = null;
|
---|
122 | assertFalse("Not equal - c1 full, c2 null", crit1.equals(crit2));
|
---|
123 |
|
---|
124 | }
|
---|
125 | catch (Throwable t)
|
---|
126 | {
|
---|
127 | t.printStackTrace();
|
---|
128 | fail(t.getMessage());
|
---|
129 | }
|
---|
130 | System.out.println("Begin testEquals");
|
---|
131 | }
|
---|
132 | }
|
---|