|
1 | 1 | package dev.openfeature.sdk; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.*; |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertNotSame; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 9 |
|
5 | 10 | import java.time.Instant; |
6 | 11 | import java.time.temporal.ChronoUnit; |
@@ -154,4 +159,74 @@ void constructorHandlesNullValue() { |
154 | 159 | attrs.put("null", null); |
155 | 160 | new ImmutableStructure(attrs); |
156 | 161 | } |
| 162 | + |
| 163 | + @Test |
| 164 | + void unequalImmutableStructuresAreNotEqual() { |
| 165 | + Map<String, Value> attrs1 = new HashMap<>(); |
| 166 | + attrs1.put("test", new Value(45)); |
| 167 | + ImmutableStructure structure1 = new ImmutableStructure(attrs1); |
| 168 | + |
| 169 | + Map<String, Value> attrs2 = new HashMap<>(); |
| 170 | + attrs2.put("test", new Value(2)); |
| 171 | + ImmutableStructure structure2 = new ImmutableStructure(attrs2); |
| 172 | + |
| 173 | + assertNotEquals(structure1, structure2); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + void equalImmutableStructuresAreEqual() { |
| 178 | + Map<String, Value> attrs1 = new HashMap<>(); |
| 179 | + attrs1.put("test", new Value(45)); |
| 180 | + ImmutableStructure structure1 = new ImmutableStructure(attrs1); |
| 181 | + |
| 182 | + Map<String, Value> attrs2 = new HashMap<>(); |
| 183 | + attrs2.put("test", new Value(45)); |
| 184 | + ImmutableStructure structure2 = new ImmutableStructure(attrs2); |
| 185 | + |
| 186 | + assertEquals(structure1, structure2); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + void unequalMutableStructuresAreNotEqual() { |
| 191 | + MutableStructure m1 = new MutableStructure(); |
| 192 | + m1.add("key1", "val1"); |
| 193 | + MutableStructure m2 = new MutableStructure(); |
| 194 | + m2.add("key2", "val2"); |
| 195 | + assertNotEquals(m1, m2); |
| 196 | + } |
| 197 | + |
| 198 | + @Test |
| 199 | + void equalMutableStructuresAreEqual() { |
| 200 | + MutableStructure m1 = new MutableStructure(); |
| 201 | + m1.add("key1", "val1"); |
| 202 | + MutableStructure m2 = new MutableStructure(); |
| 203 | + m2.add("key1", "val1"); |
| 204 | + assertEquals(m1, m2); |
| 205 | + } |
| 206 | + |
| 207 | + @Test |
| 208 | + void equalAbstractStructuresOfDifferentTypesAreEqual() { |
| 209 | + MutableStructure m1 = new MutableStructure(); |
| 210 | + m1.add("key1", "val1"); |
| 211 | + HashMap<String, Value> map = new HashMap<>(); |
| 212 | + map.put("key1", new Value("val1")); |
| 213 | + AbstractStructure m2 = new AbstractStructure(map) { |
| 214 | + @Override |
| 215 | + public Set<String> keySet() { |
| 216 | + return attributes.keySet(); |
| 217 | + } |
| 218 | + |
| 219 | + @Override |
| 220 | + public Value getValue(String key) { |
| 221 | + return attributes.get(key); |
| 222 | + } |
| 223 | + |
| 224 | + @Override |
| 225 | + public Map<String, Value> asMap() { |
| 226 | + return attributes; |
| 227 | + } |
| 228 | + }; |
| 229 | + |
| 230 | + assertEquals(m1, m2); |
| 231 | + } |
157 | 232 | } |
0 commit comments