Skip to content

Commit

Permalink
Fix failing testOnClickShouldDisplayDatePickerDialog
Browse files Browse the repository at this point in the history
Use normal Activity instead of AndroidX Activity
  • Loading branch information
LZRS committed Mar 2, 2023
1 parent 98d9305 commit 3f72b03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 3f72b03

Please sign in to comment.