Show what using EvaluationContext looks like in dev experience tests

Signed-off-by: Justin Abrahms <justin@abrah.ms>
This commit is contained in:
Justin Abrahms 2022-08-26 08:35:59 -07:00
parent 2ad492a79c
commit aeb14f61e3
No known key found for this signature in database
GPG Key ID: 599E2E12011DC474
1 changed files with 23 additions and 1 deletions

View File

@ -10,7 +10,8 @@ import org.junit.jupiter.api.Test;
import dev.openfeature.javasdk.fixtures.HookFixtures;
@SuppressWarnings("unchecked")
import java.util.Arrays;
class DeveloperExperienceTest implements HookFixtures {
transient String flagKey = "mykey";
@ -58,6 +59,27 @@ class DeveloperExperienceTest implements HookFixtures {
assertFalse(retval);
}
/**
* As an application author, you probably know special things about your users. You can communicate these to the
* provider via {@link EvaluationContext}
*/
@Test void providingContext() {
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new NoOpProvider());
Client client = api.getClient();
EvaluationContext ctx = new EvaluationContext()
.add("int-val", 3)
.add("double-val", 4.0)
.add("str-val", "works")
.add("bool-val", false)
.add("value-val", Arrays.asList(new Value(2), new Value(4)));
Boolean retval = client.getBooleanValue(flagKey, false, ctx);
assertFalse(retval);
}
@Test void brokenProvider() {
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new AlwaysBrokenProvider());