11package dev .openfeature .sdk .providers .memory ;
22
33import com .google .common .collect .ImmutableMap ;
4- import dev .openfeature .sdk .Client ;
5- import dev .openfeature .sdk .EventDetails ;
6- import dev .openfeature .sdk .ImmutableContext ;
7- import dev .openfeature .sdk .OpenFeatureAPI ;
8- import dev .openfeature .sdk .Value ;
4+ import dev .openfeature .sdk .*;
95import dev .openfeature .sdk .exceptions .FlagNotFoundError ;
6+ import dev .openfeature .sdk .exceptions .GeneralError ;
107import dev .openfeature .sdk .exceptions .ProviderNotReadyError ;
118import dev .openfeature .sdk .exceptions .TypeMismatchError ;
129import lombok .SneakyThrows ;
1916
2017import static dev .openfeature .sdk .Structure .mapToStructure ;
2118import static dev .openfeature .sdk .testutils .TestFlagsUtils .buildFlags ;
22- import static org .junit .jupiter .api .Assertions .assertEquals ;
23- import static org .junit .jupiter .api .Assertions .assertThrows ;
24- import static org .junit .jupiter .api .Assertions .assertTrue ;
2519import static org .awaitility .Awaitility .await ;
20+ import static org .junit .jupiter .api .Assertions .*;
2621import static org .mockito .ArgumentMatchers .any ;
2722import static org .mockito .ArgumentMatchers .argThat ;
28- import static org .mockito .Mockito .mock ;
29- import static org .mockito .Mockito .spy ;
30- import static org .mockito .Mockito .times ;
31- import static org .mockito .Mockito .verify ;
23+ import static org .mockito .Mockito .*;
3224
3325class InMemoryProviderTest {
3426
@@ -41,15 +33,16 @@ class InMemoryProviderTest {
4133 void beforeEach () {
4234 Map <String , Flag <?>> flags = buildFlags ();
4335 provider = spy (new InMemoryProvider (flags ));
44- OpenFeatureAPI .getInstance ().onProviderConfigurationChanged (eventDetails -> {});
36+ OpenFeatureAPI .getInstance ().onProviderConfigurationChanged (eventDetails -> {
37+ });
4538 OpenFeatureAPI .getInstance ().setProviderAndWait (provider );
4639 client = OpenFeatureAPI .getInstance ().getClient ();
4740 provider .updateFlags (flags );
4841 provider .updateFlag ("addedFlag" , Flag .builder ()
49- .variant ("on" , true )
50- .variant ("off" , false )
51- .defaultVariant ("on" )
52- .build ());
42+ .variant ("on" , true )
43+ .variant ("off" , false )
44+ .defaultVariant ("on" )
45+ .build ());
5346 }
5447
5548 @ SneakyThrows
@@ -81,9 +74,9 @@ void getDoubleEvaluation() {
8174 @ Test
8275 void getObjectEvaluation () {
8376 Value expectedObject = new Value (mapToStructure (ImmutableMap .of (
84- "showImages" , new Value (true ),
85- "title" , new Value ("Check out these pics!" ),
86- "imagesPerPage" , new Value (100 )
77+ "showImages" , new Value (true ),
78+ "title" , new Value ("Check out these pics!" ),
79+ "imagesPerPage" , new Value (100 )
8780 )));
8881 assertEquals (expectedObject , client .getObjectValue ("object-flag" , new Value (true )));
8982 }
@@ -108,7 +101,7 @@ void shouldThrowIfNotInitialized() {
108101 InMemoryProvider inMemoryProvider = new InMemoryProvider (new HashMap <>());
109102
110103 // ErrorCode.PROVIDER_NOT_READY should be returned when evaluated via the client
111- assertThrows (ProviderNotReadyError .class , ()-> inMemoryProvider .getBooleanEvaluation ("fail_not_initialized" , false , new ImmutableContext ()));
104+ assertThrows (ProviderNotReadyError .class , () -> inMemoryProvider .getBooleanEvaluation ("fail_not_initialized" , false , new ImmutableContext ()));
112105 }
113106
114107 @ SuppressWarnings ("unchecked" )
@@ -125,4 +118,15 @@ void emitChangedFlagsOnlyIfThereAreChangedFlags() {
125118 await ().untilAsserted (() -> verify (handler , times (1 ))
126119 .accept (argThat (details -> details .getFlagsChanged ().size () == buildFlags ().size ())));
127120 }
121+
122+ @ SneakyThrows
123+ @ Test
124+ void shouldThrowGeneralErrorAfterEmittingErrorEvent () {
125+ InMemoryProvider inMemoryProvider = new InMemoryProvider (new HashMap <>());
126+ inMemoryProvider .initialize (null );
127+ inMemoryProvider .emitProviderError (ProviderEventDetails .builder ().build ());
128+
129+ // ErrorCode.GENERAL should be returned when evaluated via the client
130+ assertThrows (GeneralError .class , () -> inMemoryProvider .getBooleanEvaluation ("fail_in_error" , false , new ImmutableContext ()));
131+ }
128132}
0 commit comments