6
6
import com .statsig .sdk .StatsigOptions ;
7
7
import com .statsig .sdk .StatsigUser ;
8
8
import dev .openfeature .sdk .Client ;
9
+ import dev .openfeature .sdk .FlagEvaluationDetails ;
9
10
import dev .openfeature .sdk .ImmutableContext ;
10
11
import dev .openfeature .sdk .MutableContext ;
11
12
import dev .openfeature .sdk .OpenFeatureAPI ;
@@ -54,6 +55,7 @@ class StatsigProviderTest {
54
55
public static final Double DOUBLE_FLAG_VALUE = 3.14 ;
55
56
public static final String USERS_FLAG_NAME = "userIdMatching" ;
56
57
public static final String PROPERTIES_FLAG_NAME = "emailMatching" ;
58
+ public static final String TARGETING_KEY = "user1" ;
57
59
private static StatsigProvider statsigProvider ;
58
60
private static Client client ;
59
61
@@ -115,15 +117,18 @@ static void shutdown() {
115
117
116
118
@ Test
117
119
void getBooleanEvaluation () {
118
- assertEquals (true , statsigProvider .getBooleanEvaluation (FLAG_NAME , false , new ImmutableContext ()).getValue ());
119
- assertEquals (true , client .getBooleanValue (FLAG_NAME , false ));
120
- assertEquals (false , statsigProvider .getBooleanEvaluation ("non-existing" , false , new ImmutableContext ()).getValue ());
121
- assertEquals (false , client .getBooleanValue ("non-existing" , false ));
122
-
123
- // expected to succeed when https://github.com/statsig-io/java-server-sdk/issues/22 is resolved and adopted
124
- // assertEquals(true, client.getBooleanValue("non-existing", true));
120
+ FlagEvaluationDetails <Boolean > flagEvaluationDetails = client .getBooleanDetails (FLAG_NAME , false , new ImmutableContext ());
121
+ assertEquals (false , flagEvaluationDetails .getValue ());
122
+ assertEquals ("ERROR" , flagEvaluationDetails .getReason ());
125
123
126
124
MutableContext evaluationContext = new MutableContext ();
125
+ evaluationContext .setTargetingKey (TARGETING_KEY );
126
+ assertEquals (true , statsigProvider .getBooleanEvaluation (FLAG_NAME , false , evaluationContext ).getValue ());
127
+ assertEquals (true , client .getBooleanValue (FLAG_NAME , false , evaluationContext ));
128
+ assertEquals (false , statsigProvider .getBooleanEvaluation ("non-existing" , false , evaluationContext ).getValue ());
129
+ assertEquals (false , client .getBooleanValue ("non-existing" , false , evaluationContext ));
130
+ assertEquals (true , client .getBooleanValue ("non-existing" , true ));
131
+
127
132
MutableContext featureConfig = new MutableContext ();
128
133
featureConfig .add ("type" , "CONFIG" );
129
134
featureConfig .add ("name" , "product" );
@@ -135,6 +140,7 @@ void getBooleanEvaluation() {
135
140
@ Test
136
141
void getStringEvaluation () {
137
142
MutableContext evaluationContext = new MutableContext ();
143
+ evaluationContext .setTargetingKey (TARGETING_KEY );
138
144
MutableContext featureConfig = new MutableContext ();
139
145
featureConfig .add ("type" , "CONFIG" );
140
146
featureConfig .add ("name" , "product" );
@@ -149,6 +155,7 @@ void getStringEvaluation() {
149
155
@ Test
150
156
void getObjectConfigEvaluation () {
151
157
MutableContext evaluationContext = new MutableContext ();
158
+ evaluationContext .setTargetingKey (TARGETING_KEY );
152
159
MutableContext featureConfig = new MutableContext ();
153
160
featureConfig .add ("type" , "CONFIG" );
154
161
featureConfig .add ("name" , "object-config-name" );
@@ -164,6 +171,7 @@ void getObjectConfigEvaluation() {
164
171
@ Test
165
172
void getObjectLayerEvaluation () {
166
173
MutableContext evaluationContext = new MutableContext ();
174
+ evaluationContext .setTargetingKey (TARGETING_KEY );
167
175
MutableContext featureConfig = new MutableContext ();
168
176
featureConfig .add ("type" , "LAYER" );
169
177
featureConfig .add ("name" , "layer-name" );
@@ -180,6 +188,7 @@ void getObjectLayerEvaluation() {
180
188
@ Test
181
189
void getIntegerEvaluation () {
182
190
MutableContext evaluationContext = new MutableContext ();
191
+ evaluationContext .setTargetingKey (TARGETING_KEY );
183
192
MutableContext featureConfig = new MutableContext ();
184
193
featureConfig .add ("type" , "CONFIG" );
185
194
featureConfig .add ("name" , "product" );
@@ -197,6 +206,7 @@ void getIntegerEvaluation() {
197
206
@ Test
198
207
void getDoubleEvaluation () {
199
208
MutableContext evaluationContext = new MutableContext ();
209
+ evaluationContext .setTargetingKey (TARGETING_KEY );
200
210
MutableContext featureConfig = new MutableContext ();
201
211
featureConfig .add ("type" , "CONFIG" );
202
212
featureConfig .add ("name" , "product" );
@@ -214,6 +224,7 @@ void getDoubleEvaluation() {
214
224
@ Test
215
225
void getBooleanEvaluationByUser () {
216
226
MutableContext evaluationContext = new MutableContext ();
227
+ evaluationContext .setTargetingKey (TARGETING_KEY );
217
228
MutableContext featureConfig = new MutableContext ();
218
229
featureConfig .add ("type" , "CONFIG" );
219
230
featureConfig .add ("name" , "product" );
0 commit comments