diff --git a/opensrp-chw-anc/src/main/java/org/smartregister/chw/anc/util/NCUtils.java b/opensrp-chw-anc/src/main/java/org/smartregister/chw/anc/util/NCUtils.java index ec5f1ec9..33a4aa4c 100644 --- a/opensrp-chw-anc/src/main/java/org/smartregister/chw/anc/util/NCUtils.java +++ b/opensrp-chw-anc/src/main/java/org/smartregister/chw/anc/util/NCUtils.java @@ -644,9 +644,9 @@ public static String toCSV(List list) { if (list.size() > 0) { StringBuilder sb = new StringBuilder(); for (String s : list) { - sb.append(s).append(","); + sb.append(s).append(", "); } - result = sb.deleteCharAt(sb.length() - 1).toString(); + result = sb.deleteCharAt(sb.length() - 2).toString(); } return result; } diff --git a/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/NCUtilsTest.java b/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/NCUtilsTest.java new file mode 100644 index 00000000..0f59b203 --- /dev/null +++ b/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/NCUtilsTest.java @@ -0,0 +1,47 @@ +package org.smartregister.chw.anc.util; + +import org.junit.Assert; +import org.junit.Test; +import org.smartregister.chw.anc.domain.VisitDetail; + +import java.util.ArrayList; +import java.util.List; + +public class NCUtilsTest { + + @Test + public void testGetText() { + List details = new ArrayList<>(); + + VisitDetail visitDetail1 = new VisitDetail(); + visitDetail1.setHumanReadable("test1"); + details.add(visitDetail1); + + VisitDetail visitDetail2 = new VisitDetail(); + visitDetail2.setHumanReadable("test2"); + details.add(visitDetail2); + + VisitDetail visitDetail3 = new VisitDetail(); + details.add(visitDetail3); + + details.add(null); + + String val = NCUtils.getText(details).trim(); + String expected = "test1, test2"; + + Assert.assertEquals(expected, val); + } + + @Test + public void testGetTextOneParam() { + + VisitDetail visitDetail1 = new VisitDetail(); + visitDetail1.setHumanReadable("test1"); + + String val = NCUtils.getText(visitDetail1).trim(); + String expected = "test1"; + + Assert.assertEquals(expected, val); + } + +} diff --git a/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/VisitNCUtilsTest.java b/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/VisitUtilsTest.java similarity index 99% rename from opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/VisitNCUtilsTest.java rename to opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/VisitUtilsTest.java index b89d11ac..5ee3c2d1 100644 --- a/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/VisitNCUtilsTest.java +++ b/opensrp-chw-anc/src/test/java/org/smartregister/chw/anc/util/VisitUtilsTest.java @@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue; @PrepareForTest({AncLibrary.class, JsonFormUtils.class, ImmunizationLibrary.class}) -public class VisitNCUtilsTest { +public class VisitUtilsTest { @Rule public PowerMockRule rule = new PowerMockRule();