diff --git a/opensrp-core/src/test/java/org/smartregister/util/FormUtilsTest.java b/opensrp-core/src/test/java/org/smartregister/util/FormUtilsTest.java index 9882be74a..c5a1d4560 100644 --- a/opensrp-core/src/test/java/org/smartregister/util/FormUtilsTest.java +++ b/opensrp-core/src/test/java/org/smartregister/util/FormUtilsTest.java @@ -36,11 +36,13 @@ import java.io.InputStream; import java.net.URL; import java.util.HashMap; +import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Created by kaderchowdhury on 14/11/17. @@ -339,4 +341,27 @@ public void testRetrieveSubformDefinitionForBindPath() throws Exception { assertNotNull(result); assertEquals("path/to/SubForm1", result.getString("default_bind_path")); } + + @Test + public void testGetSubFormNames() throws Exception { + // Create sample input data + JSONObject formDefinition = new JSONObject(); + JSONObject form = new JSONObject(); + JSONArray subForms = new JSONArray(); + JSONObject subForm1 = new JSONObject(); + subForm1.put("default_bind_path", "path/to/SubForm1"); + JSONObject subForm2 = new JSONObject(); + subForm2.put("default_bind_path", "path/to/SubForm2"); + subForms.put(subForm1); + subForms.put(subForm2); + form.put("sub_forms", subForms); + formDefinition.put("form", form); + + List result = ReflectionHelpers.callInstanceMethod(formUtils, "getSubFormNames" + , ReflectionHelpers.ClassParameter.from(JSONObject.class, formDefinition)); + assertNotNull(result); + assertEquals(2, result.size()); + assertTrue(result.contains("SubForm1")); + assertTrue(result.contains("SubForm2")); + } }