@@ -82,32 +82,7 @@ Client _client() {
82
82
"evaluation, including boolean, numeric, string, and structure." )
83
83
@ Test void value_flags () {
84
84
OpenFeatureAPI api = OpenFeatureAPI .getInstance ();
85
- api .setProvider (new FeatureProvider () {
86
- @ Override
87
- public String getName () {
88
- return "test" ;
89
- }
90
-
91
- @ Override
92
- public ProviderEvaluation <Boolean > getBooleanEvaluation (String key , Boolean defaultValue , EvaluationContext ctx , FlagEvaluationOptions options ) {
93
- return ProviderEvaluation .<Boolean >builder ()
94
- .value (!defaultValue ).build ();
95
- }
96
-
97
- @ Override
98
- public ProviderEvaluation <String > getStringEvaluation (String key , String defaultValue , EvaluationContext ctx , FlagEvaluationOptions options ) {
99
- return ProviderEvaluation .<String >builder ()
100
- .value (new StringBuilder (defaultValue ).reverse ().toString ())
101
- .build ();
102
- }
103
-
104
- @ Override
105
- public ProviderEvaluation <Integer > getIntegerEvaluation (String key , Integer defaultValue , EvaluationContext ctx , FlagEvaluationOptions options ) {
106
- return ProviderEvaluation .<Integer >builder ()
107
- .value (defaultValue * 100 )
108
- .build ();
109
- }
110
- });
85
+ api .setProvider (new DoSomethingProvider ());
111
86
Client c = api .getClient ();
112
87
String key = "key" ;
113
88
@@ -146,21 +121,37 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
146
121
"field." )
147
122
@ Specification (spec ="flag evaluation" , number ="1.12" , text ="The evaluation details structure's flag key field MUST " +
148
123
"contain the flag key argument passed to the detailed flag evaluation method." )
149
- @ Specification (spec ="flag evaluation" , number ="1.13" , text ="In cases of normal execution, the evaluation details " +
150
- "structure's variant field MUST contain the value of the variant field in the flag resolution structure " +
151
- "returned by the configured provider, if the field is set." )
152
- @ Specification (spec ="flag evaluation" , number ="1.14" , text ="In cases of normal execution, the evaluation details " +
153
- "structure's reason field MUST contain the value of the reason field in the flag resolution structure " +
154
- "returned by the configured provider, if the field is set." )
155
- @ Specification (spec ="flag evaluation" , number ="1.15" , text ="In cases of abnormal execution, the evaluation details " +
156
- "structure's error code field MUST identify an error occurred during flag evaluation, having possible " +
157
- "values PROVIDER_NOT_READY, FLAG_NOT_FOUND, PARSE_ERROR, TYPE_MISMATCH, or GENERAL." )
158
- @ Specification (spec ="flag evaluation" , number ="1.16" , text ="In cases of abnormal execution (network failure, " +
159
- "unhandled error, etc) the reason field in the evaluation details SHOULD indicate an error." )
160
- @ Disabled
161
124
@ Test void detail_flags () {
162
- // TODO: Add tests re: detail functions.
163
- throw new NotImplementedException ();
125
+ OpenFeatureAPI api = OpenFeatureAPI .getInstance ();
126
+ api .setProvider (new DoSomethingProvider ());
127
+ Client c = api .getClient ();
128
+ String key = "key" ;
129
+
130
+ FlagEvaluationDetails <Boolean > bd = FlagEvaluationDetails .<Boolean >builder ()
131
+ .flagKey (key )
132
+ .value (false )
133
+ .variant (null )
134
+ .build ();
135
+ assertEquals (bd , c .getBooleanDetails (key , true ));
136
+ assertEquals (bd , c .getBooleanDetails (key , true , new EvaluationContext ()));
137
+ assertEquals (bd , c .getBooleanDetails (key , true , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
138
+
139
+ FlagEvaluationDetails <String > sd = FlagEvaluationDetails .<String >builder ()
140
+ .flagKey (key )
141
+ .value ("tset" )
142
+ .variant (null )
143
+ .build ();
144
+ assertEquals (sd , c .getStringDetails (key , "test" ));
145
+ assertEquals (sd , c .getStringDetails (key , "test" , new EvaluationContext ()));
146
+ assertEquals (sd , c .getStringDetails (key , "test" , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
147
+
148
+ FlagEvaluationDetails <Integer > id = FlagEvaluationDetails .<Integer >builder ()
149
+ .flagKey (key )
150
+ .value (400 )
151
+ .build ();
152
+ assertEquals (id , c .getIntegerDetails (key , 4 ));
153
+ assertEquals (id , c .getIntegerDetails (key , 4 , new EvaluationContext ()));
154
+ assertEquals (id , c .getIntegerDetails (key , 4 , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
164
155
}
165
156
166
157
@ Specification (spec ="flag evaluation" , number ="1.17" , text ="The evaluation options structure's hooks field denotes " +
@@ -199,6 +190,17 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
199
190
@ Specification (spec ="flag evaluation" , number ="1.21" , text ="The client MUST transform the evaluation context using " +
200
191
"the provider's context transformer function, before passing the result of the transformation to the " +
201
192
"provider's flag resolution functions." )
193
+ @ Specification (spec ="flag evaluation" , number ="1.13" , text ="In cases of normal execution, the evaluation details " +
194
+ "structure's variant field MUST contain the value of the variant field in the flag resolution structure " +
195
+ "returned by the configured provider, if the field is set." )
196
+ @ Specification (spec ="flag evaluation" , number ="1.14" , text ="In cases of normal execution, the evaluation details " +
197
+ "structure's reason field MUST contain the value of the reason field in the flag resolution structure " +
198
+ "returned by the configured provider, if the field is set." )
199
+ @ Specification (spec ="flag evaluation" , number ="1.15" , text ="In cases of abnormal execution, the evaluation details " +
200
+ "structure's error code field MUST identify an error occurred during flag evaluation, having possible " +
201
+ "values PROVIDER_NOT_READY, FLAG_NOT_FOUND, PARSE_ERROR, TYPE_MISMATCH, or GENERAL." )
202
+ @ Specification (spec ="flag evaluation" , number ="1.16" , text ="In cases of abnormal execution (network failure, " +
203
+ "unhandled error, etc) the reason field in the evaluation details SHOULD indicate an error." )
202
204
@ Test @ Disabled void todo () {}
203
205
204
206
@ Specification (spec ="flag evaluation" , number ="1.20" , text ="The client SHOULD provide asynchronous or non-blocking " +
0 commit comments