88import dev .openfeature .sdk .NoOpTransactionContextPropagator ;
99import dev .openfeature .sdk .OpenFeatureAPI ;
1010import dev .openfeature .sdk .ThreadLocalTransactionContextPropagator ;
11+ import dev .openfeature .sdk .isolated .OpenFeatureAPIFactory ;
1112import dev .openfeature .sdk .providers .memory .Flag ;
1213import dev .openfeature .sdk .providers .memory .InMemoryProvider ;
1314import java .util .Map ;
@@ -30,8 +31,8 @@ class IsolatedAPITest {
3031 @ Test
3132 @ DisplayName ("factory creates distinct API instances" )
3233 void factoryCreatesDistinctInstances () {
33- OpenFeatureAPI api1 = new OpenFeatureAPI ();
34- OpenFeatureAPI api2 = new OpenFeatureAPI ();
34+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
35+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
3536
3637 assertThat (api1 ).isInstanceOf (OpenFeatureAPI .class ).isNotSameAs (api2 );
3738 }
@@ -42,8 +43,8 @@ void factoryCreatesDistinctInstances() {
4243 @ Test
4344 @ DisplayName ("providers are isolated between instances" )
4445 void providerIsolation () {
45- OpenFeatureAPI api1 = new OpenFeatureAPI ();
46- OpenFeatureAPI api2 = new OpenFeatureAPI ();
46+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
47+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
4748
4849 InMemoryProvider provider = new InMemoryProvider (Map .of ());
4950 api1 .setProvider (provider );
@@ -58,8 +59,8 @@ void providerIsolation() {
5859 @ Test
5960 @ DisplayName ("hooks are isolated between instances" )
6061 void hookIsolation () {
61- OpenFeatureAPI api1 = new OpenFeatureAPI ();
62- OpenFeatureAPI api2 = new OpenFeatureAPI ();
62+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
63+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
6364
6465 api1 .addHooks (new NoOpHook ());
6566
@@ -73,8 +74,8 @@ void hookIsolation() {
7374 @ Test
7475 @ DisplayName ("evaluation context is isolated between instances" )
7576 void evaluationContextIsolation () {
76- OpenFeatureAPI api1 = new OpenFeatureAPI ();
77- OpenFeatureAPI api2 = new OpenFeatureAPI ();
77+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
78+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
7879
7980 api1 .setEvaluationContext (new ImmutableContext ("key-1" ));
8081 api2 .setEvaluationContext (new ImmutableContext ("key-2" ));
@@ -90,8 +91,8 @@ void evaluationContextIsolation() {
9091 @ Timeout (value = 2 , threadMode = Timeout .ThreadMode .SEPARATE_THREAD )
9192 @ DisplayName ("event handlers are isolated between instances" )
9293 void eventHandlerIsolation () throws Exception {
93- OpenFeatureAPI api1 = new OpenFeatureAPI ();
94- OpenFeatureAPI api2 = new OpenFeatureAPI ();
94+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
95+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
9596
9697 CountDownLatch api1HandlerLatch = new CountDownLatch (1 );
9798 AtomicBoolean api2HandlerCalled = new AtomicBoolean (false );
@@ -119,8 +120,8 @@ void eventHandlerIsolation() throws Exception {
119120 @ Test
120121 @ DisplayName ("transaction context propagator is isolated between instances" )
121122 void transactionContextPropagatorIsolation () {
122- OpenFeatureAPI api1 = new OpenFeatureAPI ();
123- OpenFeatureAPI api2 = new OpenFeatureAPI ();
123+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
124+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
124125
125126 ThreadLocalTransactionContextPropagator propagator = new ThreadLocalTransactionContextPropagator ();
126127 api1 .setTransactionContextPropagator (propagator );
@@ -136,7 +137,7 @@ void transactionContextPropagatorIsolation() {
136137 @ Test
137138 @ DisplayName ("isolated instance conforms to API contract" )
138139 void isolatedInstanceConformsToAPIContract () throws Exception {
139- OpenFeatureAPI api = new OpenFeatureAPI ();
140+ OpenFeatureAPI api = OpenFeatureAPIFactory . createAPI ();
140141
141142 // provider management
142143 InMemoryProvider provider = new InMemoryProvider (Map .of (
@@ -171,8 +172,8 @@ void isolatedInstanceConformsToAPIContract() throws Exception {
171172 @ Test
172173 @ DisplayName ("clearHooks does not affect other instances" )
173174 void clearHooksDoesNotAffectOtherInstances () {
174- OpenFeatureAPI api1 = new OpenFeatureAPI ();
175- OpenFeatureAPI api2 = new OpenFeatureAPI ();
175+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
176+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
176177
177178 NoOpHook hook = new NoOpHook ();
178179 api1 .addHooks (hook );
@@ -191,8 +192,8 @@ void clearHooksDoesNotAffectOtherInstances() {
191192 @ Test
192193 @ DisplayName ("clients use their own instance's provider" )
193194 void clientUsesItsOwnInstanceProvider () throws Exception {
194- OpenFeatureAPI api1 = new OpenFeatureAPI ();
195- OpenFeatureAPI api2 = new OpenFeatureAPI ();
195+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
196+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
196197
197198 api1 .setProviderAndWait (new InMemoryProvider (Map .of (
198199 "flag1" ,
@@ -220,8 +221,8 @@ void warnWhenProviderBoundToMultipleInstances() {
220221 Logger mockLogger = Mockito .mock (Logger .class );
221222 LoggerMock .setMock (OpenFeatureAPI .class , mockLogger );
222223 try {
223- OpenFeatureAPI api1 = new OpenFeatureAPI ();
224- OpenFeatureAPI api2 = new OpenFeatureAPI ();
224+ OpenFeatureAPI api1 = OpenFeatureAPIFactory . createAPI ();
225+ OpenFeatureAPI api2 = OpenFeatureAPIFactory . createAPI ();
225226
226227 NoOpProvider provider = new NoOpProvider ();
227228 api1 .setProvider (provider );
0 commit comments