Java Code Examples for android.widget.Button#performClick()

The following examples show how to use android.widget.Button#performClick() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppSettingsDialogTest.java    From easypermissions with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNegativeListener_whenClickingPositiveButtonFromSupportFragment() {
    AlertDialog alertDialog = new AppSettingsDialog.Builder(spyFragment)
            .setTitle(TITLE)
            .setRationale(RATIONALE)
            .setPositiveButton(POSITIVE)
            .setNegativeButton(NEGATIVE)
            .setThemeResId(R.style.Theme_AppCompat)
            .build()
            .showDialog(positiveListener, negativeListener);
    Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    positive.performClick();

    verify(negativeListener, times(1))
            .onClick(any(DialogInterface.class), anyInt());
}
 
Example 2
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void startWithoutParametersCancel()
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    Activity activity = (Activity)activityController.get();

    final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton);

    assertEquals(false, activity.isFinishing());
    cancelButton.performClick();
    assertEquals(true, activity.isFinishing());
}
 
Example 3
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomAuthMethodPickerLayout() {
    List<String> providers = Arrays.asList(EmailAuthProvider.PROVIDER_ID);

    AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
            .Builder(R.layout.fui_provider_button_email)
            .setEmailButtonId(R.id.email_button)
            .build();

    AuthMethodPickerActivity authMethodPickerActivity = createActivityWithCustomLayout(providers, customLayout);

    Button emailButton = authMethodPickerActivity.findViewById(R.id.email_button);
    emailButton.performClick();

    //Expected result -> Directing users to EmailActivity
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
    assertEquals(
            EmailActivity.class.getName(),
            nextIntent.intent.getComponent().getClassName());
}
 
Example 4
Source File: TestActivityTest.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Test
public void inverse() {
    CheckBox checkBox = (CheckBox) mTestActivity.findViewById(R.id.checkBox);
    Button button = (Button) mTestActivity.findViewById(R.id.button4);

    Assert.assertFalse(checkBox.isChecked());

    button.performClick();

    Assert.assertTrue(checkBox.isChecked());

    button.performClick();

    Assert.assertFalse(checkBox.isChecked());
}
 
Example 5
Source File: EmailActivityTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignUpButton_validatesFields() {

    EmailActivity emailActivity = createActivity(EmailAuthProvider.PROVIDER_ID);

    // Trigger RegisterEmailFragment (bypass check email)
    emailActivity.onNewUser(
            new User.Builder(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build());

    Button button = emailActivity.findViewById(R.id.button_create);
    button.performClick();

    TextInputLayout nameLayout = emailActivity.findViewById(R.id.name_layout);
    TextInputLayout passwordLayout = emailActivity.findViewById(R.id.password_layout);

    assertEquals(
            emailActivity.getString(R.string.fui_missing_first_and_last_name),
            nameLayout.getError().toString());
    assertEquals(
            String.format(
                    emailActivity.getResources().getQuantityString(
                            R.plurals.fui_error_weak_password,
                            R.integer.fui_min_password_length),
                    emailActivity.getResources()
                            .getInteger(R.integer.fui_min_password_length)
            ),
            passwordLayout.getError().toString());
}
 
Example 6
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithGiftCardWithReceiptUpdateReceiptCancel() throws IOException
{
    ActivityController activityController = createActivityWithGiftCard();
    Activity activity = (Activity)activityController.get();
    DBHelper db = new DBHelper(activity);

    db.insertGiftCard("store", "cardId", "value", "receipt");

    activityController.start();
    activityController.visible();
    activityController.resume();

    checkAllFields(activity, "store", "cardId", "value", "receipt", false);

    // Add something that will 'handle' the media capture intent
    registerMediaStoreIntentHandler();

    // Complete image capture successfully
    Uri imageLocation = captureImageWithResult(activity, R.id.updateButton, true);

    checkAllFields(activity, "store", "cardId", "value", "receipt", true);

    // Cancel the gift card creation
    final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton);
    assertEquals(false, activity.isFinishing());
    cancelButton.performClick();
    assertEquals(true, activity.isFinishing());
    activityController.destroy();

    // Ensure the image has been deleted
    File imageFile = new File(imageLocation.getPath());
    assertEquals(false, imageFile.exists());
}
 
