From 3f72b036f9148aa7661835db9fe9907e28e6caa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E2=89=A1ZRS?= <12814349+LZRS@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:47:20 +0300 Subject: [PATCH] Fix failing testOnClickShouldDisplayDatePickerDialog Use normal Activity instead of AndroidX Activity --- .../widgets/NativeRadioButtonFactory.java | 2 +- ...izardFormFragmentPresenterRoboelectricTest.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) 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..638fc2535 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; 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); }