Skip to content

Commit 4a3faf1

Browse files
committed
fixup: add missing steps and adapt to new spec steps
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 017611b commit 4a3faf1

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

spec

src/main/java/dev/openfeature/sdk/providers/memory/Flag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public class Flag<T> {
2020
private String defaultVariant;
2121
private ContextEvaluator<T> contextEvaluator;
2222
private ImmutableMetadata flagMetadata;
23+
private boolean disabled;
2324
}

src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,36 +97,37 @@ public void updateFlag(String flagKey, Flag<?> newFlag) {
9797
@Override
9898
public ProviderEvaluation<Boolean> getBooleanEvaluation(
9999
String key, Boolean defaultValue, EvaluationContext evaluationContext) {
100-
return getEvaluation(key, evaluationContext, Boolean.class);
100+
return getEvaluation(key, defaultValue, evaluationContext, Boolean.class);
101101
}
102102

103103
@Override
104104
public ProviderEvaluation<String> getStringEvaluation(
105105
String key, String defaultValue, EvaluationContext evaluationContext) {
106-
return getEvaluation(key, evaluationContext, String.class);
106+
return getEvaluation(key, defaultValue, evaluationContext, String.class);
107107
}
108108

109109
@Override
110110
public ProviderEvaluation<Integer> getIntegerEvaluation(
111111
String key, Integer defaultValue, EvaluationContext evaluationContext) {
112-
return getEvaluation(key, evaluationContext, Integer.class);
112+
return getEvaluation(key, defaultValue, evaluationContext, Integer.class);
113113
}
114114

115115
@Override
116116
public ProviderEvaluation<Double> getDoubleEvaluation(
117117
String key, Double defaultValue, EvaluationContext evaluationContext) {
118-
return getEvaluation(key, evaluationContext, Double.class);
118+
return getEvaluation(key, defaultValue, evaluationContext, Double.class);
119119
}
120120

121121
@SneakyThrows
122122
@Override
123123
public ProviderEvaluation<Value> getObjectEvaluation(
124124
String key, Value defaultValue, EvaluationContext evaluationContext) {
125-
return getEvaluation(key, evaluationContext, Value.class);
125+
return getEvaluation(key, defaultValue, evaluationContext, Value.class);
126126
}
127127

128128
private <T> ProviderEvaluation<T> getEvaluation(
129-
String key, EvaluationContext evaluationContext, Class<?> expectedType) throws OpenFeatureError {
129+
String key, T defaultValue, EvaluationContext evaluationContext, Class<?> expectedType)
130+
throws OpenFeatureError {
130131
if (!ProviderState.READY.equals(state)) {
131132
if (ProviderState.NOT_READY.equals(state)) {
132133
throw new ProviderNotReadyError("provider not yet initialized");
@@ -140,6 +141,13 @@ private <T> ProviderEvaluation<T> getEvaluation(
140141
if (flag == null) {
141142
throw new FlagNotFoundError("flag " + key + " not found");
142143
}
144+
if (flag.isDisabled()) {
145+
return ProviderEvaluation.<T>builder()
146+
.reason(Reason.DISABLED.name())
147+
.value(defaultValue)
148+
.flagMetadata(flag.getFlagMetadata())
149+
.build();
150+
}
143151
T value;
144152
Reason reason = Reason.STATIC;
145153
if (flag.getContextEvaluator() != null) {

src/test/java/dev/openfeature/sdk/e2e/GherkinSpecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
1717
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.sdk.e2e.steps")
1818
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
19-
@ExcludeTags({"deprecated", "reason-codes", "async", "immutability", "evaluation-options"})
19+
@ExcludeTags({"deprecated", "reason-codes-cached", "async", "immutability", "evaluation-options"})
2020
public class GherkinSpecTest {}

src/test/java/dev/openfeature/sdk/e2e/steps/FlagStepDefinitions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public FlagStepDefinitions(State state) {
2424
this.state = state;
2525
}
2626

27-
@Given("a {}-flag with key {string} and a default value {string}")
27+
@Given("a {}-flag with key {string} and a fallback value {string}")
2828
public void givenAFlag(String type, String name, String defaultValue) {
2929
state.flag = new Flag(type, name, Utils.convert(defaultValue, type));
3030
}

0 commit comments

Comments
 (0)