Example 7
Source File: LoginAdapterTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void instantiateItem_loginButtonShouldSendMixpanelEvent() throws Exception {
    TestLoginListener listener = new TestLoginListener();
    loginAdapter.setLoginListener(listener);
    View view = (View) loginAdapter.instantiateItem(new FrameLayout(application), PAGE_4);
    Button loginButton = (Button) view.findViewById(R.id.login_button);
    CheckBox checkbox = (CheckBox) view.findViewById(R.id.agree);
    checkbox.setEnabled(true);
    loginButton.performClick();
    assertThat(listener.login).isFalse();
}
 
Example 8
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithoutParametersCannotCreateGiftCard()
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    Activity activity = (Activity)activityController.get();
    DBHelper db = new DBHelper(activity);
    assertEquals(0, db.getGiftCardCount());

    final EditText storeField = (EditText) activity.findViewById(R.id.storeName);
    final EditText cardIdField = (EditText) activity.findViewById(R.id.cardId);
    final TextView receiptField = (TextView) activity.findViewById(R.id.receiptLocation);

    final Button saveButton = (Button) activity.findViewById(R.id.saveButton);

    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());

    storeField.setText("store");
    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());

    cardIdField.setText("cardId");
    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());

    receiptField.setText("receipt");
    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());
}
 
Example 9
Source File: EditTextDialogBuilder.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (mDialog != null) {
        Button button = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        if (button != null) {
            button.performClick();
        }
        return true;
    } else {
        return false;
    }
}
 
Example 10
Source File: SnackbarBuilderTest.java    From SnackbarBuilder with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(11)
public void whenBuild_thenSnackbarSetup() {
  int messageTextColor = 0xFF111111;
  int actionTextColor = 0xFF999999;
  int backgroundCOlor = 0xFF777777;
  String message = "message";
  String action = "action";
  RuntimeEnvironment.application.setTheme(R.style.TestSnackbarBuilder_AppTheme);
  CoordinatorLayout parent = new CoordinatorLayout(RuntimeEnvironment.application);

  Snackbar snackbar = new SnackbarBuilder(parent)
      .messageTextColor(messageTextColor)
      .actionTextColor(actionTextColor)
      .message(message)
      .actionText(action)
      .duration(Snackbar.LENGTH_INDEFINITE)
      .backgroundColor(backgroundCOlor)
      .actionAllCaps(false)
      .build();

  assertThat(snackbar.getDuration()).isEqualTo(Snackbar.LENGTH_INDEFINITE);

  Assertions.assertThat((TextView) snackbar.getView().findViewById(R.id.snackbar_text))
      .hasCurrentTextColor(messageTextColor)
      .hasText(message);

  Assertions.assertThat((ColorDrawable) snackbar.getView().getBackground())
      .hasColor(backgroundCOlor);

  Button button = (Button) snackbar.getView().findViewById(R.id.snackbar_action);
  Assertions.assertThat(button).hasCurrentTextColor(actionTextColor);
  button.performClick();
  assertThat(button.getTransformationMethod()).isNull();
}
 
Example 11
Source File: StepCreateFragmentTest.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void whenClickingSelectPictureExpectOpenFilePickerBeCalled() throws Exception {
    Button selectPicture = (Button) activity.findViewById(R.id.id_btn_select_step_picture);
    selectPicture.performClick();

    verify(filePickerProxy)
            .openFilePicker(any(StepCreateFragment.class), any(AssetType.class));
}
 
Example 12
Source File: EditTextDialogBuilder.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (mDialog != null) {
        Button button = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        if (button != null) {
            button.performClick();
        }
        return true;
    } else {
        return false;
    }
}
 
Example 13
Source File: RobolectricActivityTest.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void buttonClickShouldStartNewActivity() throws Exception
{
    Button button = (Button) activity.findViewById( R.id.startNextActivity );
    button.performClick();
    Intent intent = Shadows.shadowOf(activity).peekNextStartedActivity();
    assertEquals(RobolectricSecondActivity.class.getCanonicalName(), intent.getComponent().getClassName());
}
 
