Skip to content

Commit 877a977

Browse files
jarebudevtoddbaert
authored andcommitted
added missing unit tests to increase test coverage
Signed-off-by: jarebudev <[email protected]>
1 parent 9f43e80 commit 877a977

File tree

7 files changed

+173
-0
lines changed

7 files changed

+173
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.openfeature.sdk;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import dev.openfeature.sdk.fixtures.HookFixtures;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
class BooleanHookTest implements HookFixtures {
10+
11+
private Hook<Boolean> hook;
12+
13+
@BeforeEach
14+
void setupTest() {
15+
hook = mockBooleanHook();
16+
}
17+
18+
@Test
19+
void verifyFlagValueTypeIsSupportedByHook() {
20+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.BOOLEAN);
21+
22+
assertThat(hookSupported).isTrue();
23+
}
24+
25+
@Test
26+
void verifyFlagValueTypeIsNotSupportedByHook() {
27+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);
28+
29+
assertThat(hookSupported).isFalse();
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.openfeature.sdk;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import dev.openfeature.sdk.fixtures.HookFixtures;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
class DoubleHookTest implements HookFixtures {
10+
11+
private Hook<Double> hook;
12+
13+
@BeforeEach
14+
void setupTest() {
15+
hook = mockDoubleHook();
16+
}
17+
18+
@Test
19+
void verifyFlagValueTypeIsSupportedByHook() {
20+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.DOUBLE);
21+
22+
assertThat(hookSupported).isTrue();
23+
}
24+
25+
@Test
26+
void verifyFlagValueTypeIsNotSupportedByHook() {
27+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.STRING);
28+
29+
assertThat(hookSupported).isFalse();
30+
}
31+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ void mergeShouldRetainItsSubkeysWhenOverridingContextHasNoTargetingKey() {
135135
assertArrayEquals(new Object[] {"key1_1"}, value.keySet().toArray());
136136
}
137137

138+
@DisplayName("Merge should obtain keys from the overriding context when the existing context is empty")
139+
@Test
140+
void mergeShouldObtainKeysFromOverridingContextWhenExistingContextIsEmpty() {
141+
HashMap<String, Value> attributes = new HashMap<>();
142+
attributes.put("key1", new Value("val1"));
143+
attributes.put("key2", new Value("val2"));
144+
145+
EvaluationContext ctx = new ImmutableContext();
146+
EvaluationContext overriding = new ImmutableContext(attributes);
147+
EvaluationContext merge = ctx.merge(overriding);
148+
assertArrayEquals(new Object[] {"key1", "key2"}, merge.keySet().toArray());
149+
}
150+
138151
@DisplayName("Two different MutableContext objects with the different contents are not considered equal")
139152
@Test
140153
void unequalImmutableContextsAreNotEqual() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.openfeature.sdk;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import dev.openfeature.sdk.fixtures.HookFixtures;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
class IntegerHookTest implements HookFixtures {
10+
11+
private Hook<Integer> hook;
12+
13+
@BeforeEach
14+
void setupTest() {
15+
hook = mockIntegerHook();
16+
}
17+
18+
@Test
19+
void verifyFlagValueTypeIsSupportedByHook() {
20+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);
21+
22+
assertThat(hookSupported).isTrue();
23+
}
24+
25+
@Test
26+
void verifyFlagValueTypeIsNotSupportedByHook() {
27+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.STRING);
28+
29+
assertThat(hookSupported).isFalse();
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.openfeature.sdk;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import dev.openfeature.sdk.fixtures.HookFixtures;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ObjectHookTest implements HookFixtures {
10+
11+
private Hook<Object> hook;
12+
13+
@BeforeEach
14+
void setupTest() {
15+
hook = mockObjectHook();
16+
}
17+
18+
@Test
19+
void verifyFlagValueTypeIsSupportedByHook() {
20+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.OBJECT);
21+
22+
assertThat(hookSupported).isTrue();
23+
}
24+
25+
@Test
26+
void verifyFlagValueTypeIsNotSupportedByHook() {
27+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);
28+
29+
assertThat(hookSupported).isFalse();
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.openfeature.sdk;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import dev.openfeature.sdk.fixtures.HookFixtures;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
class StringHookTest implements HookFixtures {
10+
11+
private Hook<String> hook;
12+
13+
@BeforeEach
14+
void setupTest() {
15+
hook = mockStringHook();
16+
}
17+
18+
@Test
19+
void verifyFlagValueTypeIsSupportedByHook() {
20+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.STRING);
21+
22+
assertThat(hookSupported).isTrue();
23+
}
24+
25+
@Test
26+
void verifyFlagValueTypeIsNotSupportedByHook() {
27+
boolean hookSupported = hook.supportsFlagValueType(FlagValueType.INTEGER);
28+
29+
assertThat(hookSupported).isFalse();
30+
}
31+
}

src/test/java/dev/openfeature/sdk/fixtures/HookFixtures.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.openfeature.sdk.DoubleHook;
77
import dev.openfeature.sdk.Hook;
88
import dev.openfeature.sdk.IntegerHook;
9+
import dev.openfeature.sdk.ObjectHook;
910
import dev.openfeature.sdk.StringHook;
1011

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

30+
default Hook<Object> mockObjectHook() {
31+
return spy(ObjectHook.class);
32+
}
33+
2934
default Hook<?> mockGenericHook() {
3035
return spy(Hook.class);
3136
}

0 commit comments

Comments
 (0)