|
1 | 1 | package dev.openfeature.contrib.providers.flagd;
|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
5 | 6 | import static org.mockito.ArgumentMatchers.any;
|
6 | 7 | import static org.mockito.ArgumentMatchers.anyInt;
|
@@ -375,6 +376,36 @@ void context_is_parsed_and_passed_to_grpc_service() {
|
375 | 376 | assertEquals(DEFAULT.toString(), booleanDetails.getReason());
|
376 | 377 | }
|
377 | 378 |
|
| 379 | + @Test |
| 380 | + // Validates null handling - https://github.com/open-feature/java-sdk-contrib/issues/258 |
| 381 | + void null_context_handling(){ |
| 382 | + // given |
| 383 | + final String flagA = "flagA"; |
| 384 | + final boolean defaultVariant = false; |
| 385 | + final boolean expectedVariant = true; |
| 386 | + |
| 387 | + final MutableContext context = new MutableContext(); |
| 388 | + context.add("key", (String) null); |
| 389 | + |
| 390 | + final ServiceBlockingStub serviceBlockingStubMock = mock(ServiceBlockingStub.class); |
| 391 | + final ServiceStub serviceStubMock = mock(ServiceStub.class); |
| 392 | + |
| 393 | + // when |
| 394 | + when(serviceBlockingStubMock.withDeadlineAfter(anyLong(), any(TimeUnit.class))) |
| 395 | + .thenReturn(serviceBlockingStubMock); |
| 396 | + when(serviceBlockingStubMock.resolveBoolean(any())) |
| 397 | + .thenReturn(ResolveBooleanResponse.newBuilder().setValue(expectedVariant).build()); |
| 398 | + |
| 399 | + OpenFeatureAPI.getInstance() |
| 400 | + .setProvider(new FlagdProvider(serviceBlockingStubMock, serviceStubMock, "lru", 10, 1)); |
| 401 | + |
| 402 | + // then |
| 403 | + final Boolean evaluation = api.getClient().getBooleanValue(flagA, defaultVariant, context); |
| 404 | + |
| 405 | + assertNotEquals(evaluation, defaultVariant); |
| 406 | + assertEquals(evaluation, expectedVariant); |
| 407 | + } |
| 408 | + |
378 | 409 | @Test
|
379 | 410 | void set_deadline_deadline_send_in_grpc() {
|
380 | 411 | long deadline = 1300;
|
|
0 commit comments