Example 14
Source File: RobolectricActivityTest.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testButtonClickShouldShowToast() throws Exception {
    RobolectricActivity activity = Robolectric.buildActivity(RobolectricActivity.class).create().get();
    Button view = (Button) activity.findViewById(R.id.showToast);
    assertNotNull(view);
    view.performClick();
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo("Lala") );
}
 
Example 15
Source File: ConfirmDialog.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 处理返回键
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Button btn = (Button) findViewById(R.id.dialog_button_cancel);
        btn.performClick();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 16
Source File: FilterTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNeutralButton() {
    // setup
    fixture.show();
    Button button = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    FilterAdapter filterAdapter = MainContextHelper.INSTANCE.getFilterAdapter();
    MainActivity mainActivity = MainContextHelper.INSTANCE.getMainActivity();
    // execute
    button.performClick();
    // validate
    RobolectricUtil.INSTANCE.clearLooper();
    assertFalse(alertDialog.isShowing());
    verify(filterAdapter).reload();
    verify(mainActivity, never()).update();
}
 
Example 17
Source File: StepCreateFragmentTest.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void whenClickingSelectSoundExpectOpenFilePickerBeCalled() throws Exception {
    Button selectSound = (Button) activity.findViewById(R.id.id_btn_select_step_sound);
    selectSound.performClick();

    verify(filePickerProxy)
            .openFilePicker(any(TaskCreateFragment.class), any(AssetType.class));
}
 
Example 18
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testPhoneLoginFlow() {
    List<String> providers = Arrays.asList(PhoneAuthProvider.PROVIDER_ID);

    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);

    Button phoneButton = authMethodPickerActivity.findViewById(R.id.phone_button);
    phoneButton.performClick();
    ShadowActivity.IntentForResult nextIntent =
            Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();

    assertEquals(
            PhoneActivity.class.getName(),
            nextIntent.intent.getComponent().getClassName());
}
 
Example 19
Source File: LoginAdapterTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void instantiateItem_inActiveLoginButtonShouldToast() throws Exception {
    TestLoginListener listener = new TestLoginListener();
    loginAdapter.setLoginListener(listener);
    View view = (View) loginAdapter.instantiateItem(new FrameLayout(application), PAGE_4);
    Button loginButton = (Button) view.findViewById(R.id.login_button);
    loginButton.performClick();
    String expected = application.getString(R.string.agree_to_terms_please);
    assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected);
}
 
Example 20
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initiate and complete an image capture, returning the
 * location of the resulting file if the capture was
 * a success.
 *
 * @param success
 *      true if the image capture is a success, and a
 *      file is to be created at the requested location,
 *      false otherwise.
 * @param buttonId
 *      id of the button to press to initiate the capture
 * @return The URI pointing to the image file location,
 * regardless if the operation was successful or not.
 */
private Uri captureImageWithResult(final Activity activity, final int buttonId, final boolean success) throws IOException
{
    // Start image capture
    final Button captureButton = (Button) activity.findViewById(buttonId);
    captureButton.performClick();

    ShadowActivity.IntentForResult intentForResult = shadowOf(activity).peekNextStartedActivityForResult();
    assertNotNull(intentForResult);

    Intent intent = intentForResult.intent;
    assertNotNull(intent);

    String action = intent.getAction();
    assertNotNull(action);
    assertEquals(MediaStore.ACTION_IMAGE_CAPTURE, action);

    Bundle bundle = intent.getExtras();
    assertNotNull(bundle);

    assertEquals(false, bundle.isEmpty());
    Uri argument = bundle.getParcelable(MediaStore.EXTRA_OUTPUT);
    assertNotNull(argument);
    assertTrue(argument.toString().length() > 0);

    // Respond to image capture, success
    shadowOf(activity).receiveResult(
            intent,
            success ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
            null);

    if(success)
    {
        File imageFile = new File(argument.getPath());
        assertEquals(false, imageFile.exists());
        boolean result = imageFile.createNewFile();
        assertTrue(result);
    }

    return argument;
}