@@ -81,20 +81,48 @@ Client _client() {
81
81
@ Specification (spec ="flag evaluation" , number ="1.8.1" ,text ="The client MUST provide methods for typed flag " +
82
82
"evaluation, including boolean, numeric, string, and structure." )
83
83
@ Test void value_flags () {
84
- Client c = _client ();
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
+ });
111
+ Client c = api .getClient ();
85
112
String key = "key" ;
86
- assertFalse (c .getBooleanValue (key , false ));
87
- assertFalse (c .getBooleanValue (key , false , new EvaluationContext ()));
88
- assertFalse (c .getBooleanValue (key , false , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
113
+
114
+ assertEquals (true , c .getBooleanValue (key , false ));
115
+ assertEquals (true , c .getBooleanValue (key , false , new EvaluationContext ()));
116
+ assertEquals (true , c .getBooleanValue (key , false , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
89
117
90
118
91
- assertEquals ("my-string " , c .getStringValue (key , "my-string" ));
92
- assertEquals ("my-string " , c .getStringValue (key , "my-string" , new EvaluationContext ()));
93
- assertEquals ("my-string " , c .getStringValue (key , "my-string" , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
119
+ assertEquals ("gnirts-ym " , c .getStringValue (key , "my-string" ));
120
+ assertEquals ("gnirts-ym " , c .getStringValue (key , "my-string" , new EvaluationContext ()));
121
+ assertEquals ("gnirts-ym " , c .getStringValue (key , "my-string" , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
94
122
95
- assertEquals (4 , c .getIntegerValue (key , 4 ));
96
- assertEquals (4 , c .getIntegerValue (key , 4 , new EvaluationContext ()));
97
- assertEquals (4 , c .getIntegerValue (key , 4 , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
123
+ assertEquals (400 , c .getIntegerValue (key , 4 ));
124
+ assertEquals (400 , c .getIntegerValue (key , 4 , new EvaluationContext ()));
125
+ assertEquals (400 , c .getIntegerValue (key , 4 , new EvaluationContext (), FlagEvaluationOptions .builder ().build ()));
98
126
99
127
}
100
128
0 commit comments