Skip to content
Merged
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
31 changes: 31 additions & 0 deletions src/test/java/dev/openfeature/sdk/BooleanHookTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;

import dev.openfeature.sdk.fixtures.HookFixtures;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class BooleanHookTest implements HookFixtures {

private Hook<Boolean> hook;

@BeforeEach
void setupTest() {
hook = mockBooleanHook();
}

@Test
void verifyFlagValueTypeIsSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.BOOLEAN);

assertThat(hookSupported).isTrue();
}

@Test
void verifyFlagValueTypeIsNotSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);

assertThat(hookSupported).isFalse();
}
}
31 changes: 31 additions & 0 deletions src/test/java/dev/openfeature/sdk/DoubleHookTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;

import dev.openfeature.sdk.fixtures.HookFixtures;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class DoubleHookTest implements HookFixtures {

private Hook<Double> hook;

@BeforeEach
void setupTest() {
hook = mockDoubleHook();
}

@Test
void verifyFlagValueTypeIsSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.DOUBLE);

assertThat(hookSupported).isTrue();
}

@Test
void verifyFlagValueTypeIsNotSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.STRING);

assertThat(hookSupported).isFalse();
}
}
13 changes: 13 additions & 0 deletions src/test/java/dev/openfeature/sdk/ImmutableContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ void mergeShouldRetainItsSubkeysWhenOverridingContextHasNoTargetingKey() {
assertArrayEquals(new Object[] {"key1_1"}, value.keySet().toArray());
}

@DisplayName("Merge should obtain keys from the overriding context when the existing context is empty")
@Test
void mergeShouldObtainKeysFromOverridingContextWhenExistingContextIsEmpty() {
HashMap<String, Value> attributes = new HashMap<>();
attributes.put("key1", new Value("val1"));
attributes.put("key2", new Value("val2"));

EvaluationContext ctx = new ImmutableContext();
EvaluationContext overriding = new ImmutableContext(attributes);
EvaluationContext merge = ctx.merge(overriding);
assertEquals(new java.util.HashSet<>(java.util.Arrays.asList("key1", "key2")), merge.keySet());
}

@DisplayName("Two different MutableContext objects with the different contents are not considered equal")
@Test
void unequalImmutableContextsAreNotEqual() {
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/dev/openfeature/sdk/IntegerHookTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;

import dev.openfeature.sdk.fixtures.HookFixtures;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class IntegerHookTest implements HookFixtures {

private Hook<Integer> hook;

@BeforeEach
void setupTest() {
hook = mockIntegerHook();
}

@Test
void verifyFlagValueTypeIsSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);

assertThat(hookSupported).isTrue();
}

@Test
void verifyFlagValueTypeIsNotSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.STRING);

assertThat(hookSupported).isFalse();
}
}
31 changes: 31 additions & 0 deletions src/test/java/dev/openfeature/sdk/ObjectHookTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;

import dev.openfeature.sdk.fixtures.HookFixtures;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class ObjectHookTest implements HookFixtures {

private Hook<Object> hook;

@BeforeEach
void setupTest() {
hook = mockObjectHook();
}

@Test
void verifyFlagValueTypeIsSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.OBJECT);

assertThat(hookSupported).isTrue();
}

@Test
void verifyFlagValueTypeIsNotSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);

assertThat(hookSupported).isFalse();
}
}
31 changes: 31 additions & 0 deletions src/test/java/dev/openfeature/sdk/StringHookTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;

import dev.openfeature.sdk.fixtures.HookFixtures;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class StringHookTest implements HookFixtures {

private Hook<String> hook;

@BeforeEach
void setupTest() {
hook = mockStringHook();
}

@Test
void verifyFlagValueTypeIsSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.STRING);

assertThat(hookSupported).isTrue();
}

@Test
void verifyFlagValueTypeIsNotSupportedByHook() {
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);

assertThat(hookSupported).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.openfeature.sdk.DoubleHook;
import dev.openfeature.sdk.Hook;
import dev.openfeature.sdk.IntegerHook;
import dev.openfeature.sdk.ObjectHook;
import dev.openfeature.sdk.StringHook;

public interface HookFixtures {
Expand All @@ -26,6 +27,10 @@ default Hook<Double> mockDoubleHook() {
return spy(DoubleHook.class);
}

default Hook<Object> mockObjectHook() {
return spy(ObjectHook.class);
}

default Hook<?> mockGenericHook() {
return spy(Hook.class);
}
Expand Down
Loading