Skip to content

Commit

Permalink
fix some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hoefgen committed Oct 27, 2023
1 parent 836ffe3 commit 0c6534f
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,20 @@ public void testCreateUserOnlyUserId() {
Map<String, Value> apiAttrs = new LinkedHashMap();
apiAttrs.put("user_id", new Value("test-6789"));

// ensure fallback to user_id when target key is null
ctx = new ImmutableContext(null, apiAttrs);
user = DevCycleUser.fromEvaluationContext(ctx);
Assert.assertEquals(user.getUserId(), "test-6789");

// ensure fallback to user_id when target key is empty
ctx = new ImmutableContext("", apiAttrs);
user = DevCycleUser.fromEvaluationContext(ctx);
Assert.assertEquals(user.getUserId(), "test-6789");

// ensure target key takes precedence over user_id
ctx = new ImmutableContext("user-4567", apiAttrs);
user = DevCycleUser.fromEvaluationContext(ctx);
Assert.assertEquals(user.getUserId(), "user-4567");
}

@Test
Expand Down Expand Up @@ -137,18 +148,18 @@ public void testSetCustomValueBadData() {
list.add("two");
list.add("three");

Assert.assertThrows(IllegalArgumentException.class, () -> {
DevCycleUser.setCustomValue(customData, "test", new Value(list));
});
customData = new HashMap();
DevCycleUser.setCustomValue(customData, "test", new Value(list));
Assert.assertEquals(customData.size(), 0);

Map map = new HashMap();
map.put("p1", "one");
map.put("p2", "two");
map.put("p3", "three");

Assert.assertThrows(IllegalArgumentException.class, () -> {
DevCycleUser.setCustomValue(customData, "test", new Value(Structure.mapToStructure(map)));
});
customData = new HashMap();
DevCycleUser.setCustomValue(customData, "test", new Value(Structure.mapToStructure(map)));
Assert.assertEquals(customData.size(), 0);
}

@Test
Expand Down

0 comments on commit 0c6534f

Please sign in to comment.