ContentEvent implements Event { @Override public void process(Context context, Intent intent) { switch (mRequest.opCode) { case ContentRequest.SELECT: Uri authorized = null; if (Nanny.SC_OK == intent.getIntExtra(Nanny.STATUS_CODE, 0)) { long uriPath = intent.getBundleExtra(Nanny.ENTITY_BODY).getLong(mRequest.opCode, 0); authorized = Nanny.getProxyContentProvider().buildUpon().appendPath(Long.toString(uriPath)).build(); } ContentResolver cr = context.getContentResolver(); Cursor data = authorized == null ? null : cr.query(authorized, null, null, null, null); mListener.onResponse(intent.getExtras(), data); break; default: mListener.onResponse(intent.getExtras(), null); } } ContentEvent(RequestParams request, ContentListener listener); @Override String filter(); @Override void process(Context context, Intent intent);  }
@Test public void process_shouldReturnNull_whenDelete() throws Exception { setupProcess(ContentRequest.DELETE); mEventFilter.process(RuntimeEnvironment.application, mIntent); assertProcess_nullCursor(); }
@Test public void process_shouldReturnCursor_whenSelect() throws Exception { setupProcess(ContentRequest.SELECT); mEventFilter.process(RuntimeEnvironment.application, mIntent); verify(mContentListener).onResponse(mBundleArgumentCaptor.capture(), mCursorArgumentCaptor.capture()); assertThat(mCursorArgumentCaptor.getValue(), sameInstance(mCursor)); assertThat(mBundleArgumentCaptor.getValue(), equalToBundle(mIntent.getExtras())); }
@Test public void process_shouldReturnNull_whenSelectStatusCodeIsNotOk() throws Exception { setupProcess(ContentRequest.SELECT); mIntent.putExtra(Nanny.STATUS_CODE, Nanny.SC_FORBIDDEN); mEventFilter.process(RuntimeEnvironment.application, mIntent); assertProcess_nullCursor(); }
@Test public void process_shouldReturnNull_whenInsert() throws Exception { setupProcess(ContentRequest.INSERT); mEventFilter.process(RuntimeEnvironment.application, mIntent); assertProcess_nullCursor(); }
@Test public void process_shouldReturnNull_whenUpdate() throws Exception { setupProcess(ContentRequest.UPDATE); mEventFilter.process(RuntimeEnvironment.application, mIntent); assertProcess_nullCursor(); }