Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/dev/openfeature/sdk/AbstractStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public boolean isEmpty() {
* @return immutable map
*/
public Map<String, Value> asUnmodifiableMap() {
if (attributes == null || attributes.isEmpty()) {
return Collections.emptyMap();
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return Collections.unmodifiableMap(attributes);
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/java/dev/openfeature/sdk/MutableStructureTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class MutableStructureTest {
Expand All @@ -21,6 +23,20 @@ void mutableStructureWithNullBackingStructureIsEmpty() {
assertTrue(m1.isEmpty());
}

@Test
void asUnmodifiableMapOnEmptyStructureIsEmpty() {
Map<String, Value> map = new MutableStructure().asUnmodifiableMap();
assertThat(map).isEmpty();
Assertions.assertThrows(UnsupportedOperationException.class, () -> map.put("key", new Value("val")));
}

@Test
void asUnmodifiableMapOnNullAttributesIsEmpty() {
Map<String, Value> map = new MutableStructure(null).asUnmodifiableMap();
assertThat(map).isEmpty();
Assertions.assertThrows(UnsupportedOperationException.class, () -> map.put("key", new Value("val")));
}

@Test
void unequalMutableStructuresAreNotEqual() {
MutableStructure m1 = new MutableStructure();
Expand Down
Loading