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

Commit d255ded

Browse files
authored
prepare 3.0.2 release (#119)
1 parent 044d314 commit d255ded

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/main/java/com/launchdarkly/client/LDUser.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ public LDUser(String key) {
7171
}
7272

7373
protected JsonElement getValueForEvaluation(String attribute) {
74-
try {
75-
return UserAttribute.valueOf(attribute).get(this);
76-
} catch (IllegalArgumentException expected) {
77-
return getCustom(attribute);
74+
// Don't use Enum.valueOf because we don't want to trigger unnecessary exceptions
75+
for (UserAttribute builtIn: UserAttribute.values()) {
76+
if (builtIn.name().equals(attribute)) {
77+
return builtIn.get(this);
78+
}
7879
}
80+
return getCustom(attribute);
7981
}
8082

8183
JsonPrimitive getKey() {

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.google.gson.JsonElement;
55
import com.google.gson.JsonPrimitive;
66
import com.google.gson.reflect.TypeToken;
7+
8+
import org.junit.Assert;
79
import org.junit.Test;
810

911
import java.lang.reflect.Type;
@@ -198,6 +200,38 @@ public void testLDUserCustomMarshalWithBuiltInAttributesRedactsCorrectAttrs() {
198200
Type type = new TypeToken<Map<String, JsonElement>>(){}.getType();
199201
Map<String, JsonElement> privateJson = config.gson.fromJson(config.gson.toJson(user), type);
200202
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"));
202236
}
203237
}

0 commit comments

Comments
 (0)