Skip to content

Commit 4dba143

Browse files
committed
fix: equals and hashcode of several classes
Signed-off-by: christian.lutnik <[email protected]>
1 parent 6be975b commit 4dba143

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/main/java/dev/openfeature/sdk/ImmutableStructure.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ private static Map<String, Value> copyAttributes(Map<String, Value> in) {
7070

7171
private static Map<String, Value> copyAttributes(Map<String, Value> in, String targetingKey) {
7272
Map<String, Value> copy = new HashMap<>();
73-
for (Entry<String, Value> entry : in.entrySet()) {
74-
copy.put(
75-
entry.getKey(),
76-
Optional.ofNullable(entry.getValue())
77-
.map((Value val) -> val.clone())
78-
.orElse(null));
73+
if (in != null) {
74+
for (Entry<String, Value> entry : in.entrySet()) {
75+
copy.put(
76+
entry.getKey(),
77+
Optional.ofNullable(entry.getValue())
78+
.map((Value val) -> val.clone())
79+
.orElse(null));
80+
}
7981
}
8082
if (targetingKey != null) {
8183
copy.put(EvaluationContext.TARGETING_KEY, new Value(targetingKey));

src/test/java/dev/openfeature/sdk/ImmutableStructureTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ void equalImmutableStructuresAreEqual() {
185185

186186
assertEquals(structure1, structure2);
187187
}
188+
189+
@Test
190+
void emptyImmutableStructureIsEmpty() {
191+
ImmutableStructure m1 = new ImmutableStructure();
192+
assertTrue(m1.isEmpty());
193+
}
194+
195+
@Test
196+
void immutableStructureWithNullAttributesIsEmpty() {
197+
ImmutableStructure m1 = new ImmutableStructure(null);
198+
assertTrue(m1.isEmpty());
199+
}
188200
}

src/test/java/dev/openfeature/sdk/MutableStructureTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package dev.openfeature.sdk;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
5-
63
import java.util.HashMap;
74
import java.util.Map;
85
import java.util.Set;
96
import org.junit.jupiter.api.Test;
107

8+
import static org.junit.jupiter.api.Assertions.*;
9+
1110
class MutableStructureTest {
1211

12+
@Test
13+
void emptyMutableStructureIsEmpty() {
14+
MutableStructure m1 = new MutableStructure();
15+
assertTrue(m1.isEmpty());
16+
}
17+
18+
@Test
19+
void mutableStructureWithNullBackingStructureIsEmpty() {
20+
MutableStructure m1 = new MutableStructure(null);
21+
assertTrue(m1.isEmpty());
22+
}
23+
1324
@Test
1425
void unequalMutableStructuresAreNotEqual() {
1526
MutableStructure m1 = new MutableStructure();

0 commit comments

Comments
 (0)