AccountsUpdateEvent implements Event { @Override public void process(Context context, Intent intent) { mAck.sendAck(context, intent); Bundle entity = new NannyBundle(intent).getEntityBody(); if (entity == null) { Timber.wtf(Err.NO_ENTITY); return; } final Parcelable[] parcels = entity.getParcelableArray(ACCOUNTS); if (parcels == null) { Timber.wtf(Err.NO_ACCOUNTS); return; } mHandler.post(new Runnable() { @Override public void run() { Account[] accounts = new Account[parcels.length]; System.arraycopy(parcels, 0, accounts, 0, parcels.length); mListener.onAccountsUpdated(accounts); } }); } AccountsUpdateEvent(OnAccountsUpdateListener listener, @Nullable Handler handler); @VisibleForTesting  AccountsUpdateEvent(OnAccountsUpdateListener listener, @Nullable Handler handler, Ack ack); @Override String filter(); @Override void process(Context context, Intent intent); @PPP static final String FILTER; @PPP static final String ACCOUNTS; }
@Test public void process() throws Exception { mBundle.putParcelableArray(AccountsUpdateEvent.ACCOUNTS, new Account[]{mAccount}); mIntent.putExtra(Nanny.ENTITY_BODY, mBundle); mEventFilter.process(mContext, mIntent); verify(mAck).sendAck(mContext, mIntent); verify(mHandler).post(mRunnableCaptor.capture()); mRunnableCaptor.getValue().run(); verify(mOnAccountsUpdateListener).onAccountsUpdated(mAccountsCaptor.capture()); assertThat(mAccountsCaptor.getValue()[0], is(mAccount)); }