robolectric/robolectric — pull request #1431 by kriegfrj (2014-12-19 06:15:42+00:00)
Title: Removed ShadowHandler, introduced ShadowMessageQueue

Started as a requirement for `ShadowHandler`'s `remove()` functionality to work better.

`ShadowHandler` attempted to emulate the message queuing of Android. Unfortunately it did so imperfectly, with problems including:

* `removeCallbacksAndMessages()` only removed messages and not callbacks.
* It didn't honour tags on callbacks (posted `Runnable`s) - only on messages.
* `Handler`s connected to the same `Looper` in Android are isolated from each other - doing a remove on one `Handler` instance will not interfere with the messages associated with a different `Handler` even if they have the same tags. The previous `ShadowHandler` implementation didn't honour this (eg, `removeCallbacksAndMessages()` would remove all callbacks for all handlers associated with the same looper).

When I looked at trying to add this functionality to the `ShadowHandler` I realised I would basically be reinventing the Android implementation of `MessageQueue` for most of it. Hence `ShadowMessageQueue` was born, which basically only needs to reimplement one method to interface it with the `Scheduler`.

I kept most of `ShadowHandlerTest` as a regression test to make sure that no existing functionality was broken. Added a couple of more tests to ensure that the broken functionality mentioned above was fixed.

I also kept `ShadowHandler` only because of the static methods (which client code might be using). This could be removed completely in a later revision.