robolectric/robolectric — pull request #1336 by macfergus (2014-10-23 18:29:06+00:00)
Title: Implement swapCursor in ShadowCursorAdapter.

Hello! When writing my very first Robolectric test I was quite surprised by the behavior of swapCursor. Since it's not implemented on the ShadowCursorAdapter, using swapCursor puts you in a confusing state where mCursor on the real changes but mCursor on the shadow does not.

This pull request implements swapCursor on the shadow.

swapCursor is exactly like changeCursor, but it returns the old cursor instead of closing it. It's common to use swapCursor with CursorLoaders, since the CursorLoader is responsible for closing the old cursor.

PS. In my specific case, replacing the ShadowCursorAdapter entirely also worked:
```
// Disable the Robolectric ShadowCursorAdapter, which breaks swapCursor.
@Implements(CursorAdapter.class)
public static class FixedShadowCursorAdapter extends ShadowBaseAdapter {
@RealObject CursorAdapter realCursorAdapter;

public void __constructor__(Context context, Cursor c, int flags) {
// Delegate all the work to the realCursorAdapter.
}
}
```