-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add getNumberEvaluation method delegating to getDoubleEvaluation (#501) #1536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,9 +287,11 @@ private <T> ProviderEvaluation<?> createProviderEvaluation( | |
case STRING: | ||
return provider.getStringEvaluation(key, (String) defaultValue, invocationContext); | ||
case INTEGER: | ||
return provider.getIntegerEvaluation(key, (Integer) defaultValue, invocationContext); | ||
return provider.getNumberEvaluation(key, (Integer) defaultValue, invocationContext); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to modify/cast here the resolved value to an Integer before returning, for backwards compatibility? |
||
case NUMBER: | ||
return provider.getNumberEvaluation(key, (Number) defaultValue, invocationContext); | ||
case DOUBLE: | ||
return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext); | ||
return provider.getNumberEvaluation(key, (Double) defaultValue, invocationContext); | ||
case OBJECT: | ||
return provider.getObjectEvaluation(key, (Value) defaultValue, invocationContext); | ||
default: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,11 @@ void value() { | |
ProviderEvaluation<Value> eval = p.getObjectEvaluation("key", s, null); | ||
assertEquals(s, eval.getValue()); | ||
} | ||
|
||
@Test | ||
void noOpNumber() { | ||
NoOpProvider p = new NoOpProvider(); | ||
ProviderEvaluation<Number> eval = p.getNumberEvaluation("key", 123456789L, null); | ||
assertEquals(123456789.0, eval.getValue()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is good for verifying the returned value. To make it more robust, I suggest adding assertions for the assertEquals(123456789.0, eval.getValue());
assertEquals(NoOpProvider.PASSED_IN_DEFAULT, eval.getVariant());
assertEquals(Reason.DEFAULT.toString(), eval.getReason()); |
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -40,6 +40,9 @@ void flag_value_set() { | |||||
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new ImmutableContext()); | ||||||
assertNotNull(int_result.getValue()); | ||||||
|
||||||
ProviderEvaluation<Number> number_result = p.getNumberEvaluation("key", 2L, new ImmutableContext()); | ||||||
assertNotNull(number_result.getValue()); | ||||||
|
||||||
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new ImmutableContext()); | ||||||
assertNotNull(double_result.getValue()); | ||||||
|
||||||
|
@@ -97,6 +100,9 @@ void variant_set() { | |||||
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new ImmutableContext()); | ||||||
assertNotNull(int_result.getReason()); | ||||||
|
||||||
ProviderEvaluation<Number> number_result = p.getNumberEvaluation("key", 2L, new ImmutableContext()); | ||||||
assertNotNull(number_result.getReason()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test method is named
Suggested change
|
||||||
|
||||||
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new ImmutableContext()); | ||||||
assertNotNull(double_result.getReason()); | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bug in the constructor call for
ProviderEvaluation
. The arguments forvariant
andreason
are swapped. According to theProviderEvaluation
class definition, the constructor expectsvariant
beforereason
. This will lead to incorrect evaluation details.