|
7 | 7 | import com.google.gson.JsonArray; |
8 | 8 | import com.google.gson.JsonElement; |
9 | 9 | import com.google.gson.JsonObject; |
| 10 | +import com.google.gson.JsonPrimitive; |
10 | 11 | import com.google.gson.reflect.TypeToken; |
11 | 12 | import com.launchdarkly.client.value.LDValue; |
12 | 13 |
|
|
29 | 30 | import static org.junit.Assert.assertEquals; |
30 | 31 | import static org.junit.Assert.assertNotNull; |
31 | 32 | import static org.junit.Assert.assertNull; |
| 33 | +import static org.junit.Assert.assertTrue; |
32 | 34 |
|
33 | 35 | @SuppressWarnings("javadoc") |
34 | 36 | public class LDUserTest { |
@@ -344,8 +346,14 @@ private Map<LDUser, String> getUserPropertiesJsonMap() { |
344 | 346 | @Test |
345 | 347 | public void defaultJsonEncodingHasPrivateAttributeNames() { |
346 | 348 | LDUser user = new LDUser.Builder("userkey").privateName("x").privateEmail("y").build(); |
347 | | - String expected = "{\"key\":\"userkey\",\"name\":\"x\",\"email\":\"y\",\"privateAttributeNames\":[\"name\",\"email\"]}"; |
348 | | - assertEquals(defaultGson.fromJson(expected, JsonElement.class), defaultGson.toJsonTree(user)); |
| 349 | + JsonObject serialized = defaultGson.toJsonTree(user).getAsJsonObject(); |
| 350 | + assertEquals(serialized.get("key").getAsJsonPrimitive().getAsString(), "userkey"); |
| 351 | + assertEquals(serialized.get("name").getAsJsonPrimitive().getAsString(), "x"); |
| 352 | + assertEquals(serialized.get("email").getAsJsonPrimitive().getAsString(), "y"); |
| 353 | + JsonArray privateAttrs = serialized.get("privateAttributeNames").getAsJsonArray(); |
| 354 | + assertEquals(privateAttrs.size(), 2); |
| 355 | + assertTrue(privateAttrs.contains(new JsonPrimitive("name"))); |
| 356 | + assertTrue(privateAttrs.contains(new JsonPrimitive("email"))); |
349 | 357 | } |
350 | 358 |
|
351 | 359 | @Test |
|
0 commit comments