Skip to content

Commit 74e5a50

Browse files
committed
Fix test
1 parent c7beb5a commit 74e5a50

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

splitio_android/android/src/main/java/io/split/splitio/SplitMethodParserImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ private static void invokeCallback(MethodChannel methodChannel, String matchingK
422422
private static Map<String, Map<String, String>> mapToSplitResults(Map<String, SplitResult> treatmentsWithConfig) {
423423
Map<String, Map<String, String>> resultMap = new HashMap<>();
424424

425+
if (treatmentsWithConfig == null) {
426+
return resultMap;
427+
}
428+
425429
for (Map.Entry<String, SplitResult> entry : treatmentsWithConfig.entrySet()) {
426430
resultMap.put(entry.getKey(), getSplitResultMap(entry.getValue()));
427431
}

splitio_android/android/src/test/java/io/split/splitio/SplitMethodParserImplTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,17 +553,20 @@ public void getTreatmentsWithConfigByFlagSetWorksCorrectly() {
553553
map.put("flagSet", "set_1");
554554
map.put("attributes", Collections.singletonMap("age", 10));
555555

556+
Map<String, String> resultMap1 = new HashMap<>();
557+
resultMap1.put("treatment", "on");
558+
resultMap1.put("config", "{config}");
559+
556560
when(mArgumentParser.getStringArgument("matchingKey", map)).thenReturn("user-key");
557561
when(mArgumentParser.getStringArgument("bucketingKey", map)).thenReturn("bucketing-key");
558562
when(mArgumentParser.getStringArgument("flagSet", map)).thenReturn("set_1");
559563
when(mArgumentParser.getMapArgument("attributes", map)).thenReturn(Collections.singletonMap("age", 10));
560-
SplitResult splitResult = new SplitResult("on", "{config}");
561-
when(mSplitWrapper.getTreatmentsWithConfigByFlagSet(any(), any(), any(), any())).thenReturn(Collections.singletonMap("flag_1", splitResult));
564+
when(mSplitWrapper.getTreatmentsWithConfigByFlagSet(any(), any(), any(), any())).thenReturn(Collections.singletonMap("flag_1", new SplitResult("on", "{config}")));
562565

563566
mMethodParser.onMethodCall("getTreatmentsWithConfigByFlagSet", map, mResult);
564567

565568
verify(mSplitWrapper).getTreatmentsWithConfigByFlagSet("user-key", "bucketing-key", "set_1", Collections.singletonMap("age", 10));
566-
verify(mResult).success(Collections.singletonMap("flag_1", splitResult));
569+
verify(mResult).success(Collections.singletonMap("flag_1", resultMap1));
567570
}
568571

569572
@Test
@@ -574,16 +577,19 @@ public void getTreatmentsWithConfigByFlagSetsWorksCorrectly() {
574577
map.put("flagSets", Arrays.asList("set_1", "set_2"));
575578
map.put("attributes", Collections.singletonMap("age", 10));
576579

580+
Map<String, String> resultMap1 = new HashMap<>();
581+
resultMap1.put("treatment", "on");
582+
resultMap1.put("config", "{config}");
583+
577584
when(mArgumentParser.getStringArgument("matchingKey", map)).thenReturn("user-key");
578585
when(mArgumentParser.getStringArgument("bucketingKey", map)).thenReturn("bucketing-key");
579586
when(mArgumentParser.getStringListArgument("flagSets", map)).thenReturn(Arrays.asList("set_1", "set_2"));
580587
when(mArgumentParser.getMapArgument("attributes", map)).thenReturn(Collections.singletonMap("age", 10));
581-
SplitResult splitResult = new SplitResult("on", "{config}");
582-
when(mSplitWrapper.getTreatmentsWithConfigByFlagSets(any(), any(), any(), any())).thenReturn(Collections.singletonMap("flag_1", splitResult));
588+
when(mSplitWrapper.getTreatmentsWithConfigByFlagSets(any(), any(), any(), any())).thenReturn(Collections.singletonMap("flag_1", new SplitResult("on", "{config}")));
583589

584590
mMethodParser.onMethodCall("getTreatmentsWithConfigByFlagSets", map, mResult);
585591

586592
verify(mSplitWrapper).getTreatmentsWithConfigByFlagSets("user-key", "bucketing-key", Arrays.asList("set_1", "set_2"), Collections.singletonMap("age", 10));
587-
verify(mResult).success(Collections.singletonMap("flag_1", splitResult));
593+
verify(mResult).success(Collections.singletonMap("flag_1", resultMap1));
588594
}
589595
}

0 commit comments

Comments
 (0)