12
12
import static org .mockito .Mockito .times ;
13
13
import static org .mockito .Mockito .verify ;
14
14
15
+ import java .io .Serializable ;
16
+ import java .util .ArrayList ;
15
17
import java .util .HashMap ;
16
18
import java .util .List ;
17
19
import java .util .Map ;
18
20
19
- import com . google . common . collect . ImmutableList ;
21
+
20
22
import dev .openfeature .sdk .exceptions .FlagNotFoundError ;
21
- import io .cucumber .java .hu .Ha ;
22
23
import org .junit .jupiter .api .AfterEach ;
24
+ import org .junit .jupiter .api .BeforeEach ;
23
25
import org .junit .jupiter .api .Test ;
24
26
25
27
import dev .openfeature .sdk .fixtures .HookFixtures ;
26
- import uk .org .lidalia .slf4jtest .LoggingEvent ;
27
- import uk .org .lidalia .slf4jtest .TestLogger ;
28
- import uk .org .lidalia .slf4jtest .TestLoggerFactory ;
28
+ import org .mockito .ArgumentMatchers ;
29
+ import org .mockito .Mockito ;
30
+ import org .simplify4u .slf4jmock .LoggerMock ;
31
+ import org .slf4j .Logger ;
29
32
30
33
class FlagEvaluationSpecTest implements HookFixtures {
31
34
32
- private static final TestLogger TEST_LOGGER = TestLoggerFactory . getTestLogger ( OpenFeatureClient . class ) ;
35
+ private Logger logger ;
33
36
34
37
private Client _client () {
35
38
OpenFeatureAPI api = OpenFeatureAPI .getInstance ();
@@ -42,6 +45,15 @@ private Client _client() {
42
45
api .setEvaluationContext (null );
43
46
}
44
47
48
+ @ BeforeEach void set_logger () {
49
+ logger = Mockito .mock (Logger .class );
50
+ LoggerMock .setMock (OpenFeatureClient .class , logger );
51
+ }
52
+
53
+ @ AfterEach void reset_logs () {
54
+ LoggerMock .setMock (OpenFeatureClient .class , logger );
55
+ }
56
+
45
57
@ Specification (number ="1.1.1" , text ="The API, and any state it maintains SHOULD exist as a global singleton, even in cases wherein multiple versions of the API are present at runtime." )
46
58
@ Test void global_singleton () {
47
59
assertSame (OpenFeatureAPI .getInstance (), OpenFeatureAPI .getInstance ());
@@ -203,20 +215,16 @@ private Client _client() {
203
215
204
216
@ Specification (number ="1.4.10" , text ="In the case of abnormal execution, the client SHOULD log an informative error message." )
205
217
@ Test void log_on_error () throws NotImplementedException {
206
- TEST_LOGGER .clear ();
207
218
OpenFeatureAPI api = OpenFeatureAPI .getInstance ();
208
219
api .setProvider (new AlwaysBrokenProvider ());
209
220
Client c = api .getClient ();
210
221
FlagEvaluationDetails <Boolean > result = c .getBooleanDetails ("test" , false );
211
- assertEquals (Reason .ERROR .toString (), result .getReason ());
212
222
213
- ImmutableList <LoggingEvent > loggingEvents = TEST_LOGGER .getLoggingEvents ();
214
- assertThat (loggingEvents .size ()).isGreaterThan (0 );
215
-
216
- LoggingEvent event = loggingEvents .get (0 );
217
- assertThat (event .getMessage ()).isEqualTo ("Unable to correctly evaluate flag with key '{}'" );
218
- assertThat (event .getThrowable ().isPresent ()).isTrue ();
219
- assertThat (event .getThrowable ().get ()).isInstanceOf (FlagNotFoundError .class );
223
+ assertEquals (Reason .ERROR .toString (), result .getReason ());
224
+ Mockito .verify (logger ).error (
225
+ ArgumentMatchers .contains ("Unable to correctly evaluate flag with key" ),
226
+ any (),
227
+ ArgumentMatchers .isA (FlagNotFoundError .class ));
220
228
}
221
229
222
230
@ Specification (number ="1.2.2" , text ="The client interface MUST define a metadata member or accessor, containing an immutable name field or accessor of type string, which corresponds to the name value supplied during client creation." )
0 commit comments