From 33437e8bf789b5ecb7bd6fd9924eb137efbca0a9 Mon Sep 17 00:00:00 2001 From: vend Date: Mon, 29 May 2023 19:31:31 +0500 Subject: [PATCH] updated test --- .../org/smartregister/util/FormUtilsTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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")); + } }