@Test public void testShouldDoNothingIfButtonInvalid() throws Exception { final Intent intent = new Intent(application, WidgetReceiver.class); intent.setAction(ACTION_BUTTON_PRESSED); intent.putExtra(ACTION_BUTTON_ID_EXTRA, "test!@"); widgetReceiver.onReceive(application, intent); verify(widgetReceiver.keyboard, times(0)).buttonPressed(Mockito.anyString()); }
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (!TextUtils.equals(action, ACTION_BUTTON_PRESSED)) { return; } cast(context).getComponent().inject(this); final int buttonId = intent.getIntExtra(ACTION_BUTTON_ID_EXTRA, 0); final CppButton button = CppButton.getById(buttonId); if (button == null) { return; } if (history.isLoaded()) { if (!keyboard.buttonPressed(button.action)) { return; } } else { history.runWhenLoaded(new MyRunnable(keyboard, button.action)); } vibrate(context); }
WidgetReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (!TextUtils.equals(action, ACTION_BUTTON_PRESSED)) { return; } cast(context).getComponent().inject(this); final int buttonId = intent.getIntExtra(ACTION_BUTTON_ID_EXTRA, 0); final CppButton button = CppButton.getById(buttonId); if (button == null) { return; } if (history.isLoaded()) { if (!keyboard.buttonPressed(button.action)) { return; } } else { history.runWhenLoaded(new MyRunnable(keyboard, button.action)); } vibrate(context); } }
WidgetReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (!TextUtils.equals(action, ACTION_BUTTON_PRESSED)) { return; } cast(context).getComponent().inject(this); final int buttonId = intent.getIntExtra(ACTION_BUTTON_ID_EXTRA, 0); final CppButton button = CppButton.getById(buttonId); if (button == null) { return; } if (history.isLoaded()) { if (!keyboard.buttonPressed(button.action)) { return; } } else { history.runWhenLoaded(new MyRunnable(keyboard, button.action)); } vibrate(context); }  }
WidgetReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (!TextUtils.equals(action, ACTION_BUTTON_PRESSED)) { return; } cast(context).getComponent().inject(this); final int buttonId = intent.getIntExtra(ACTION_BUTTON_ID_EXTRA, 0); final CppButton button = CppButton.getById(buttonId); if (button == null) { return; } if (history.isLoaded()) { if (!keyboard.buttonPressed(button.action)) { return; } } else { history.runWhenLoaded(new MyRunnable(keyboard, button.action)); } vibrate(context); }  @Nonnull static Intent newButtonClickedIntent(@Nonnull Context context, @Nonnull CppButton button); @Override void onReceive(Context context, Intent intent); }
WidgetReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (!TextUtils.equals(action, ACTION_BUTTON_PRESSED)) { return; } cast(context).getComponent().inject(this); final int buttonId = intent.getIntExtra(ACTION_BUTTON_ID_EXTRA, 0); final CppButton button = CppButton.getById(buttonId); if (button == null) { return; } if (history.isLoaded()) { if (!keyboard.buttonPressed(button.action)) { return; } } else { history.runWhenLoaded(new MyRunnable(keyboard, button.action)); } vibrate(context); }  @Nonnull static Intent newButtonClickedIntent(@Nonnull Context context, @Nonnull CppButton button); @Override void onReceive(Context context, Intent intent); static final String ACTION_BUTTON_ID_EXTRA; static final String ACTION_BUTTON_PRESSED; }