diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java index ad4d459b0..4079ade6b 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java @@ -64,7 +64,7 @@ */ public class NativeRadioButtonFactory implements FormWidgetFactory { - private static final String TAG = NativeRadioButtonFactory.class.getCanonicalName(); + public static final String TAG = NativeRadioButtonFactory.class.getCanonicalName(); private final FormUtils formUtils = new FormUtils(); private final CustomTextViewClickListener customTextViewClickListener = new CustomTextViewClickListener(); private RadioButton radioButton; @@ -190,6 +190,7 @@ private static void showDatePickerDialog(Activity context, DatePickerDialog date ft.addToBackStack(null); datePickerDialog.show(ft, TAG); + System.out.println(context.getFragmentManager().findFragmentByTag(TAG) != null); Calendar calendar = getDate(radioButton); datePickerDialog.setDate(calendar.getTime()); } 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 2c0bb07ee..e31a18ad1 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 @@ -1,12 +1,12 @@ package com.vijay.jsonwizard.presenters; import android.app.Activity; +import android.app.FragmentManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.provider.MediaStore; -import androidx.appcompat.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; @@ -159,10 +159,10 @@ public void testOnClickShouldSOpenPictureTakingActivity() { } @Test - public void testOnClickShouldDisplayDatePickerDialog() { + public void testOnClickShouldDisplayDatePickerDialog() throws InterruptedException { LinearLayout view = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.native_form_compound_button_parent, null); CustomTextView customTextView = new CustomTextView(context); - Activity activity = Robolectric.buildActivity(AppCompatActivity.class).create().get(); + Activity activity = Robolectric.buildActivity(Activity.class).create().get(); RadioButton radioButton = new RadioButton(context); view.setTag(R.id.specify_textview, customTextView); view.setTag(R.id.native_radio_button, radioButton); @@ -175,8 +175,12 @@ public void testOnClickShouldDisplayDatePickerDialog() { view.setTag(R.id.specify_widget, JsonFormConstants.DATE_PICKER); view.setTag(R.id.option_json_object, new JSONObject()); formFragmentPresenter.onClick(view); - DatePickerDialog dialogFragment = (DatePickerDialog) activity.getFragmentManager() - .findFragmentByTag(NativeRadioButtonFactory.class.getCanonicalName()); + Thread.sleep(3000); + DatePickerDialog dialogFragment = null; + FragmentManager fragmentManager = activity.getFragmentManager(); + if (fragmentManager != null){ + dialogFragment = (DatePickerDialog) fragmentManager.findFragmentByTag(NativeRadioButtonFactory.TAG); + } assertNotNull(dialogFragment); }