Add method to get double
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org> Signed-off-by: Robert Grassian <robert.grassian@split.io>
This commit is contained in:
parent
1508c94119
commit
cfc94c5b77
|
|
@ -8,5 +8,6 @@ public interface FeatureProvider {
|
||||||
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||||
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||||
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||||
|
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||||
<T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options);
|
<T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,14 @@ public class NoOpProvider implements FeatureProvider {
|
||||||
.reason(Reason.DEFAULT)
|
.reason(Reason.DEFAULT)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||||
|
return ProviderEvaluation.<Double>builder()
|
||||||
|
.value(defaultValue)
|
||||||
|
.variant(PASSED_IN_DEFAULT)
|
||||||
|
.reason(Reason.DEFAULT)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
|
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
|
||||||
return ProviderEvaluation.<T>builder()
|
return ProviderEvaluation.<T>builder()
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@ public class AlwaysBrokenProvider implements FeatureProvider {
|
||||||
throw new NotImplementedException("BORK");
|
throw new NotImplementedException("BORK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||||
|
throw new NotImplementedException("BORK");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
|
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
|
||||||
throw new NotImplementedException("BORK");
|
throw new NotImplementedException("BORK");
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,13 @@ public class DoSomethingProvider implements FeatureProvider {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||||
|
return ProviderEvaluation.<Double>builder()
|
||||||
|
.value(defaultValue * 100)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
|
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
|
||||||
return ProviderEvaluation.<T>builder()
|
return ProviderEvaluation.<T>builder()
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ public class NoOpProviderTest {
|
||||||
assertEquals(4, eval.getValue());
|
assertEquals(4, eval.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test void noOpdouble() {
|
||||||
|
NoOpProvider p = new NoOpProvider();
|
||||||
|
ProviderEvaluation<Double> eval = p.getDoubleEvaluation("key", 0.4, null, null);
|
||||||
|
assertEquals(0.4, eval.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test void structure() {
|
@Test void structure() {
|
||||||
NoOpProvider p = new NoOpProvider();
|
NoOpProvider p = new NoOpProvider();
|
||||||
Node<Integer> node = new Node<Integer>();
|
Node<Integer> node = new Node<Integer>();
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ public class ProviderSpecTest {
|
||||||
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
||||||
assertNotNull(int_result.getValue());
|
assertNotNull(int_result.getValue());
|
||||||
|
|
||||||
|
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
||||||
|
assertNotNull(double_result.getValue());
|
||||||
|
|
||||||
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
||||||
assertNotNull(string_result.getValue());
|
assertNotNull(string_result.getValue());
|
||||||
|
|
||||||
|
|
@ -67,6 +70,9 @@ public class ProviderSpecTest {
|
||||||
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
||||||
assertNotNull(int_result.getReason());
|
assertNotNull(int_result.getReason());
|
||||||
|
|
||||||
|
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
||||||
|
assertNotNull(double_result.getReason());
|
||||||
|
|
||||||
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
|
||||||
assertNotNull(string_result.getReason());
|
assertNotNull(string_result.getReason());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue