From fd5b2a181e806ac2a9dd5d0d22a1a7b883192a41 Mon Sep 17 00:00:00 2001 From: SebaMutuku Date: Tue, 12 Sep 2023 11:33:27 +0300 Subject: [PATCH] Add tests for OptiBPWidgetFactory:getValueResult --- .../widgets/OptiBpWidgetFactoryTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/OptiBpWidgetFactoryTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/OptiBpWidgetFactoryTest.java index 5e772301b..ddc50404f 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/OptiBpWidgetFactoryTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/OptiBpWidgetFactoryTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -17,6 +18,7 @@ import com.vijay.jsonwizard.interfaces.OnActivityResultListener; import com.vijay.jsonwizard.utils.FormUtils; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.junit.Assert; @@ -564,14 +566,15 @@ public void testSetUpOptiBpActivityResultListenerReturnsResultOK() { factory.setUpOptiBpActivityResultListener(widgetArgs, requestCode, rootLayout, systolicBp, diastolicBp); ArgumentCaptor resultListenerArgumentCaptor = ArgumentCaptor.forClass(OnActivityResultListener.class); verify(jsonFormActivity).addOnActivityResultListener(anyInt(), resultListenerArgumentCaptor.capture()); - resultListenerArgumentCaptor.getValue().onActivityResult(requestCode,Activity.RESULT_OK,mockIntent); + resultListenerArgumentCaptor.getValue().onActivityResult(requestCode, Activity.RESULT_OK, mockIntent); } + @Test public void testSetUpOptiBpActivityResultListenerShowsToast() { WidgetArgs widgetArgs = Mockito.mock(WidgetArgs.class); when(widgetArgs.getContext()).thenReturn(jsonFormActivity); - String badJson="{\n" + + String badJson = "{\n" + " \"identifier\": [\n" + " {\n" + " \"use\": \"official\",\n" + @@ -664,4 +667,21 @@ public void testSetUpOptiBpActivityResultListenerShowsToast() { assertEquals(Toast.LENGTH_SHORT, toast.getDuration()); } + + @Test + public void testGetValueStringReturnsANonNullResult() throws JSONException { + String result = factory.getValueString(resultJson); + JSONArray jsonArray = new JSONArray(result); + assertNotNull(result); + String comperatives = jsonArray.optJSONObject(0).optString("comperatives"); + assertNotNull(comperatives); + JSONObject object = new JSONArray(comperatives).getJSONObject(0); + assertEquals(180, object.optInt("cuffSystolic")); + assertEquals(85, object.optInt("diastolic")); + } + @Test + public void testGetValueStringReturnsANullResult() throws JSONException { + String result = factory.getValueString(null); + assertNull(result); + } } \ No newline at end of file