|
1 | 1 | package dev.openfeature.sdk; |
2 | 2 |
|
| 3 | +import com.google.common.collect.ImmutableMap; |
3 | 4 | import com.google.common.collect.Maps; |
4 | 5 | import dev.openfeature.sdk.fixtures.ProviderFixture; |
5 | 6 | import dev.openfeature.sdk.testutils.FeatureProviderTestUtils; |
@@ -137,21 +138,50 @@ void noopProvider() { |
137 | 138 | @Test |
138 | 139 | void eventDetails() { |
139 | 140 | assertEquals(0f, new MutableTrackingEventDetails().getValue()); |
| 141 | + assertEquals(0f, new ImmutableTrackingEventDetails().getValue()); |
140 | 142 | assertEquals(9.87f, new MutableTrackingEventDetails(9.87f).getValue()); |
| 143 | + assertEquals(9.87f, new ImmutableTrackingEventDetails(9.87f).getValue()); |
| 144 | + |
| 145 | + |
| 146 | + // using mutable tracking event details |
141 | 147 | Map<String, Value> expectedMap = Maps.newHashMap(); |
142 | 148 | expectedMap.put("my-str", new Value("str")); |
143 | 149 | expectedMap.put("my-num", new Value(1)); |
144 | 150 | expectedMap.put("my-bool", new Value(true)); |
145 | 151 | expectedMap.put("my-struct", new Value(new MutableTrackingEventDetails())); |
146 | 152 |
|
147 | | - |
148 | 153 | MutableStructure details = new MutableTrackingEventDetails() |
149 | 154 | .add("my-str", new Value("str")) |
150 | 155 | .add("my-num", new Value(1)) |
151 | 156 | .add("my-bool", new Value(true)) |
152 | 157 | .add("my-struct", new Value(new MutableTrackingEventDetails())); |
153 | 158 |
|
154 | 159 | assertEquals(expectedMap, details.asMap()); |
| 160 | + assertThatCode(() -> OpenFeatureAPI.getInstance().getClient(). |
| 161 | + track( |
| 162 | + "tracking-event-name", |
| 163 | + new ImmutableContext(), |
| 164 | + new MutableTrackingEventDetails())) |
| 165 | + .doesNotThrowAnyException(); |
| 166 | + |
| 167 | + |
| 168 | + // using immutable tracking event details |
| 169 | + ImmutableMap<String, Value> expectedImmutable = ImmutableMap.of("my-str", new Value("str"), |
| 170 | + "my-num", new Value(1), |
| 171 | + "my-bool", new Value(true), |
| 172 | + "my-struct", new Value(new ImmutableStructure()) |
| 173 | + ); |
| 174 | + |
| 175 | + ImmutableTrackingEventDetails immutableDetails = new ImmutableTrackingEventDetails(2, expectedMap); |
| 176 | + assertEquals(expectedImmutable, immutableDetails.asMap()); |
| 177 | + assertThatCode(() -> OpenFeatureAPI.getInstance().getClient(). |
| 178 | + track( |
| 179 | + "tracking-event-name", |
| 180 | + new ImmutableContext(), |
| 181 | + new ImmutableTrackingEventDetails())) |
| 182 | + .doesNotThrowAnyException(); |
| 183 | + |
| 184 | + |
155 | 185 | } |
156 | 186 |
|
157 | 187 | } |
0 commit comments