tumblr/jumblr — pull request #33 by orac (2013-11-13 17:16:25+00:00)
Title: Handle empty response bodies

I've seen a problem in production where RequestBuilder.clear NPEs
because gson.fromJson returns null, which it does when the passed-in
string (which is the response body) is empty.

I've added a unit test for this case. The test looks a bit silly
because it relies on mocking the response with a really implausible
one. There's nothing to stop you writing more mock responses with
nonsense values, which is the main shortcoming of this kind of test.
But in this case, this is just a regression test for a bug I've seen
in the wild, not just an invalid situation I've made up. Long-term,
it would be better to be able to plug in a fake server and test the
whole response decoding pipeline: since the API doesn't use SSL,
the 'server' could be sending any garbage down the line.

Armed with the test case, I've fixed the bug, and also found and
fixed a limitation of JumblrException: it couldn't handle an empty
response body either.