Skip to content

Commit

Permalink
Add tests for OptiBPWidgetFactory:getValueResult
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku committed Sep 12, 2023
1 parent 04c125e commit fd5b2a1
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -564,14 +566,15 @@ public void testSetUpOptiBpActivityResultListenerReturnsResultOK() {
factory.setUpOptiBpActivityResultListener(widgetArgs, requestCode, rootLayout, systolicBp, diastolicBp);
ArgumentCaptor<OnActivityResultListener> 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" +
Expand Down Expand Up @@ -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);
}
}

0 comments on commit fd5b2a1

Please sign in to comment.