Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit ae3696a

Browse files
committed
add another unit test
1 parent 3063cd2 commit ae3696a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/test/java/com/launchdarkly/client/FeatureFlagTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.launchdarkly.client;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonArray;
5+
import com.google.gson.JsonElement;
6+
import com.google.gson.JsonObject;
7+
8+
import org.junit.Assert;
39
import org.junit.Before;
410
import org.junit.Test;
511

@@ -13,6 +19,7 @@
1319
import static com.launchdarkly.client.VersionedDataKind.FEATURES;
1420
import static com.launchdarkly.client.VersionedDataKind.SEGMENTS;
1521
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertNotNull;
1623
import static org.junit.Assert.assertNull;
1724

1825
public class FeatureFlagTest {
@@ -243,9 +250,23 @@ public void clauseCanBeNegated() throws Exception {
243250
assertEquals(jbool(false), f.evaluate(user, featureStore).getValue());
244251
}
245252

253+
@Test
254+
public void clauseWithUnsupportedOperatorStringIsUnmarshalledWithNullOperator() throws Exception {
255+
// This just verifies that GSON will give us a null in this case instead of throwing an exception,
256+
// so we fail as gracefully as possible if a new operator type has been added in the application
257+
// and the SDK hasn't been upgraded yet.
258+
String badClauseJson = "{\"attribute\":\"name\",\"operator\":\"doesSomethingUnsupported\",\"values\":[\"x\"]}";
259+
Gson gson = new Gson();
260+
Clause clause = gson.fromJson(badClauseJson, Clause.class);
261+
assertNotNull(clause);
262+
263+
JsonElement json = gson.toJsonTree(clause);
264+
String expectedJson = "{\"attribute\":\"name\",\"values\":[\"x\"],\"negate\":false}";
265+
assertEquals(gson.fromJson(expectedJson, JsonElement.class), json);
266+
}
267+
246268
@Test
247269
public void clauseWithNullOperatorDoesNotMatch() throws Exception {
248-
// Operator will be null if it failed to be unmarshaled from JSON, i.e. it's not a supported enum value
249270
Clause badClause = new Clause("name", null, Arrays.asList(js("Bob")), false);
250271
FeatureFlag f = booleanFlagWithClauses(badClause);
251272
LDUser user = new LDUser.Builder("key").name("Bob").build();

0 commit comments

Comments
 (0)