|
1 | 1 | package dev.openfeature.sdk; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
3 | 6 | import static org.mockito.Mockito.*; |
4 | 7 |
|
5 | 8 | import dev.openfeature.sdk.fixtures.ProviderFixture; |
@@ -131,16 +134,32 @@ void mustShutdownAllProvidersOnShuttingDownApi() { |
131 | 134 | } |
132 | 135 |
|
133 | 136 | @Test |
134 | | - @DisplayName("once shutdown is complete, api must be ready to use again") |
135 | | - void apiIsReadyToUseAfterShutdown() { |
| 137 | + @Specification( |
| 138 | + number = "1.6.2", |
| 139 | + text = |
| 140 | + "The API's `shutdown` function MUST reset all state of the API, removing all hooks, event handlers, evaluation context, transaction context propagators, and providers.") |
| 141 | + @DisplayName("shutdown must reset the state of the API") |
| 142 | + void apiStateMustBeResetOnShuttingDownApi() { |
136 | 143 |
|
137 | | - NoOpProvider p1 = new NoOpProvider(); |
138 | | - api.setProvider(p1); |
| 144 | + FeatureProvider provider = ProviderFixture.createMockedProvider(); |
| 145 | + TransactionContextPropagator transactionContextPropagator = mock(TransactionContextPropagator.class); |
| 146 | + EvaluationContext evaluationContext = mock(EvaluationContext.class); |
| 147 | + |
| 148 | + api.addHooks(mock(Hook.class)); |
| 149 | + api.setProvider(provider); |
| 150 | + api.setEvaluationContext(evaluationContext); |
| 151 | + api.setTransactionContextPropagator(transactionContextPropagator); |
139 | 152 |
|
140 | 153 | api.shutdown(); |
141 | 154 |
|
142 | | - NoOpProvider p2 = new NoOpProvider(); |
143 | | - api.setProvider(p2); |
| 155 | + assertNotEquals(provider, api.getProvider()); |
| 156 | + assertTrue(api.getHooks().isEmpty()); |
| 157 | + assertNotEquals(evaluationContext, api.getEvaluationContext()); |
| 158 | + assertNotEquals(transactionContextPropagator, api.getTransactionContextPropagator()); |
| 159 | + |
| 160 | + assertInstanceOf(NoOpProvider.class, api.getProvider()); |
| 161 | + assertInstanceOf(ImmutableContext.class, api.getEvaluationContext()); |
| 162 | + assertInstanceOf(NoOpTransactionContextPropagator.class, api.getTransactionContextPropagator()); |
144 | 163 | } |
145 | 164 |
|
146 | 165 | @Test |
|
0 commit comments