diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/DatePickerDialog.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/DatePickerDialog.java index b7b14f1d5..e00d2afdd 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/DatePickerDialog.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/DatePickerDialog.java @@ -6,6 +6,8 @@ import android.content.DialogInterface; import android.os.Bundle; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -27,6 +29,10 @@ public class DatePickerDialog extends DialogFragment { private DatePicker datePicker; + + private Button okButton; + + private Button cancelButton; private android.app.DatePickerDialog.OnDateSetListener onDateSetListener; private DialogInterface.OnShowListener onShowListener; private Date date; @@ -67,9 +73,6 @@ public void setOnShowListener(DialogInterface.OnShowListener onShowListener_) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup dialogView = (ViewGroup) inflater.inflate(R.layout.native_form_dialog_date_picker, container, false); - Button cancelButton; - Button okButton; - setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { @@ -179,4 +182,14 @@ public DatePicker getDatePicker() { public void setNumericDatePicker(boolean numericDatePicker) { isNumericDatePicker = numericDatePicker; } + + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + public Button getOkButton(){ + return okButton; + } + + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + public Button getCancelButton(){ + return cancelButton; + } } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java index fc07e7472..5ceba0e25 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java @@ -1138,28 +1138,30 @@ public JSONArray getSecondaryValues(JSONObject jsonObject, String type) { */ public JSONArray getFormFields(String stepName, Context context) { Activity activity = (Activity) context; - JsonApi jsonApi = (JsonApi) activity; JSONArray fields = new JSONArray(); - JSONObject mJSONObject = jsonApi.getmJSONObject(); - if (mJSONObject != null) { - JSONObject parentJson = jsonApi.getStep(stepName); - try { - if (parentJson.has(JsonFormConstants.SECTIONS) && parentJson - .get(JsonFormConstants.SECTIONS) instanceof JSONArray) { - JSONArray sections = parentJson.getJSONArray(JsonFormConstants.SECTIONS); - for (int i = 0; i < sections.length(); i++) { - JSONObject sectionJson = sections.getJSONObject(i); - if (sectionJson.has(JsonFormConstants.FIELDS)) { - fields = concatArray(fields, sectionJson.getJSONArray(JsonFormConstants.FIELDS)); + if (activity instanceof JsonApi) { + JsonApi jsonApi = (JsonApi) activity; + JSONObject mJSONObject = jsonApi.getmJSONObject(); + if (mJSONObject != null) { + JSONObject parentJson = jsonApi.getStep(stepName); + try { + if (parentJson.has(JsonFormConstants.SECTIONS) && parentJson + .get(JsonFormConstants.SECTIONS) instanceof JSONArray) { + JSONArray sections = parentJson.getJSONArray(JsonFormConstants.SECTIONS); + for (int i = 0; i < sections.length(); i++) { + JSONObject sectionJson = sections.getJSONObject(i); + if (sectionJson.has(JsonFormConstants.FIELDS)) { + fields = concatArray(fields, sectionJson.getJSONArray(JsonFormConstants.FIELDS)); + } } - } - } else if (parentJson.has(JsonFormConstants.FIELDS) && parentJson - .get(JsonFormConstants.FIELDS) instanceof JSONArray) { - fields = parentJson.getJSONArray(JsonFormConstants.FIELDS); + } else if (parentJson.has(JsonFormConstants.FIELDS) && parentJson + .get(JsonFormConstants.FIELDS) instanceof JSONArray) { + fields = parentJson.getJSONArray(JsonFormConstants.FIELDS); + } + } catch (JSONException e) { + Timber.e(e); } - } catch (JSONException e) { - Timber.e(e); } } return fields; diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonWizardFormFragmentPresenterRoboelectricTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonWizardFormFragmentPresenterRoboelectricTest.java index e31a18ad1..6913ebdbd 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonWizardFormFragmentPresenterRoboelectricTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/presenters/JsonWizardFormFragmentPresenterRoboelectricTest.java @@ -48,6 +48,7 @@ import static com.vijay.jsonwizard.presenters.JsonFormFragmentPresenter.RESULT_LOAD_IMG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -182,6 +183,10 @@ public void testOnClickShouldDisplayDatePickerDialog() throws InterruptedExcepti dialogFragment = (DatePickerDialog) fragmentManager.findFragmentByTag(NativeRadioButtonFactory.TAG); } assertNotNull(dialogFragment); + + View okButton = dialogFragment.getOkButton(); + okButton.performClick(); + assertTrue(radioButton.getText().length() > 0); } }