|
20 | 20 | import com.flagsmith.exceptions.FlagsmithClientError; |
21 | 21 | import com.flagsmith.exceptions.FlagsmithRuntimeError; |
22 | 22 | import com.flagsmith.flagengine.EvaluationContext; |
| 23 | +import com.flagsmith.flagengine.EvaluationResult; |
23 | 24 | import com.flagsmith.interfaces.FlagsmithCache; |
24 | 25 | import com.flagsmith.models.BaseFlag; |
25 | 26 | import com.flagsmith.models.DefaultFlag; |
|
47 | 48 | import okhttp3.ResponseBody; |
48 | 49 | import okhttp3.mock.MockInterceptor; |
49 | 50 | import okio.Buffer; |
| 51 | +import com.flagsmith.flagengine.Engine; |
50 | 52 | import org.junit.jupiter.api.Test; |
51 | 53 | import org.junit.jupiter.params.ParameterizedTest; |
52 | 54 | import org.junit.jupiter.params.provider.Arguments; |
53 | 55 | import org.junit.jupiter.params.provider.MethodSource; |
54 | 56 | import org.mockito.ArgumentCaptor; |
| 57 | +import org.mockito.MockedStatic; |
55 | 58 | import org.mockito.Mockito; |
56 | 59 | import org.mockito.invocation.Invocation; |
57 | 60 | import org.slf4j.Logger; |
@@ -776,6 +779,49 @@ public void testLocalEvaluation_ReturnsIdentityOverrides() throws FlagsmithClien |
776 | 779 | assertEquals(flagsWithOverride.getFeatureValue("some_feature"), "overridden-value"); |
777 | 780 | } |
778 | 781 |
|
| 782 | + @Test |
| 783 | + public void testLocalEvaluation_getEnvironmentFlags_NoTargeting() throws FlagsmithClientError { |
| 784 | + // Given |
| 785 | + EvaluationContext evaluationContext = FlagsmithTestHelper.evaluationContext(); |
| 786 | + EvaluationResult evaluationResult = Engine.getEvaluationResult( |
| 787 | + new EvaluationContext(evaluationContext) |
| 788 | + .withSegments(null) |
| 789 | + ); |
| 790 | + |
| 791 | + FlagsmithConfig config = FlagsmithConfig.newBuilder().withLocalEvaluation(true).build(); |
| 792 | + |
| 793 | + FlagsmithApiWrapper mockedApiWrapper = mock(FlagsmithApiWrapper.class); |
| 794 | + when(mockedApiWrapper.getEvaluationContext()) |
| 795 | + .thenReturn(evaluationContext); |
| 796 | + when(mockedApiWrapper.getConfig()).thenReturn(config); |
| 797 | + |
| 798 | + FlagsmithClient client = FlagsmithClient.newBuilder() |
| 799 | + .withFlagsmithApiWrapper(mockedApiWrapper) |
| 800 | + .withConfiguration(config) |
| 801 | + .setApiKey("ser.dummy-key") |
| 802 | + .build(); |
| 803 | + |
| 804 | + // When |
| 805 | + try (MockedStatic<Engine> mockedEngine = mockStatic(Engine.class)) { |
| 806 | + mockedEngine.when( |
| 807 | + () -> Engine.getEvaluationResult( |
| 808 | + new EvaluationContext(evaluationContext) |
| 809 | + .withSegments(null) |
| 810 | + ) |
| 811 | + ).thenReturn(evaluationResult); |
| 812 | + |
| 813 | + client.getEnvironmentFlags(); |
| 814 | + |
| 815 | + // Then |
| 816 | + mockedEngine.verify( |
| 817 | + () -> Engine.getEvaluationResult( |
| 818 | + new EvaluationContext(evaluationContext) |
| 819 | + .withSegments(null) |
| 820 | + ) |
| 821 | + ); |
| 822 | + } |
| 823 | + } |
| 824 | + |
779 | 825 | @Test |
780 | 826 | public void testGetEnvironmentFlags_UsesDefaultFlags_IfLocalEvaluationEnvironmentNull() |
781 | 827 | throws FlagsmithClientError { |
|
0 commit comments