Skip to content

Commit 4041ebc

Browse files
committed
test: use direct constructor in isolated tests
Signed-off-by: marcozabel <marco.zabel@dynatrace.com>
1 parent 3a25c3c commit 4041ebc

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/test/java/dev/openfeature/sdk/isolated/IsolatedAPISingeltonTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void isolatedInstanceDoesNotInterfereWithSingleton() {
3535
// record singleton baseline
3636
FeatureProvider singletonProvider = singleton.getProvider();
3737

38-
OpenFeatureAPI isolated = OpenFeatureAPIFactory.createAPI();
38+
OpenFeatureAPI isolated = new OpenFeatureAPI();
3939
assertThat(isolated).isNotSameAs(singleton);
4040

4141
// mutate only the isolated instance
@@ -56,7 +56,7 @@ void isolatedInstanceDoesNotInterfereWithSingleton() {
5656
@Test
5757
@DisplayName("singleton does not interfere with isolated instance")
5858
void singletonDoesNotInterfereWithIsolatedInstance() {
59-
OpenFeatureAPI isolated = OpenFeatureAPIFactory.createAPI();
59+
OpenFeatureAPI isolated = new OpenFeatureAPI();
6060

6161
// record isolated baseline
6262
FeatureProvider isolatedProvider = isolated.getProvider();

src/test/java/dev/openfeature/sdk/isolated/IsolatedAPITest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class IsolatedAPITest {
3030
@Test
3131
@DisplayName("factory creates distinct API instances")
3232
void factoryCreatesDistinctInstances() {
33-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
34-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
33+
OpenFeatureAPI api1 = new OpenFeatureAPI();
34+
OpenFeatureAPI api2 = new OpenFeatureAPI();
3535

3636
assertThat(api1).isInstanceOf(OpenFeatureAPI.class).isNotSameAs(api2);
3737
}
@@ -42,8 +42,8 @@ void factoryCreatesDistinctInstances() {
4242
@Test
4343
@DisplayName("providers are isolated between instances")
4444
void providerIsolation() {
45-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
46-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
45+
OpenFeatureAPI api1 = new OpenFeatureAPI();
46+
OpenFeatureAPI api2 = new OpenFeatureAPI();
4747

4848
InMemoryProvider provider = new InMemoryProvider(Map.of());
4949
api1.setProvider(provider);
@@ -58,8 +58,8 @@ void providerIsolation() {
5858
@Test
5959
@DisplayName("hooks are isolated between instances")
6060
void hookIsolation() {
61-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
62-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
61+
OpenFeatureAPI api1 = new OpenFeatureAPI();
62+
OpenFeatureAPI api2 = new OpenFeatureAPI();
6363

6464
api1.addHooks(new NoOpHook());
6565

@@ -73,8 +73,8 @@ void hookIsolation() {
7373
@Test
7474
@DisplayName("evaluation context is isolated between instances")
7575
void evaluationContextIsolation() {
76-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
77-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
76+
OpenFeatureAPI api1 = new OpenFeatureAPI();
77+
OpenFeatureAPI api2 = new OpenFeatureAPI();
7878

7979
api1.setEvaluationContext(new ImmutableContext("key-1"));
8080
api2.setEvaluationContext(new ImmutableContext("key-2"));
@@ -90,8 +90,8 @@ void evaluationContextIsolation() {
9090
@Timeout(value = 2, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
9191
@DisplayName("event handlers are isolated between instances")
9292
void eventHandlerIsolation() throws Exception {
93-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
94-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
93+
OpenFeatureAPI api1 = new OpenFeatureAPI();
94+
OpenFeatureAPI api2 = new OpenFeatureAPI();
9595

9696
CountDownLatch api1HandlerLatch = new CountDownLatch(1);
9797
AtomicBoolean api2HandlerCalled = new AtomicBoolean(false);
@@ -119,8 +119,8 @@ void eventHandlerIsolation() throws Exception {
119119
@Test
120120
@DisplayName("transaction context propagator is isolated between instances")
121121
void transactionContextPropagatorIsolation() {
122-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
123-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
122+
OpenFeatureAPI api1 = new OpenFeatureAPI();
123+
OpenFeatureAPI api2 = new OpenFeatureAPI();
124124

125125
ThreadLocalTransactionContextPropagator propagator = new ThreadLocalTransactionContextPropagator();
126126
api1.setTransactionContextPropagator(propagator);
@@ -136,7 +136,7 @@ void transactionContextPropagatorIsolation() {
136136
@Test
137137
@DisplayName("isolated instance conforms to API contract")
138138
void isolatedInstanceConformsToAPIContract() throws Exception {
139-
OpenFeatureAPI api = OpenFeatureAPIFactory.createAPI();
139+
OpenFeatureAPI api = new OpenFeatureAPI();
140140

141141
// provider management
142142
InMemoryProvider provider = new InMemoryProvider(Map.of(
@@ -171,8 +171,8 @@ void isolatedInstanceConformsToAPIContract() throws Exception {
171171
@Test
172172
@DisplayName("clearHooks does not affect other instances")
173173
void clearHooksDoesNotAffectOtherInstances() {
174-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
175-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
174+
OpenFeatureAPI api1 = new OpenFeatureAPI();
175+
OpenFeatureAPI api2 = new OpenFeatureAPI();
176176

177177
NoOpHook hook = new NoOpHook();
178178
api1.addHooks(hook);
@@ -191,8 +191,8 @@ void clearHooksDoesNotAffectOtherInstances() {
191191
@Test
192192
@DisplayName("clients use their own instance's provider")
193193
void clientUsesItsOwnInstanceProvider() throws Exception {
194-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
195-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
194+
OpenFeatureAPI api1 = new OpenFeatureAPI();
195+
OpenFeatureAPI api2 = new OpenFeatureAPI();
196196

197197
api1.setProviderAndWait(new InMemoryProvider(Map.of(
198198
"flag1",
@@ -220,8 +220,8 @@ void warnWhenProviderBoundToMultipleInstances() {
220220
Logger mockLogger = Mockito.mock(Logger.class);
221221
LoggerMock.setMock(OpenFeatureAPI.class, mockLogger);
222222
try {
223-
OpenFeatureAPI api1 = OpenFeatureAPIFactory.createAPI();
224-
OpenFeatureAPI api2 = OpenFeatureAPIFactory.createAPI();
223+
OpenFeatureAPI api1 = new OpenFeatureAPI();
224+
OpenFeatureAPI api2 = new OpenFeatureAPI();
225225

226226
NoOpProvider provider = new NoOpProvider();
227227
api1.setProvider(provider);

0 commit comments

Comments
 (0)