Skip to content

Commit

Permalink
fixup: await verify
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
  • Loading branch information
toddbaert committed Aug 22, 2024
1 parent 69f3976 commit cf4be29
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.openfeature.sdk.EventDetails;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;
import dev.openfeature.sdk.ProviderState;
import dev.openfeature.sdk.Value;
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
Expand All @@ -27,6 +28,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
Expand All @@ -45,15 +47,16 @@ class InMemoryProviderTest {
void beforeEach() {
Map<String, Flag<?>> flags = buildFlags();
provider = spy(new InMemoryProvider(flags));
OpenFeatureAPI.getInstance().onProviderConfigurationChanged(eventDetails -> {});
OpenFeatureAPI.getInstance().onProviderConfigurationChanged(eventDetails -> {
});
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
client = OpenFeatureAPI.getInstance().getClient();
provider.updateFlags(flags);
provider.updateFlag("addedFlag", Flag.builder()
.variant("on", true)
.variant("off", false)
.defaultVariant("on")
.build());
.variant("on", true)
.variant("off", false)
.defaultVariant("on")
.build());
}

@SneakyThrows
Expand Down Expand Up @@ -85,10 +88,9 @@ void getDoubleEvaluation() {
@Test
void getObjectEvaluation() {
Value expectedObject = new Value(mapToStructure(ImmutableMap.of(
"showImages", new Value(true),
"title", new Value("Check out these pics!"),
"imagesPerPage", new Value(100)
)));
"showImages", new Value(true),
"title", new Value("Check out these pics!"),
"imagesPerPage", new Value(100))));
assertEquals(expectedObject, client.getObjectValue("object-flag", new Value(true)));
}

Expand All @@ -112,7 +114,8 @@ void shouldThrowIfNotInitialized() {
InMemoryProvider inMemoryProvider = new InMemoryProvider(new HashMap<>());

// ErrorCode.PROVIDER_NOT_READY should be returned when evaluated via the client
assertThrows(ProviderNotReadyError.class, ()-> inMemoryProvider.getBooleanEvaluation("fail_not_initialized", false, new ImmutableContext()));
assertThrows(ProviderNotReadyError.class,
() -> inMemoryProvider.getBooleanEvaluation("fail_not_initialized", false, new ImmutableContext()));
}

@SuppressWarnings("unchecked")
Expand All @@ -126,8 +129,8 @@ void emitChangedFlagsOnlyIfThereAreChangedFlags() {

provider.updateFlags(flags);

verify(handler, times(1))
.accept(argThat(details -> details.getFlagsChanged().isEmpty()));
await().untilAsserted(() -> verify(handler, times(1))
.accept(argThat(details -> details.getFlagsChanged().isEmpty())));
}

@Test
Expand Down

0 comments on commit cf4be29

Please sign in to comment.