|
4 | 4 | import com.google.gson.JsonElement; |
5 | 5 | import com.google.gson.JsonPrimitive; |
6 | 6 | import com.google.gson.reflect.TypeToken; |
| 7 | + |
| 8 | +import org.junit.Assert; |
7 | 9 | import org.junit.Test; |
8 | 10 |
|
9 | 11 | import java.lang.reflect.Type; |
@@ -198,6 +200,38 @@ public void testLDUserCustomMarshalWithBuiltInAttributesRedactsCorrectAttrs() { |
198 | 200 | Type type = new TypeToken<Map<String, JsonElement>>(){}.getType(); |
199 | 201 | Map<String, JsonElement> privateJson = config.gson.fromJson(config.gson.toJson(user), type); |
200 | 202 | assertNull(privateJson.get("email")); |
201 | | - |
| 203 | + } |
| 204 | + |
| 205 | + @Test |
| 206 | + public void getValueGetsBuiltInAttribute() { |
| 207 | + LDUser user = new LDUser.Builder("key") |
| 208 | + .name("Jane") |
| 209 | + .build(); |
| 210 | + assertEquals(new JsonPrimitive("Jane"), user.getValueForEvaluation("name")); |
| 211 | + } |
| 212 | + |
| 213 | + @Test |
| 214 | + public void getValueGetsCustomAttribute() { |
| 215 | + LDUser user = new LDUser.Builder("key") |
| 216 | + .custom("height", 5) |
| 217 | + .build(); |
| 218 | + assertEquals(new JsonPrimitive(5), user.getValueForEvaluation("height")); |
| 219 | + } |
| 220 | + |
| 221 | + @Test |
| 222 | + public void getValueGetsBuiltInAttributeEvenIfCustomAttrHasSameName() { |
| 223 | + LDUser user = new LDUser.Builder("key") |
| 224 | + .name("Jane") |
| 225 | + .custom("name", "Joan") |
| 226 | + .build(); |
| 227 | + assertEquals(new JsonPrimitive("Jane"), user.getValueForEvaluation("name")); |
| 228 | + } |
| 229 | + |
| 230 | + @Test |
| 231 | + public void getValueReturnsNullIfNotFound() { |
| 232 | + LDUser user = new LDUser.Builder("key") |
| 233 | + .name("Jane") |
| 234 | + .build(); |
| 235 | + assertNull(user.getValueForEvaluation("height")); |
202 | 236 | } |
203 | 237 | } |
0 commit comments