AccountManagerEvent implements Event { @Override public void process(Context context, Intent intent) { final Bundle entity = new NannyBundle(intent).getEntityBody(); if (entity == null) { Timber.wtf(Err.NO_ENTITY); return; } mHandler.post(new Runnable() { @Override public void run() { mCallback.run(new AccountManagerFuture<T>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { return true; } @Override public T getResult() throws OperationCanceledException, IOException, AuthenticatorException { Object value = entity.get(CALLBACK); if (value != null && value.getClass() != mType) { return null; } return (T) value; } @Override public T getResult(long timeout, TimeUnit unit) throws OperationCanceledException, IOException, AuthenticatorException { return getResult(); } }); } }); } AccountManagerEvent(AccountManagerCallback<T> callback, @Nullable Handler handler, Class<T> type); @Override String filter(); @Override void process(Context context, Intent intent); @PPP static final String FILTER; @PPP static final String CALLBACK; }
@Test public void process() throws Exception { mBundle.putParcelable(AccountManagerEvent.CALLBACK, mAccount); mIntent.putExtra(Nanny.ENTITY_BODY, mBundle); runProcess(); AccountManagerFuture<Account> future = mAccountManagerFutureCaptor.getValue(); assertThat(future.cancel(false), is(false)); assertThat(future.isCancelled(), is(false)); assertThat(future.isDone(), is(true)); assertThat(future.getResult(1, TimeUnit.DAYS), sameInstance(mAccount)); }