Skip to content

Commit 0226513

Browse files
add hook data spec test
Signed-off-by: Alexandra Oberaigner <alexandra.oberaigner@dynatrace.com>
1 parent 8b6aba9 commit 0226513

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Default implementation of HookData.
88
*/
9-
class DefaultHookData implements HookData {
9+
public class DefaultHookData implements HookData {
1010
private Map<String, Object> data;
1111

1212
@Override

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.junit.jupiter.api.Assertions.assertEquals;
77
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
88
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertNull;
910
import static org.junit.jupiter.api.Assertions.assertTrue;
1011
import static org.mockito.ArgumentMatchers.any;
1112
import static org.mockito.Mockito.doThrow;
@@ -801,4 +802,28 @@ void doesnt_use_finally() {
801802
Hook.class.getMethod("finallyAfter", HookContext.class, FlagEvaluationDetails.class, Map.class))
802803
.doesNotThrowAnyException();
803804
}
805+
806+
@Specification(
807+
number = "4.6.1",
808+
text = "hook data MUST be a structure supporting the definition of arbitrary "
809+
+ "properties, with keys of type string, and values of any type.")
810+
@Test
811+
void hook_data_structure() {
812+
// Arrange
813+
HookData hookData = new DefaultHookData();
814+
815+
// Act - Add arbitrary properties to hook data
816+
hookData.set("stringKey", "StringValue"); // String value
817+
hookData.set("intKey", 42); // Integer value
818+
hookData.set("doubleKey", 3.14); // Double value
819+
hookData.set("objectKey", new Object()); // Object value
820+
hookData.set("nullKey", null); // Null value
821+
822+
// Assert - Retrieve and validate the properties
823+
assertEquals("StringValue", hookData.get("stringKey"));
824+
assertEquals(42, hookData.get("intKey"));
825+
assertEquals(3.14, hookData.get("doubleKey"));
826+
assertNotNull(hookData.get("objectKey"));
827+
assertNull(hookData.get("nullKey"));
828+
}
804829
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ void shouldNotCallEvaluationMethodsWhenProviderIsInNotReadyState() {
111111
@ValueSource(booleans = {true, false})
112112
@DisplayName("Should support usage of HookData with/without error")
113113
void shouldSupportUsageOfHookData(boolean isError) {
114-
FeatureProvider provider = new TestEventsProvider(5000);
115114
OpenFeatureAPI api = new OpenFeatureAPI();
115+
FeatureProvider provider;
116116
if (isError) {
117-
api.setProvider("shouldSupportUsageOfHookData", provider);
117+
provider = new AlwaysBrokenWithExceptionProvider();
118118
} else {
119-
api.setProviderAndWait("shouldSupportUsageOfHookData", provider);
119+
provider = new TestEventsProvider(5000);
120120
}
121+
api.setProviderAndWait("shouldSupportUsageOfHookData", provider);
121122

122123
var testHook = new TestHookWithData("test-data");
123124
api.addHooks(testHook);

0 commit comments

Comments
 (0)